o w[e4@s|dZddlZddlmZddlmZdZddZGd d d eZGd ddeZ Gd d d eZ ddZ GdddeZ dS) TestSuiteN)case)utilTcCst||dd}|dS)NcSdSNrrr%/usr/lib/python3.10/unittest/suite.py sz!_call_if_exists..)getattr)parentattrfuncrrr _call_if_exists s rc@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__" zBaseTestSuite.__iter__cCs$|j}|D] }|r||7}q|Sr)rcountTestCases)rcasestestrrr r$%s  zBaseTestSuite.countTestCasescCsLt|s tdt|t|trt|tjt frtd|j |dS)Nz{} is not callablezNTestCases and TestSuites must be instantiated before passing them to addTest()) callable TypeErrorformatreprrtype issubclassrTestCaserrappendrr&rrr addTest,szBaseTestSuite.addTestcCs*t|tr td|D]}||q dS)Nz0tests must be an iterable of tests, not a string)rstrr(r0)rrr&rrr r6s  zBaseTestSuite.addTestscCs:t|D]\}}|jr|S|||jr||q|Sr) enumerate shouldStop_cleanup_removeTestAtIndex)rresultindexr&rrr run<s zBaseTestSuite.runcCsNz|j|}Wn tyYdSwt|dr |j|7_d|j|<dS)z2Stop holding a reference to the TestCase at index.r$N)rr(hasattrrr$)rr7r&rrr r5Es  z BaseTestSuite._removeTestAtIndexcOs|j|i|Srr8)rargskwdsrrr __call__SszBaseTestSuite.__call__cCs|D]}|qdS)7Run the tests without collecting errors in a TestResultN)debugr/rrr r?Vs zBaseTestSuite.debugN)r)__name__ __module__ __qualname____doc__r4rrr r"r$r0rr8r5r=r?rrrr rs    rc@sbeZdZdZdddZddZddZd d Zd d Z dddZ 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]D\}}|jrnTN) _DebugResultr8)rr?rrr r?szTestSuite.debugc Cstt|dd}|j}||krdS|jrdSt|ddrdSd}zd|_Wn ty,Ynwt|dd}t|dd}|durt|dzoz|Wn6ty~}z*t|trVd}zd|_Wn tyfYnwt |} | ||d| WYd}~nd}~ww|r|dur||j D]} |j || dd| | d qWt|d dSWt|d dSWt|d dSt|d wdS) NrK__unittest_skip__F setUpClassdoClassCleanups _setupStdoutTrinfo_restoreStdout) r rrFrEr(r ExceptionrrNrr"_createClassOrModuleLevelExceptiontearDown_exceptions) rr&r6 previousClass currentClassfailedrPrQe classNameexc_inforrr rJsf               zTestSuite._handleClassSetUpcCs"d}t|dd}|dur|j}|S)NrK)r rA)rr6previousModulerYrrr _get_previous_modules  zTestSuite._get_previous_modulec CsL||}|jj}||krdS||d|_ztj|}Wn ty(YdSwt|dd}|durt |dzez|Wn#t ya}zt |t rLd|_| ||d|WYd}~nd}~ww|jrztWn"t y}z| ||d|WYd}~nd}~wwWt |ddSWt |ddSWt |ddSt |dwdS)NF setUpModulerRTrU)r`rrArLrFsysmodulesKeyErrorr rrVrrNrWrdoModuleCleanups)rr&r6r_ currentModulemodulerar\rrr rIsX        zTestSuite._handleModuleFixtureNcCs$|d|d}|||||dS)Nz ())_addClassOrModuleLevelException)rr6exc method_namer rT errorNamerrr rWsz,TestSuite._createClassOrModuleLevelExceptioncCsbt|}t|dd}|durt|tjr||t|dS|s)||tdS|||dS)NaddSkip) _ErrorHolderr rrSkipTestr1addErrorrbr^)rr6 exceptionrlrTerrorrmrrr ris z)TestSuite._addClassOrModuleLevelExceptionc Cs*||}|dur dS|jrdSztj|}Wn ty!YdSwt|dzgt|dd}|durXz|Wn tyW}zt|t rE| ||d|WYd}~nd}~wwzt Wn ty~}zt|t rl| ||d|WYd}~n d}~wwWt|ddSWt|ddSt|dw)NrRtearDownModulerU) r`rFrbrcrdrr rVrrNrWrre)rr6r_rgrsr\rrr rLsP        zTestSuite._handleModuleTearDownc Csft|dd}|j}||ks|durdSt|ddrdSt|ddr#dSt|ddr+dSt|dd}t|dd}|durA|durAdSt|dzf|durvz|Wn%tyu}zt|tr^t|}|||d|WYd}~nd}~ww|dur||j D]$} t|tr| d t|}|j|| d d|| d qWt|d dSWt|d dSt|d w) NrKrEFrFrO tearDownClassrQrRrrSrU) r rrrVrrNrrrWrX) rr&r6rYrZrtrQr\r]r^rrr rHsX                z TestSuite._tearDownPreviousClass)Fr) r@rArBrCr8r?rJr`rIrWrirLrHrrrr r\s !.&   #c@sTeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ dS)rnz 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)rrvrrr rTr#z_ErrorHolder.__init__cCs|jSrrurrrr idWsz_ErrorHolder.idcCrrrrrrr shortDescriptionZz_ErrorHolder.shortDescriptioncCs d|jfS)Nzrurrrr r]s z_ErrorHolder.__repr__cCs|Sr)rwrrrr __str__`sz_ErrorHolder.__str__cCrrrrr6rrr r8csz_ErrorHolder.runcCs ||Srr:r{rrr r=hr#z_ErrorHolder.__call__cCsdSrrrrrr r$kryz_ErrorHolder.countTestCases) r@rArBrCfailureExceptionrrwrxrrzr8r=r$rrrr rnHs  rncCs$zt|WdStyYdSw)z?A crude way to tell apart testcases and suites with duck-typingTF)r!r()r&rrr rGns   rGc@seZdZdZdZdZdZdS)rNzCUsed by the TestSuite to hold previous class when running in debug.NF)r@rArBrCrKrFr3rrrr rNws rN) rCrbrr __unittestrobjectrrrnrGrNrrrr s  Lm&