U e3@sdZddlZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z m Z mZddlmZddlmZddlmZmZed Zejd kZd d d ddddgZGdddejZGdd d ejZeZZdd ZdddZ ddZ!e"dkredS)z,Implements nose test program and collector. N)Configall_config_files)defaultTestLoader) PluginManagerDefaultPluginManagerRestrictedPluginManager)TextTestResult)FinalizingSuiteWrapper)isclasstolistz nose.core) TestProgrammainrunrun_exit runmodule collectorTextTestRunnerc@s4eZdZdZejdddfddZddZdd ZdS) rzTest runner that uses nose's TextTestResult to enable errorClasses, as well as providing hooks for plugins to override or replace the test output stream, results, and the test case itself. NcCs*|dkrt}||_tj||||dSN)rconfigunittestr__init__)selfstream descriptions verbosityrr7/opt/hc_python/lib/python3.8/site-packages/nose/core.pyr szTextTestRunner.__init__cCst|j|j|j|jSr)rrrrrrrrr _makeResult(s zTextTestRunner._makeResultcCs|jj|}|dk r|}|jj|j}|dk r8||_|}t}z ||Wntk rhYnXt}|| |||jj ||S)zaOverrides to provide plugin hooks and defer all output to the test result class. N) rplugins prepareTestsetOutputStreamrr!timeKeyboardInterruptZ printErrorsZ printSummaryfinalize)rtestwrapperwrappedresultstartstoprrrr.s"  zTextTestRunner.run) __name__ __module__ __qualname____doc__sysstderrrr!rrrrrrs  c @sbeZdZdZdZdddZddd Zdd d Zd d ZddZ ddZ ddZ ddZ e e Z dS)raCollect and run tests, returning success or failure. The arguments to TestProgram() are the same as to :func:`main()` and :func:`run()`: * module: All tests are in this module (default: None) * defaultTest: Tests to load (default: '.') * argv: Command line arguments (default: None; sys.argv is read) * testRunner: Test runner instance (default: None) * testLoader: Test loader instance (default: None) * env: Environment; ignored if config is provided (default: None; os.environ is read) * config: :class:`nose.config.Config` instance (default: None) * suite: Suite or list of tests to run (default: None). Passing a suite or lists of tests will bypass all test discovery and loading. *ALSO NOTE* that if you pass a unittest.TestSuite instance as the suite, context fixtures at the class, module and package level will not be used, and many plugin hooks will not be called. If you want normal nose behavior, either pass a list of tests, or a fully-configured :class:`nose.suite.ContextSuite`. * exit: Exit after running tests and printing report (default: True) * plugins: List of plugins to use; ignored if config is provided (default: load plugins with DefaultPluginManager) * addplugins: List of **extra** plugins to use. Pass a list of plugin instances in this argument to make custom plugins available while still using the DefaultPluginManager. rN.Tc Cs|dkrtj}|dkr"||| }| r4|jj| d||_||_| |_i} tj dd} | dkrp| dkrp| | d<t j j |f|||||d| dS)N)Z extrapluginsrr )r )rexit)module defaultTestargv testRunner testLoader) osenviron makeConfigr"Z addPluginsrsuiter7r2 version_inforrr)rr8r9r:r;r<envrr@r7r"Z addplugins extra_argsversionrrrrfs0 zTestProgram.__init__cCs"|pi}|ddrgStSdS)NZNOSE_IGNORE_CONFIG_FILESF)getr)rrBrrrgetAllConfigFiles{s zTestProgram.getAllConfigFilescCs.||}|rt|d}nt}t|||dS)zSLoad a Config, pre-filled with user config files if any are found. )r")rBfilesr")rFrrr)rrBr"Z cfg_filesmanagerrrrr?s  zTestProgram.makeConfigcCsH|jj||dtd|j|jjjrhddlm}t j t _ t dt jt jd|ft d|jjjr|t d|jdkrt|jd|_nt|jr|j|jd|_|jj|j}|dk r||_td|j|jjr|jj|_n t|j|_td |jtd |j|jjdk rParse argv and env and configure running environment. )docz configured %sr) __version__z %s version %sN)rztest loader is %szdefaultTest %szTest names are %s)r configureusagelogdebugoptionsrDnoserJr2 __stdout__stdoutprintr=pathbasenamer:r7 showPluginsr<rr r"prepareTestLoader testNamesr r9Z workingDirchdir createTests)rr:rJZ plug_loaderrrr parseArgss4         zTestProgram.parseArgscCs>td|j|jdk r*|j|j|_n|j|j|_dS)zCreate the tests to run. If a self.suite is set, then that suite will be used. Otherwise, tests will be loaded from the given test names (self.testNames) using the test loader. zcreateTests called with %sN)rMrNr@r<Z suiteClassr(loadTestsFromNamesrXr rrrrZs zTestProgram.createTestscCs~td|jdkr.t|jj|jj|jd|_|jj|j}|dk rL||_|j |j }| |_ |j rxt |j |j S)zoRun Tests. Returns true on success, false on failure, and sets self.success to the same value. zrunTests calledN)rrr)rMrNr;rrrrr"prepareTestRunnerrr(Z wasSuccessfulsuccessr7r2)rZ plug_runnerr+rrrrunTestss   zTestProgram.runTestsc Csddl}Gddd}|jj}|jj|jjD]}td|j|dkr2td|jtd|j | d d d |d kr|}| |t |jrttd |jD]<\}}td d||rtd|j | ddd qtq2dS)z)Print list of available plugins. rNc@seZdZddZddZdS)z,TestProgram.showPlugins..DummyParsercSs g|_dSr)rOr rrrrsz5TestProgram.showPlugins..DummyParser.__init__c_s|j||ddfdS)Nhelp)rOappendpop)rargkwrrr add_optionsz7TestProgram.showPlugins..DummyParser.add_optionN)r.r/r0rrfrrrr DummyParsersrgz Plugin %sr z score: %s z )initial_indentsubsequent_indentr6z Options:z %sz, z )textwraprrr"sortrSnameZscorejoinwrapr`stripZ addOptionslenrO)rrkrgvpparseroptsr`rrrrVs8      zTestProgram.showPluginsc Csddl}z&|j}|tjtjtd}WnHtk rvt tjtjtdd}z | }W5| XYnXt |t s|d}|S)Nrz usage.txtrzutf-8)rP __loader__get_datar=rTrndirname__file__AttributeErroropencloseread isinstancestrdecode)clsrPldtextfrrrrLs(       zTestProgram.usage) Nr4NNNNNNTNN)N)N)r.r/r0r1rrrFr?r[rZr_rVrL classmethodrrrrrHs(   '#cOsd|d<t||jS)aCollect and run tests, returning success or failure. The arguments to `run()` are the same as to `main()`: * module: All tests are in this module (default: None) * defaultTest: Tests to load (default: '.') * argv: Command line arguments (default: None; sys.argv is read) * testRunner: Test runner instance (default: None) * testLoader: Test loader instance (default: None) * env: Environment; ignored if config is provided (default: None; os.environ is read) * config: :class:`nose.config.Config` instance (default: None) * suite: Suite or list of tests to run (default: None). Passing a suite or lists of tests will bypass all test discovery and loading. *ALSO NOTE* that if you pass a unittest.TestSuite instance as the suite, context fixtures at the class, module and package level will not be used, and many plugin hooks will not be called. If you want normal nose behavior, either pass a list of tests, or a fully-configured :class:`nose.suite.ContextSuite`. * plugins: List of plugins to use; ignored if config is provided (default: load plugins with DefaultPluginManager) * addplugins: List of **extra** plugins to use. Pass a list of plugin instances in this argument to make custom plugins available while still using the DefaultPluginManager. With the exception that the ``exit`` argument is always set to False. Fr7)rr^)rdrerrrrs__main__cKstfd|i|dS)zCollect and run tests in a single module only. Defaults to running tests in __main__. Additional arguments to TestProgram may be passed as keyword arguments. r9N)r)rmrerrrr0scCs\d}t|d}tt|d}|jdgdt|}|jrF||j}n |d}t||jS)aTestSuite replacement entry point. Use anywhere you might use a unittest.TestSuite. The collector will, by default, load options from all config files and execute loader.loadTestsFromNames() on the configured testNames, or '.' if no testNames are configured. )reportr#rWr]r$)exclude)rGr"r)r:)r4) rrrrKrrXr\r r')Zsetuptools_incompatr"confloaderr@rrrr8s   )r)#r1loggingr=r2r%rZ nose.configrrZ nose.loaderrZnose.plugins.managerrrrZ nose.resultrZ nose.suiter Z nose.utilr r getLoggerrMrAZ compat_24__all__rrrrrrrr.rrrrs2      -E!