U e3@sdZddlZddlZddlZddlmZddlmZddlm Z ddl m Z m Z m Z ddlZeeZdgZGdddejZGd d d ejZGd d d eZGd ddeZdS)znose unittest.TestCase subclasses. It is not necessary to subclass these classes when writing tests; they are used internally by nose.loader.TestLoader to create test cases from test functions and methods in test classes. N) isfunction)Config)Failure) resolve_name test_addresstry_runTestc@seZdZdZdZdddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZeedddZddZddZddZdS) rzThe universal test case wrapper. When a plugin sees a test, it will always see an instance of this class. To access the actual test case that will be run, access the test property of the nose.case.Test instance. FNcCsbt|tjstd|||_|dkr,t}||_d|_d|_||_ |j |_ d|_ t j |dS)NzTnose.case.Test called with argument %r that is not callable. A callable is required.) isinstance collectionsCallable TypeErrortestrconfigZtbinfoZcapturedOutput resultProxypluginsZpassedunittestTestCase__init__)selfr rrr7/opt/hc_python/lib/python3.8/site-packages/nose/case.pyrs z Test.__init__cOs |j||SN)run)rargkwargrrr__call__-sz Test.__call__cCs"|j|}|dk r|St|jSr)rZtestNamestrr )rnamerrr__str__0s z Test.__str__cCs d|jS)NzTest(%r))r rrrr__repr__6sz Test.__repr__cCs.z |j}Wntk rYn X||jdS)z>Called after test is complete (after result.stopTest) N) afterTestAttributeErrorr )rresultr!rrrr!9s  zTest.afterTestcCs.z |j}Wntk rYn X||jdS)zYnXzt|jjWStk rbYnXdSr)r contextr" __class__r __module__rrrr_contextcs  z Test._contextz-Get the context object of this test (if any).c Csv|jr|||}zRz||||Wn4tk rBYn t}|||YnXW5||XdS)aModified run for the test wrapper. From here we don't call result.startTest or stopTest or addSuccess. The wrapper calls addError/addFailure only if its own setup or teardown fails, or running the wrapped test fails (eg, if the wrapped "test" is not callable). Two additional methods are called, beforeTest and afterTest. These give plugins a chance to modify the wrapped test before it is called and do cleanup after it is called. They are called unconditionally. N)rr!r$runTestKeyboardInterruptr%r&ZaddError)rr#errrrrrts   zTest.runcCs,|j}|jj|}|dk r |}||dS)zRun the test. Plugins may alter the test by returning a value from prepareTestCase. The value must be callable and must accept one argument, the result instance. N)r rrZprepareTestCase)rr#r Z plug_testrrrr1s z Test.runTestc Cs|j|}|dk r|S|j}z|j|_Wn:tk rhz|j|_Wntk rbYnXYnXz|j}Wntk rYnXz|t |jkrWdSWntk rYnX|Sr) rZ describeTestr Z_testMethodDocstripr"Z_TestCase__testMethodDocshortDescription Exceptionr)rdescr rrrr5s,   zTest.shortDescription)NN)__name__r/ __qualname____doc____test__rrrr r!r$r&r)r+r0propertyr-rr1r5rrrrrs$     c@s,eZdZdZdZddZddZddZd S) TestBasezBCommon functionality for FunctionTestCase and MethodTestCase. FcCst|Sr)rrrrrr)sz TestBase.idcCs|j|jdSr)r rrrrrr1szTestBase.runTestcCsNt|jdr|jjS|\}}t|dd}|s8t|}|ddS)N descriptionr: r)r,r r> _descriptorsgetattrrr4split)rfuncrdocrrrr5s   zTestBase.shortDescriptionN)r8r/r9r:r;r)r1r5rrrrr=s r=c@sjeZdZdZdZddedfddZddZdd Ze eddd Z d d Z d dZ ddZ e ZddZdS)FunctionTestCasezTestCase wrapper for test functions. Don't use this class directly; it is used internally in nose to create test cases for test functions. FNcCs,||_||_||_||_||_t|dS)aInitialize the MethodTestCase. Required argument: * test -- the test function to call. Optional arguments: * setUp -- function to run at setup. * tearDown -- function to run at teardown. * arg -- arguments to pass to the test function. This is to support generator functions that yield arguments. * descriptor -- the function, other than the test, that should be used to construct the test name. This is to support generator functions. N)r setUpFunc tearDownFuncr descriptorr=r)rr setUptearDownrrHrrrrs zFunctionTestCase.__init__cCs"|jdk rt|jSt|jSdSr*N)rHrr rrrrr+s  zFunctionTestCase.addresscCs t|jjSr)rr r/rrrrr0szFunctionTestCase._contextz!Get context (module) of this testcCs$|jr|nd}t|j|dS)z=Run any setup function attached to the test function )setuprIrFN)rFrr rnamesrrrrIs zFunctionTestCase.setUpcCs$|jr|nd}t|j|dS)z@Run any teardown function attached to the test function )teardownrJrGN)rGrr rMrrrrJs zFunctionTestCase.tearDowncCsF|\}}t|dr|j}n|j}d|j|f}|rBd||f}|S)Ncompat_func_namez%s.%s%s%s)r@r,rPr8r/rrCrrrrrrs   zFunctionTestCase.__str__cCs"|jr|j|jfS|j|jfSdS)afGet the descriptors of the test function: the function and arguments that will be used to construct the test name. In most cases, this is the function itself and no arguments. For tests generated by generator functions, the original (generator) function and args passed to the generated function are returned. N)rHrr rrrrr@&s zFunctionTestCase._descriptors)r8r/r9r:r;tuplerr+r0r<r-rIrJrr r@rrrrrEs     rEc@sheZdZdZdZdedfddZddZeZdd Z d d Z e e ddd Z d dZ ddZddZdS)MethodTestCasezTest case wrapper for test methods. Don't use this class directly; it is used internally in nose to create test cases for test methods. FNcCsj||_||_||_||_t|r(td|jj|_||_ |jdkr\|jj }t |j ||_t |dS)aInitialize the MethodTestCase. Required argument: * method -- the method to call, may be bound or unbound. In either case, a new instance of the method's class will be instantiated to make the call. Note: In Python 3.x, if using an unbound method, you must wrap it using pyversion.unbound_method. Optional arguments: * test -- the test function to call. If this is passed, it will be called instead of getting a new bound method of the same name as the desired method from the test instance. This is to support generator methods that yield inline functions. * arg -- arguments to pass to the test function. This is to support generator methods that yield arguments. * descriptor -- the function, other than the test, that should be used to construct the test name. This is to support generator methods. z_Unbound methods must be wrapped using pyversion.unbound_method before passing to MethodTestCaseN)methodr rrHr ValueError__self__r.clsinstr8rAr=r)rrUr rrH method_namerrrr<s   zMethodTestCase.__init__cCsN|\}}t|dr|j}n|j}d|jj|jj|f}|rJd||f}|S)NrPz%s.%s.%srQ)r@r,rPr8rXr/rRrrrr`s   zMethodTestCase.__str__cCs"|jdk rt|jSt|jSdSrK)rHrrUrrrrr+ns  zMethodTestCase.addresscCs|jSr)rXrrrrr0xszMethodTestCase._contextz Get context (class) of this testcCst|jddS)N)rLrIrrYrrrrrI}szMethodTestCase.setUpcCst|jddS)N)rOrJr[rrrrrJszMethodTestCase.tearDowncCs"|jr|j|jfS|j|jfSdS)agGet the descriptors of the test method: the method and arguments that will be used to construct the test name. In most cases, this is the method itself and no arguments. For tests generated by generator methods, the original (generator) method and args passed to the generated method or function are returned. N)rHrrUrrrrr@s zMethodTestCase._descriptors)r8r/r9r:r;rSrrr r+r0r<r-rIrJr@rrrrrT4s$  rT)r:loggingr%rinspectrZ nose.configrZ nose.failurerZ nose.utilrrrr getLoggerr8log__all__rrr=rErTrrrrs    *b