3 K]#@sddlZddlZddlZddlZddlZddlZddlmZmZddl m Z ddlm Z ddl m Z ddlmZmZddlmZmZmZmZmZmZmZmZmZddlmZGd d d e ZGd d d eZGd ddeZ dS)N)DistutilsErrorDistutilsOptionError)log) TestLoader)six)mapfilter) resource_listdirresource_existsnormalize_path working_set_namespace_packagesevaluate_markeradd_activation_listenerrequire EntryPoint)Commandc@seZdZddZdddZdS)ScanningLoadercCstj|t|_dS)N)r__init__set_visited)selfr/usr/lib/python3.6/test.pyrs zScanningLoader.__init__NcCs||jkrdS|jj|g}|jtj||t|drH|j|jt|drxpt|jdD]`}|j dr|dkr|jd|dd }n"t |j|d r`|jd|}nq`|j|j |q`Wt |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. Nadditional_tests__path__z.pyz __init__.py.z /__init__.pyr)raddappendrloadTestsFromModulehasattrrr __name__endswithr ZloadTestsFromNamelenZ suiteClass)rmodulepatternZtestsfileZ submodulerrrr#s$      z"ScanningLoader.loadTestsFromModule)N)r% __module__ __qualname__rr#rrrrrsrc@seZdZddZdddZdS)NonDataPropertycCs ||_dS)N)fget)rr.rrrr>szNonDataProperty.__init__NcCs|dkr |S|j|S)N)r.)robjZobjtyperrr__get__AszNonDataProperty.__get__)N)r%r+r,rr0rrrrr-=sr-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)rrrrinitialize_optionsSsztest.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>)rmsgrrrfinalize_optionsYs        ztest.finalize_optionscCs t|jS)N)list _test_args)rrrr test_argslsztest.test_argsccs6|j rtjdkrdV|jr$dV|jr2|jVdS)NZdiscoverz --verbose)rGrH)r;sys version_infoverbose)rrrrrEps ztest._test_argsc Cs|j |WdQRXdS)zI Backward compatibility for project_on_sys_path context. N)project_on_sys_path)rfuncrrrwith_project_on_sys_pathxs 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_2to3FZbuild_pyr)ZinplaceZegg_info)egg_baseZ build_extrcSs|jS)N)Zactivate)distrrrsz*test.project_on_sys_path..z%s==%s)rPY3rAr@Zreinitialize_commandZ run_commandZget_finalized_commandr Z build_librIpathmodulescopyrPinsertr rrrZegg_nameZ egg_versionpaths_on_pythonpathclearupdate) rZ include_distsZ with_2to3Zbpy_cmdZ build_pathZei_cmdZold_pathZ old_modulesZ project_pathrrrrLs8             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_pathrrrrXs     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).0kvrrr sz%test.install_dists..)Zfetch_build_eggsZinstall_requiresZ tests_requireZextras_requireitems itertoolschain)rQZir_dZtr_dZer_drrr 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) ror@ra_argvZdry_runannounceroperator attrgetterrXrL run_tests)rZinstalled_distscmdrcrrrruns    ztest.runcCstjrt|jddr|jjdd}|tkrg}|tjkrD|j ||d7}x"tjD]}|j |rT|j |qTWt t tjj |tjdd|j|j|j|j|jdd}|jjsd|j}|j|tjt|dS)NrOFrr)Z testLoaderZ testRunnerexitzTest failed: %s)rrSrAr@r;splitr rIrUr"rgrDr __delitem__unittestmainrr_resolve_as_epr=r>resultZ wasSuccessfulrsrZERRORr)rr(Z del_modulesnamer1rBrrrrvs(        ztest.run_testscCs dg|jS)Nr|)rF)rrrrrrsz test._argvcCs$|dkr dStjd|}|jS)zu Load the indicated attribute value, called, as a as if it were specified as an entry point. Nzx=)rparseZresolve)valZparsedrrrr~sztest._resolve_as_epN)r2r3r4)r5r6r7)r8r9r:)r%r+r,__doc__ descriptionZ user_optionsr?rCr-rFrErN contextlibcontextmanagerrL staticmethodrXrorxrvpropertyrrr~rrrrr1Gs( -  r1)!r]rtrIrrmr|Zdistutils.errorsrrZ distutilsrrZsetuptools.externrZsetuptools.extern.six.movesrrZ pkg_resourcesr r r r r rrrrZ setuptoolsrrr\r-r1rrrrs   , )