
|_"                 @   s8  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z d  d l m	 Z	 d  d l
 m Z d  d l m Z d  d l m Z m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d	 l m Z Gd
 d   d e  Z Gd d   d e  Z  Gd d   d e  Z! d S)    N)DistutilsErrorDistutilsOptionError)log)
TestLoader)six)mapfilter)resource_listdirresource_existsnormalize_pathworking_set_namespace_packagesadd_activation_listenerrequire
EntryPoint)Command)unittest_mainc               @   s   e  Z d  Z d d d  Z d S)ScanningLoaderNc             C   s  g  } | j  t j |  |   t | d  rA | j  | j    t | d  r x t | j d  D] } | j d  r | d k r | j d | d d  } n- t | j | d	  rc | j d | } n qc | j  |  j	 |   qc Wt
 |  d
 k r|  j |  S| d Sd S)a  Return a suite of all tests cases contained in the given module

        If the module is a package, load tests from all the modules in it.
        If the module has an ``additional_tests`` function, call it and add
        the return value to the tests.
        additional_tests__path__ z.pyz__init__.py.N   z/__init__.py   r   )appendr   loadTestsFromModulehasattrr   r	   __name__endswithr
   ZloadTestsFromNamelenZ
suiteClass)selfmodulepatterntestsfile	submodule r'   =/tmp/pip-build-3_sjtvrs/setuptools/setuptools/command/test.pyr      s    z"ScanningLoader.loadTestsFromModule)r   
__module____qualname__r   r'   r'   r'   r(   r      s   r   c               @   s+   e  Z d  Z d d   Z d d d  Z d S)NonDataPropertyc             C   s   | |  _  d  S)N)fget)r!   r,   r'   r'   r(   __init__5   s    zNonDataProperty.__init__Nc             C   s   | d  k r |  S|  j  |  S)N)r,   )r!   objZobjtyper'   r'   r(   __get__8   s    zNonDataProperty.__get__)r   r)   r*   r-   r/   r'   r'   r'   r(   r+   4   s   r+   c               @   s   e  Z d  Z d Z d Z d% d& d' g Z d d   Z d d   Z e d d    Z	 d d   Z
 d d   Z e j g  d d   Z e e j d d     Z e d d    Z d d   Z d d   Z e d  d!    Z e d" d#    Z d$ S)(testz.Command to run unit tests after in-place buildz#run unit tests after in-place buildtest-module=m$Run 'test_suite' in specified moduletest-suite=s1Test suite to run (e.g. 'some_module.test_suite')test-runner=rTest runner to usec             C   s(   d  |  _  d  |  _ d  |  _ d  |  _ d  S)N)
test_suitetest_moduletest_loadertest_runner)r!   r'   r'   r(   initialize_optionsJ   s    			ztest.initialize_optionsc             C   s   |  j  r$ |  j r$ d } t |   |  j  d  k rd |  j d  k rT |  j j  |  _  n |  j d |  _  |  j d  k r t |  j d d   |  _ |  j d  k r d |  _ |  j d  k r t |  j d d   |  _ d  S)Nz1You may specify a module or a suite, but not bothz.test_suiter<   z&setuptools.command.test:ScanningLoaderr=   )r:   r;   r   distributionr<   getattrr=   )r!   msgr'   r'   r(   finalize_optionsP   s    	ztest.finalize_optionsc             C   s   t  |  j    S)N)list
_test_args)r!   r'   r'   r(   	test_argsc   s    ztest.test_argsc             c   s#   |  j  r d V|  j r |  j Vd  S)Nz	--verbose)verboser:   )r!   r'   r'   r(   rD   g   s    		ztest._test_argsc          	   C   s   |  j     |   Wd QRXd S)zI
        Backward compatibility for project_on_sys_path context.
        N)project_on_sys_path)r!   funcr'   r'   r(   with_project_on_sys_pathm   s    ztest.with_project_on_sys_pathc       	      c   s  t  j o t |  j d d  } | r |  j d d d |  j d  |  j d  } t | j  } |  j d d | |  j d  |  j d d d |  j d  n- |  j d  |  j d d d	 |  j d  |  j d  } t	 j
 d  d   } t	 j j   } zy t | j  } t	 j
 j d |  t j   t d
 d    t d | j | j f  |  j | g  
 d  VWd  QRXWd  | t	 j
 d  d   <t	 j j   t	 j j |  t j   Xd  S)Nuse_2to3Fbuild_pyZinplacer   egg_infoegg_base	build_extr   c             S   s
   |  j    S)N)activate)distr'   r'   r(   <lambda>   s    z*test.project_on_sys_path.<locals>.<lambda>z%s==%s)r   PY3r@   r?   reinitialize_commandrun_commandget_finalized_commandr   	build_libsyspathmodulescopyrM   insertr   r-   r   r   egg_nameZegg_versionpaths_on_pythonpathclearupdate)	r!   Zinclude_distsZ	with_2to3Zbpy_cmdZ
build_pathZei_cmdZold_pathZold_modulesZproject_pathr'   r'   r(   rG   t   s8    
ztest.project_on_sys_pathc             c   s   t    } t j j d |  } t j j d d  } zU t j j |   } t d | | g  } t j j |  } | r | t j d <d VWd | | k r t j j d d  n | t j d <Xd S)z
        Add the indicated paths to the head of the PYTHONPATH environment
        variable so that subprocesses will also see the packages at
        these paths.

        Do this in a context that restores the value on exit.
        
PYTHONPATHr   N)objectosenvirongetpathsepjoinr   pop)pathsZnothingZorig_pythonpathZcurrent_pythonpathprefixZto_joinnew_pathr'   r'   r(   r]      s    
		ztest.paths_on_pythonpathc             C   s@   |  j  |  j p g   } |  j  |  j p* g   } t j | |  S)z
        Install the requirements indicated by self.distribution and
        return an iterable of the dists that were built.
        )Zfetch_build_eggsZinstall_requiresZtests_require	itertoolschain)rP   Zir_dZtr_dr'   r'   r(   install_dists   s    ztest.install_distsc             C   s   |  j  |  j  } d j |  j  } |  j rB |  j d |  d  S|  j d |  t t j d  |  } |  j	 |  # |  j
    |  j   Wd  QRXWd  QRXd  S)N zskipping "%s" (dry run)zrunning "%s"location)rm   r?   rf   _argvdry_runannouncer   operator
attrgetterr]   rG   	run_tests)r!   installed_distscmdrh   r'   r'   r(   run   s    	ztest.runc          	   C   sQ  t  j r t |  j d d  r |  j j d  d } | t k r g  } | t j k rb | j	 |  | d 7} x- t j D]" } | j
 |  rv | j	 |  qv Wt t t j j |   t j d k  r i  n	 d d i } t d  d  |  j d |  j |  j  d	 |  j |  j  | } | j j   sMd
 | j } |  j | t j  t |   d  S)NrJ   Fr   r         exitZ
testLoaderZ
testRunnerzTest failed: %s)ry   rz   )r   rR   r@   r?   r:   splitr   rW   rY   r   
startswithrC   r   __delitem__version_infor   rp   _resolve_as_epr<   r=   resultZwasSuccessfulrr   r   ERRORr   )r!   r"   Zdel_modulesnameZ
exit_kwargr0   rA   r'   r'   r(   ru      s*    
!	ztest.run_testsc             C   s   d g |  j  S)Nunittest)rE   )r!   r'   r'   r(   rp      s    z
test._argvc             C   s0   |  d k r d St  j d |   } | j     S)zu
        Load the indicated attribute value, called, as a as if it were
        specified as an entry point.
        Nzx=)r   parseresolve)valparsedr'   r'   r(   r      s    ztest._resolve_as_epN)r1   r2   r3   )r4   r5   r6   )r7   r8   r9   )r   r)   r*   __doc__descriptionuser_optionsr>   rB   r+   rE   rD   rI   
contextlibcontextmanagerrG   staticmethodr]   rm   rx   ru   propertyrp   r   r'   r'   r'   r(   r0   >   s(    	-
r0   )"rb   rs   rW   r   rk   Zdistutils.errorsr   r   	distutilsr   r   r   Zsetuptools.externr   Zsetuptools.extern.six.movesr   r   pkg_resourcesr	   r
   r   r   r   r   r   r   
setuptoolsr   Zsetuptools.py31compatr   r   ra   r+   r0   r'   r'   r'   r(   <module>   s   : 
