
§|j™"  ã               @   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-5c7ija6t/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=Úsú1Test 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   : 
