3 M(YT#@sddlZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddlmZmZddlmZmZmZmZmZmZmZmZmZddlmZdd lmZGd d d e ZGd d d e Z!GdddeZ"dS)N)DistutilsErrorDistutilsOptionError)log) TestLoader)six)mapfilter) resource_listdirresource_existsnormalize_path working_set_namespace_packagesevaluate_markeradd_activation_listenerrequire EntryPoint)Command) unittest_mainc@seZdZdddZdS)ScanningLoaderNcCsg}|jtj||t|dr.|j|jt|drxpt|jdD]`}|jdrt|dkrt|jd|dd }n"t|j|d rF|jd|}nqF|j|j |qFWt |d kr|j |S|d SdS) aReturn 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.Nz /__init__.pyr) appendrloadTestsFromModulehasattrrr __name__endswithr ZloadTestsFromNamelenZ suiteClass)selfmodulepatterntestsfile submoduler(E/private/tmp/pip-build-nl73fm5q/setuptools/setuptools/command/test.pyrs    z"ScanningLoader.loadTestsFromModule)N)r __module__ __qualname__rr(r(r(r)rsrc@seZdZddZdddZdS)NonDataPropertycCs ||_dS)N)fget)r"r-r(r(r)__init__5szNonDataProperty.__init__NcCs|dkr |S|j|S)N)r-)r"objZobjtyper(r(r)__get__8szNonDataProperty.__get__)N)rr*r+r.r0r(r(r(r)r,4sr,c@seZdZdZdZd%d&d'gZd d ZddZeddZ ddZ ddZ e j gfddZee j ddZeddZddZddZed d!Zed"d#Zd$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=s9Run single test, case or suite (e.g. 'module.test_suite') test-runner=rTest runner to usecCsd|_d|_d|_d|_dS)N) test_suite test_module test_loader test_runner)r"r(r(r)initialize_optionsJsztest.initialize_optionscCs|jr|jrd}t||jdkrD|jdkr8|jj|_n |jd|_|jdkr^t|jdd|_|jdkrnd|_|jdkrt|jdd|_dS)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_optionsPs        ztest.finalize_optionscCs t|jS)N)list _test_args)r"r(r(r) test_argscsztest.test_argsccs|jr dV|jr|jVdS)Nz --verbose)verboser;)r"r(r(r)rEgsztest._test_argsc Cs|j |WdQRXdS)zI Backward compatibility for project_on_sys_path context. N)project_on_sys_path)r"funcr(r(r)with_project_on_sys_pathms ztest.with_project_on_sys_pathc csPtjot|jdd}|rv|jddd|jd|jd}t|j}|jd|d|jd|jddd|jdn"|jd|jdd d|jd|jd}t j dd}t j j }zbt|j }t j jd|tjtd d td |j|jf|j|g dVWdQRXWd|t j dd<t j jt j j|tjXdS) Nuse_2to3Fbuild_pyr)Zinplaceegg_info)egg_base build_extrcSs|jS)N)activate)distr(r(r)sz*test.project_on_sys_path..z%s==%s)rPY3rAr@reinitialize_command run_commandget_finalized_commandr build_libsyspathmodulescopyrNinsertr r.rregg_nameZ egg_versionpaths_on_pythonpathclearupdate) r"Z include_distsZ with_2to3Zbpy_cmdZ build_pathZei_cmdZold_pathZ old_modulesZ project_pathr(r(r)rHts8             ztest.project_on_sys_pathc cst}tjjd|}tjjdd}z>tjj|}td||g}tjj|}|rX|tjd<dVWd||krztjjddn |tjd<XdS)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. PYTHONPATHrN)objectosenvirongetpathsepjoinrpop)pathsZnothingZorig_pythonpathZcurrent_pythonpathprefixZto_joinnew_pathr(r(r)r^s     ztest.paths_on_pythonpathcCsD|j|j}|j|jpg}|jdd|jjD}tj|||S)z Install the requirements indicated by self.distribution and return an iterable of the dists that were built. css0|](\}}|jdrt|ddr|VqdS):rN) startswithr).0kvr(r(r) sz%test.install_dists..)Zfetch_build_eggsZinstall_requiresZ tests_requireZextras_requireitems itertoolschain)rQZir_dZtr_dZer_dr(r(r) install_distss  ztest.install_distscCs|j|j}dj|j}|jr0|jd|dS|jd|ttjd|}|j |"|j |j WdQRXWdQRXdS)N zskipping "%s" (dry run)z running "%s"location) rur@rg_argvdry_runannounceroperator attrgetterr^rH run_tests)r"installed_distscmdrir(r(r)runs    ztest.runcCstjrt|jddr|jjdd}|tkrg}|tjkrD|j ||d7}x"tjD]}|j |rT|j |qTWt t tjj |tjd krinddi}tdd|jf|j|j|j|jd|}|jjsd |j}|j|tjt|dS) NrKFrrexit)Z testLoaderZ testRunnerzTest failed: %s)rr)rrSrAr@r;splitr rXrZrrmrDr __delitem__ version_inforrx_resolve_as_epr=r>resultZ wasSuccessfulrzrERRORr)r"r#Z del_modulesnameZ exit_kwargr1rBr(r(r)r}s*        ztest.run_testscCs dg|jS)Nunittest)rF)r"r(r(r)rxsz test._argvcCs$|dkr dStjd|}|jS)zu Load the indicated attribute value, called, as a as if it were specified as an entry point. Nzx=)rparseresolve)valparsedr(r(r)rsztest._resolve_as_epN)r2r3r4)r5r6r7)r8r9r:)rr*r+__doc__ description user_optionsr?rCr,rFrErJ contextlibcontextmanagerrH staticmethodr^rurr}propertyrxrr(r(r(r)r1>s( -  r1)#rcr{rXrrsZdistutils.errorsrr distutilsrrrZsetuptools.externrZsetuptools.extern.six.movesrr pkg_resourcesr r r r r rrrr setuptoolsrZsetuptools.py31compatrrrbr,r1r(r(r(r)s   ,