3 e@sddlZddlZddlZddlZddlZddlZddlmZmZddl m Z ddlm Z ddl m Z mZmZmZmZmZmZmZddlmZddlmZGdd d e ZGd d d ZGd d d eZdS)N)DistutilsErrorDistutilsOptionError)log) TestLoader)resource_listdirresource_existsnormalize_path working_setevaluate_markeradd_activation_listenerrequire EntryPoint)Command)unique_everseenc@seZdZddZdddZdS)ScanningLoadercCstj|t|_dS)N)r__init__set_visited)selfr=/tmp/pip-build-vlmub77e/setuptools/setuptools/command/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__endswithrZloadTestsFromNamelenZ suiteClass)rmodulepatterntestsfile submodulerrrr s$      z"ScanningLoader.loadTestsFromModule)N)r" __module__ __qualname__rr rrrrrsrc@seZdZddZdddZdS)NonDataPropertycCs ||_dS)N)fget)rr-rrrrBszNonDataProperty.__init__NcCs|dkr |S|j|S)N)r-)robjZobjtyperrr__get__EszNonDataProperty.__get__)N)r"r*r+rr/rrrrr,Asr,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 buildz0run unit tests after in-place build (deprecated) 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_optionsZsztest.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_options`s        ztest.finalize_optionscCs t|jS)N)list _test_args)rrrr test_argsssztest.test_argsccs6|j rtjdkrdV|jr$dV|jr2|jVdS)NZdiscoverz --verbose)rFrG)r:sys version_infoverbose)rrrrrDws ztest._test_argsc Cs|j |WdQRXdS)zI Backward compatibility for project_on_sys_path context. N)project_on_sys_path)rfuncrrrwith_project_on_sys_paths ztest.with_project_on_sys_pathccs|jd|jddd|jd|jd}tjdd}tjj}zbt|j}tjj d|t j t ddt d|j|jf|j|g dVWdQRXWd|tjdd<tjjtjj|t j XdS) Negg_info build_extr)ZinplacercSs|jS)N)activate)distrrrsz*test.project_on_sys_path..z%s==%s) run_commandreinitialize_commandget_finalized_commandrHpathmodulescopyrZegg_baseinsertr rr r egg_nameZ egg_versionpaths_on_pythonpathclearupdate)rZ include_distsZei_cmdZold_pathZ old_modulesZ project_pathrrrrKs$        ztest.project_on_sys_pathc cst}tjjd|}tjjdd}zBtjjt|}td||g}tjj|}|r\|tjd<dVWd||kr~tjjddn |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) objectosenvirongetpathsepjoinrfilterpop)pathsZnothingZorig_pythonpathZcurrent_pythonpathprefixZto_joinnew_pathrrrr[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 ).0kvrrr sz%test.install_dists..)Zfetch_build_eggsZinstall_requiresZ tests_requireZextras_requireitems itertoolschain)rQZir_dZtr_dZer_drrr install_distss  ztest.install_distscCs|jdtj|j|j}dj|j}|jr>|jd|dS|jd|tt j d|}|j |"|j |j WdQRXWdQRXdS)NzWARNING: Testing via this command is deprecated and will be removed in a future version. Users looking for a generic test entry point independent of test runner are encouraged to use tox. zskipping "%s" (dry run)z running "%s"location)announcerWARNrsr?rd_argvdry_runmapoperator attrgetterr[rK run_tests)rinstalled_distscmdrgrrrruns    ztest.runcCsVtjdd|j|j|j|j|jdd}|jjsRd|j}|j|t j t |dS)NF)Z testLoaderZ testRunnerexitzTest failed: %s) unittestmainrx_resolve_as_epr<r=resultZ wasSuccessfulrvrERRORr)rr0rArrrr}s    ztest.run_testscCs dg|jS)Nr)rE)rrrrrxsz test._argvcCs$|dkr dStjd|}|jS)zu Load the indicated attribute value, called, as a as if it were specified as an entry point. Nzx=)r parseresolve)valparsedrrrrsztest._resolve_as_epN)r1r2r3)r4r5r6)r7r8r9)r"r*r+__doc__ description user_optionsr>rBr,rErDrM contextlibcontextmanagerrK staticmethodr[rsrr}propertyrxrrrrrr0Ks*   r0)r`r{rHrrqrZdistutils.errorsrr distutilsrr pkg_resourcesrrrr r r r r setuptoolsrZ setuptools.extern.more_itertoolsrrr,r0rrrrs  (  (