a ;`2@s|dZddlZddlmZddlmZdZddZGd d d eZGd ddeZ Gd d d eZ ddZ GdddeZ dS) TestSuiteN)case)utilTcCst||dd}|dS)NcSsdSNrrr$/usr/lib/python3.9/unittest/suite.py z!_call_if_exists..)getattr)parentattrfuncrrr_call_if_exists src@sneZdZdZdZdddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS) BaseTestSuitezNA simple test suite that doesn't provide class or module shared fixtures. TrcCsg|_d|_||dSNr)_tests_removed_testsaddTests)selftestsrrr__init__szBaseTestSuite.__init__cCsdt|jt|fS)Nz <%s tests=%s>)rstrclass __class__listrrrr__repr__szBaseTestSuite.__repr__cCs t||jstSt|t|kSr) isinstancerNotImplementedr)rotherrrr__eq__s zBaseTestSuite.__eq__cCs t|jSr)iterrrrrr__iter__"szBaseTestSuite.__iter__cCs$|j}|D]}|r ||7}q |Sr)rcountTestCases)rZcasestestrrrr#%s zBaseTestSuite.countTestCasescCsLt|stdt|t|tr|j|7_d|j|<dS)z2Stop holding a reference to the TestCase at index.r#N)rr&hasattrrr#)rr4r$rrrr2Es  z BaseTestSuite._removeTestAtIndexcOs|j|i|Srr5)rargskwdsrrr__call__SszBaseTestSuite.__call__cCs|D] }|qdS)7Run the tests without collecting errors in a TestResultN)debugr,rrrr<VszBaseTestSuite.debugN)r)__name__ __module__ __qualname____doc__r1rrr r"r#r-rr5r2r:r<rrrrrs   rc@s^eZdZdZdddZddZddZd d Zd d ZdddZ dddZ ddZ ddZ d S)raA test suite is a composite test consisting of a number of TestCases. For use, create an instance of TestSuite, then add test case instances. When all tests have been added, the suite can be passed to a test runner, such as TextTestRunner. It will run the individual test cases in the order in which they were added, aggregating the results. When subclassing, do not forget to call the base class constructor. FcCsd}t|dddurd|_}t|D]\}}|jr8qt|r||||||||||j|_ t|jdds&t|ddrq&|s||n| |j r&| |q&|r|d|| |d|_|S)NF_testRunEnteredT_classSetupFailed_moduleSetUpFailed)r rAr/r0 _isnotsuite_tearDownPreviousClass_handleModuleFixture_handleClassSetUpr_previousTestClassr<r1r2_handleModuleTearDown)rr3r<ZtopLevelr4r$rrrr5fs2         z TestSuite.runcCst}||ddS)r;TN) _DebugResultr5)rr<rrrr<szTestSuite.debugc Cst|dd}|j}||krdS|jr(dSt|ddr8dSz d|_WntyTYn0t|dd}|durt|dzz |WnPty}z8t|trd|_t |}| ||d|WYd}~n d}~00Wt|d|jdur| t |jdkr|jD]}|j ||d d||d q nVt|d|jdur| t |jdkr|jD]}|j ||d d||d q`0dS) NrH__unittest_skip__F setUpClass _setupStdoutT_restoreStdoutrrinfo)r rrCrBr&r ExceptionrrJrr"_createClassOrModuleLevelExceptiondoClassCleanupslentearDown_exceptions) rr$r3 previousClass currentClassrLe classNameexcrrrrGsX                  zTestSuite._handleClassSetUpcCs"d}t|dd}|dur|j}|S)NrH)r r>)rr3previousModulerVrrr_get_previous_modules  zTestSuite._get_previous_modulec Cs(||}|jj}||krdS||d|_ztj|}WntyPYdS0t|dd}|dur$t |dzz |Wnt y}zpz t Wn4t y}z| ||d|WYd}~n d}~00t|trނd|_| ||d|WYd}~n d}~00Wt |dn t |d0dS)NF setUpModulerMTrN)r\rr>rIrCsysmodulesKeyErrorr rrQrdoModuleCleanupsrRrrJ) rr$r3r[Z currentModulemoduler]rXrZrrrrFs>         zTestSuite._handleModuleFixtureNcCs$|d|d}|||||dS)Nz ())_addClassOrModuleLevelException)rr3rZZ method_namer rP errorNamerrrrRsz,TestSuite._createClassOrModuleLevelExceptioncCs^t|}t|dd}|dur8t|tjr8||t|n"|sN||tn |||dS)NaddSkip) _ErrorHolderr rrZSkipTestr.ZaddErrorr^exc_info)rr3Z exceptionrerPerrorrfrrrrds z)TestSuite._addClassOrModuleLevelExceptioncCsX||}|durdS|jr dSztj|}WntyBYdS0t|dd}|durTt|dzz |Wn@ty}z(t|t r| ||d|WYd}~n d}~00Wt|dz t Wn6ty}z| ||d|WYd}~n d}~00nPt|dz t Wn6tyP}z| ||d|WYd}~n d}~000dS)NtearDownModulerMrN) r\rCr^r_r`r rrQrrJrRrra)rr3r[rbrjrXrrrrIsJ           zTestSuite._handleModuleTearDownc Csrt|dd}|j}||krdSt|ddr.dSt|ddr>dSt|ddrNdSt|dd}|durnt|dzz |WnJty}z2t|trt|}|||d|WYd}~n d}~00Wt|d| t |j d krn|j D]&}t|}|j||d d||d qnTt|d| t |j d krl|j D](}t|}|j||d d||d qB0dS) NrHrBFrCrK tearDownClassrMrNrrrO) r rrrQrrJrrrRrSrTrU) rr$r3rVrWrkrXrYrZrrrrEsV                  z TestSuite._tearDownPreviousClass)F)N)N) r=r>r?r@r5r<rGr\rFrRrdrIrErrrrr\s !($   c@sTeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ dS)rgz Placeholder for a TestCase inside a result. As far as a TestResult is concerned, this looks exactly like a unit test. Used to insert arbitrary errors into a test suite run. NcCs ||_dSr description)rrmrrrrBsz_ErrorHolder.__init__cCs|jSrrlrrrridEsz_ErrorHolder.idcCsdSrrrrrrshortDescriptionHsz_ErrorHolder.shortDescriptioncCs d|jfS)NzrlrrrrrKsz_ErrorHolder.__repr__cCs|Sr)rnrrrr__str__Nsz_ErrorHolder.__str__cCsdSrrrr3rrrr5Qsz_ErrorHolder.runcCs ||Srr7rqrrrr:Vsz_ErrorHolder.__call__cCsdSrrrrrrr#Ysz_ErrorHolder.countTestCases) r=r>r?r@ZfailureExceptionrrnrorrpr5r:r#rrrrrg6s rgcCs&z t|Wnty YdS0dS)z?A crude way to tell apart testcases and suites with duck-typingTF)r!r&)r$rrrrD\s   rDc@seZdZdZdZdZdZdS)rJzCUsed by the TestSuite to hold previous class when running in debug.NF)r=r>r?r@rHrCr0rrrrrJesrJ) r@r^rrZ __unittestrobjectrrrgrDrJrrrrs  L[&