U
    jP^                     @   s   d Z ddlmZ ddlZddlZddlZddlZddlZee	Z
G dd dejZG dd dejZzddlmZ d	ZeZW n ek
r   d
ZeZY nX dS )a  setuptools/distutils command to run testr via setup.py

PBR will hook in the Testr class to provide "setup.py test" when
.testr.conf is present in the repository (see pbr/hooks/commands.py).

If we are activated but testrepository is not installed, we provide a
sensible error.

You can pass --coverage which will also export PYTHON='coverage run
--source <your package>' and automatically combine the coverage from
each testr backend test runner after the run completes.

    )cmdNc                   @   s\   e Zd ZdZdddddddgZd	d
dgZdd Zdd Zdd Zdd Z	dd Z
dd ZdS )	TestrRealz&DEPRECATED: Run unit tests using testr)coverageNzGReplace PYTHON with coverage and merge coverage from each testr worker.)ztestr-args=tzRun 'testr' with these args)zomit=oz(Files to omit from coverage calculations)zcoverage-package-name=NzLUse this name to select packages for coverage (one or more, comma-separated))slowestNz-Show slowest test times after tests complete.)zno-parallelNzRun testr serially)z
log-level=lzLog level (default: info)r   r   no_parallelc                 G   s2   t d| ttjd gt| tjtjtj	S )Nz _run_testr called with args = %rr   )
loggerdebugcommandsZrun_argvsysargvliststdinstdoutstderr)selfargs r   3/usr/lib/python3/dist-packages/pbr/testr_command.py
_run_testrH   s      zTestrReal._run_testrc                 C   s.   d | _ d | _d| _d | _d | _d | _d| _d S )N info)
testr_argsr   omitr   coverage_package_namer	   	log_levelr   r   r   r   initialize_optionsM   s    zTestrReal.initialize_optionsc                 C   sp   t t| j tj| _tj| jd td | jd kr@g | _n| j	 | _| j
r^d| j
 | _
td| j d S )N)levelzfinalize_options calledz	--omit=%sz$finalize_options: self.__dict__ = %r)getattrloggingr   upperINFOZbasicConfigr
   r   r   splitr   __dict__r   r   r   r   finalize_optionsV   s    

zTestrReal.finalize_optionsc                 C   s   t d tdt tjds,| d | j	r:| 
  | jsR| jd| j }n| jd| j }|rvtjd| | jrtd | d	 | j	r|   d
S )z"Set up testr repo, then run testr.z
run calledzctestr integration in pbr is deprecated. Please use the 'testr' setup command or call testr directlyz.testrepositoryZinitrun
--parallelztestr failed (%d)zSlowest Testsr   N)r(   r)   )r(   )r
   r   warningswarnDeprecationWarningospathisdirr   r   _coverage_beforer	   r   	distutilserrorsZDistutilsErrorr   print_coverage_after)r   Z	testr_retr   r   r   r(   e   s(    


zTestrReal.runc                 C   sb   t d | j }|dr*|dd  }| jr6| j}d| }d| tjd< t dtjd  d S )Nz_coverage_before calledzpython-   z--source %s --parallel-modezcoverage run %sZPYTHONzos.environ['PYTHON'] = %r)r
   r   ZdistributionZget_name
startswithr   r-   environ)r   packageZoptionsr   r   r   r0      s    


zTestrReal._coverage_beforec                 C   s8   t d td td| j  td| j  d S )Nz_coverage_after calledzcoverage combinezcoverage html -d ./cover %sz'coverage xml -o ./cover/coverage.xml %s)r
   r   r-   systemr   r   r   r   r   r4      s    

zTestrReal._coverage_afterN)__name__
__module____qualname__descriptionuser_optionsZboolean_optionsr   r   r'   r(   r0   r4   r   r   r   r   r   5   s    
	r   c                   @   s,   e Zd ZdZg Zdd Zdd Zdd ZdS )		TestrFakezRun unit tests using testrc                 C   s   d S Nr   r   r   r   r   r      s    zTestrFake.initialize_optionsc                 C   s   d S r@   r   r   r   r   r   r'      s    zTestrFake.finalize_optionsc                 C   s   t d d S )Nz7Install testrepository to run 'testr' command properly.)r3   r   r   r   r   r(      s    zTestrFake.runN)r:   r;   r<   r=   r>   r   r'   r(   r   r   r   r   r?      s
   r?   )r   TF)__doc__r1   r   Zdistutils.errorsr"   r-   r   r*   Z	getLoggerr:   r
   ZCommandr   r?   Ztestrepositoryr   Z
have_testrZTestrImportErrorr   r   r   r   <module>   s    
^