a DOgC@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl m Z ddl m Z mZmZmZmZdZeZdZGdddeZGd d d eZGd d d eZGd ddeZddZgZddZddZddZddZ ddZ!ddZ"ddZ#Gdd d Z$Gd!d"d"e$Z%Gd#d$d$e%Z&Gd%d&d&e%Z'Gd'd(d(ej(Z)Gd)d*d*eZ*Gd+d,d,e*Z+Gd-d.d.e*Z,dS)/N)result)strclass safe_repr_count_diff_all_purpose_count_diff_hashable_common_shorten_reprTz@ Diff is %s characters long. Set self.maxDiff to None to see it.c@s eZdZdS)SkipTestN__name__ __module__ __qualname__rr%/usr/lib64/python3.9/unittest/case.pyr sr c@s eZdZdS) _ShouldStopNr rrrrr!src@s eZdZdS)_UnexpectedSuccessNr rrrrr&src@s&eZdZdddZejdddZdS) _OutcomeNcCs4d|_||_t|d|_d|_g|_d|_g|_dS)NF addSubTestT)expecting_failurerhasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfrrrr__init__-s z_Outcome.__init__Fc cs|j}d|_zz dVWnty,Yntyh}z&d|_|j|t|fWYd}~npd}~0tyxYnXt}|j r||_ nd|_|j ||fd}Yn0|j r|jr|j |dfW|jo||_n|jo||_0dS)NTF) rKeyboardInterruptr rappendstrrsysexc_inforrrr)r test_caseisTestZ old_successer!rrrtestPartExecutor6s*  (   z_Outcome.testPartExecutor)N)F)r r r r contextlibcontextmanagerr%rrrrr,s rcCs|SNr)objrrr_idTsr*cOst|||fdSr()_module_cleanupsr)functionargskwargsrrraddModuleCleanupYsr/c Csjg}trZt\}}}z||i|WqtyV}z||WYd}~qd}~00q|rf|ddSNr)r+pop Exceptionr) exceptionsr,r-r.excrrrdoModuleCleanups_s"r5cs,fdd}ttjr(}d||S|S)Ncs4t|ts$t|fdd}|}d|_|_|S)Ncs tdSr(r r-r.reasonrr skip_wrapperusz-skip..decorator..skip_wrapperT) isinstancetype functoolswraps__unittest_skip____unittest_skip_why__) test_itemr:r8rr decoratorss zskip..decorator)r;types FunctionType)r9rBrArr8rskipos  rFcCs|r t|StSr(rFr*Z conditionr9rrrskipIfsrIcCs|s t|StSr(rGrHrrr skipUnlesssrJcCs d|_|S)NT)__unittest_expecting_failure__)rArrrrsrcs4t|tr tfdd|DSt|to2t|S)Nc3s|]}t|VqdSr() _is_subtype).0r$basetyperr z_is_subtype..)r;tupleallr< issubclass)expectedrOrrNrrLs rLc@seZdZddZddZdS)_BaseTestCaseContextcCs ||_dSr()r")rr"rrrrsz_BaseTestCaseContext.__init__cCs |j|j|}|j|dSr()r"_formatMessagemsgfailureException)r standardMsgrXrrr _raiseFailuresz"_BaseTestCaseContext._raiseFailureN)r r r rr[rrrrrVsrVc@seZdZdddZddZdS)_AssertRaisesBaseContextNcCs@t||||_||_|dur*t|}||_d|_d|_dSr() rVrrUr"recompileexpected_regexobj_namerX)rrUr"r_rrrrs  z!_AssertRaisesBaseContext.__init__cCszt|j|js"td||jf|sX|dd|_|rNtdtt|f|Wd}S|^}}z |j |_ Wnt yt ||_ Yn0|||i|Wdn1s0YWd}nd}0dS)Nz%s() arg 1 must be %srXz3%r is an invalid keyword argument for this function) rLrU _base_type TypeError_base_type_strr1rXnextiterr r`AttributeErrorr)rnamer-r.Z callable_objrrrhandles,    .z_AssertRaisesBaseContext.handle)N)r r r rrhrrrrr\s r\c@s.eZdZeZdZddZddZee j Z dS)_AssertRaisesContextz-an exception type or tuple of exception typescCs|Sr(rrrrr __enter__sz_AssertRaisesContext.__enter__cCs|dur`z |jj}Wnty0t|j}Yn0|jrN|d||jqj|d|n t|t ||jszdS| d|_ |j durdS|j }| t|s|d|jt|dS)Nz{} not raised by {}z {} not raisedFT"{}" does not match "{}")rUr rfrr`r[format traceback clear_framesrTwith_traceback exceptionr_searchpattern)rexc_type exc_valuetbexc_namer_rrr__exit__s,        z_AssertRaisesContext.__exit__N) r r r BaseExceptionrarcrkrx classmethodrD GenericAlias__class_getitem__rrrrris ric@s$eZdZeZdZddZddZdS)_AssertWarnsContextz(a warning type or tuple of warning typescCsRttjD]}t|ddri|_qtjdd|_|j |_t d|j |S)N__warningregistry__T)recordalways) listr modulesvaluesgetattrr~warningscatch_warningswarnings_managerrk simplefilterrU)rvrrrrks  z_AssertWarnsContext.__enter__cCs|j||||durdSz |jj}WntyDt|j}Yn0d}|jD]Z}|j}t||jshqP|durt|}|j dur|j t|sqP||_ |j |_ |j |_ dS|dur|d|j jt||jr|d||jn|d|dS)Nrlz{} not triggered by {}z{} not triggered)rrxrUr rfrrmessager;r_rrwarningfilenamelinenor[rmrsr`)rrtrurvrwZfirst_matchingmwrrrrxs>       z_AssertWarnsContext.__exit__N)r r r Warningrarcrkrxrrrrr}s r}c@seZdZddZdS)_OrderedChainMapccs8t}|jD]&}|D]}||vr|||Vqq dSr()setmapsadd)rseenmappingkrrr__iter__,s   z_OrderedChainMap.__iter__N)r r r rrrrrr+src@seZdZeZdZdZdZdZgZ dddZ dd Z d d Z e d d ZddZddZe ddZe ddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zejefd(d)Zd*d+Z d,d-Z!d.d/Z"d0d1Z#d2d3Z$d4d5Z%d6d7Z&dd9d:Z'd;d<Z(e d=d>Z)d?d@Z*dAdBZ+dCdDZ,ddEdFZ-ddGdHZ.ddIdJZ/dKdLZ0dMdNZ1dOdPZ2ddQdRZ3dSdTZ4ddUdVZ5ddWdXZ6ddYdZZ7dd[d\Z8dd]d^Z9dd_d`Z:dadbZ;ddcddZddidjZ?ddkdlZ@ddmdnZAddodpZBddqdrZCddsdtZDddudvZEddwdxZFddydzZGdd{d|ZHdd}d~ZIdddZJdddZKdddZLdddZMdddZNddZOddZPdddZQdddZRddZSeSe6ZTZUeSe7ZVZWeSe8ZXZYeSe9ZZZ[eSe/Z\Z]eSe1Z^eSe.Z_eSeOZ`eSeQZaeSeRZbd8S)TestCaseTiiFrunTestcCs||_d|_d|_zt||}Wn,tyL|dkrHtd|j|fYn 0|j|_g|_d|_ i|_ | t d| t d| td| td| td| tddS) NzNo testrzno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocrrf ValueError __class____doc__ _cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictrrRr frozensetr)rZ methodName testMethodrrrrfs(       zTestCase.__init__cCs||j|<dSr()r)rZtypeobjr,rrrrs zTestCase.addTypeEqualityFunccOs|j|||fdSr()rrrr,r-r.rrr addCleanupszTestCase.addCleanupcOs|j|||fdSr()_class_cleanupsrclsr,r-r.rrraddClassCleanupszTestCase.addClassCleanupcCsdSr(rrjrrrsetUpszTestCase.setUpcCsdSr(rrjrrrtearDownszTestCase.tearDowncCsdSr(rrrrr setUpClassszTestCase.setUpClasscCsdSr(rrrrr tearDownClassszTestCase.tearDownClasscCsdS)NrrrjrrrcountTestCasesszTestCase.countTestCasescCstSr()rZ TestResultrjrrrdefaultTestResultszTestCase.defaultTestResultcCs$|j}|r |ddSdSN r)rstripsplitrdocrrrshortDescriptionszTestCase.shortDescriptioncCsdt|j|jfS)Nz%s.%srrrrjrrridsz TestCase.idcCs t|t|urtS|j|jkSr()r<NotImplementedrrotherrrr__eq__szTestCase.__eq__cCstt||jfSr()hashr<rrjrrr__hash__szTestCase.__hash__cCsd|jt|jfSNz%s (%s))rrrrjrrr__str__szTestCase.__str__cCsdt|j|jfS)Nz<%s testMethod=%s>rrjrrr__repr__szTestCase.__repr__cCs<t|dd}|dur |||ntdtd||dS)NaddSkipz4TestResult has no addSkip method, skips not reported)rrwarnRuntimeWarning addSuccess)rrr"r9rrrr_addSkips  zTestCase._addSkipcks|jdus|jjsdVdS|j}|dur4t|}n |j|}t||||_zr|jj|jdddVWdn1s~0Y|jjs|jj }|dur|j rt n |jj rt W||_n||_0dS)NTr#) rrrrparams new_child_SubTestr%rrZfailfastrr)rrXrparentZ params_maprrrrsubTests$  $zTestCase.subTestcCs`|D]V\}}t|tr(||j||q|durt|d|jrN|||q|||qdSr0)r;rrr"rTrY addFailureZaddError)rrrtestr!rrr_feedErrorsToResults  zTestCase._feedErrorsToResultcCsBz |j}Wn(ty2tdt||Yn 0|||dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurerfrrrr)rrr!rrrr_addExpectedFailure s  zTestCase._addExpectedFailurec Csdz |j}WnLtyVtdtz tdWn"tyP||tYn0Yn 0||dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) addUnexpectedSuccessrfrrrrrr r!)rrrrrr_addUnexpectedSuccesss    zTestCase._addUnexpectedSuccesscCs |dSr()rrjrrr _callSetUp"szTestCase._callSetUpcCs |dSr(r)rmethodrrr_callTestMethod%szTestCase._callTestMethodcCs |dSr()rrjrrr _callTearDown(szTestCase._callTearDowncOs||i|dSr(rrrrr _callCleanup+szTestCase._callCleanupNc Cs|dur8|}t|dd}t|dd}|dur<|nd}||z,t||j}t|jddspt|ddrt|jddpt|dd}|||||W|||dur|St|ddpt|dd}t|}zf||_| || Wdn1s 0Y|j r||_ |j |dd | |Wdn1sR0Yd|_ | ||Wdn1s0Y||jD]\}} |||| q|||j|j r|r|jr|||jn ||n |||W|jd|_d|_W|||dur>|S|jd|_d|_0W|||dur|n|||dur|0dS) N startTestRun stopTestRunr?Fr@rCrKTr)rrZ startTestrrrZstopTestrrr%rrrrr doCleanupsrrrrrrrclear) rrrrrskip_whyroutcomerr9rrrrun.s      ,    (* (           z TestCase.runcCsl|jp t}|jrf|j\}}}||(|j|g|Ri|Wdq 1sZ0Yq |jSr()rrrr1r%rr)rrr,r-r.rrrrqs   8zTestCase.doCleanupscCsXg|_|jrT|j\}}}z||i|WqtyP|jtYq0qdSr()ZtearDown_exceptionsrr1r2rr r!rrrrdoClassCleanups~s zTestCase.doClassCleanupscOs|j|i|Sr()r)rr-kwdsrrr__call__szTestCase.__call__cCst||j}t|jdds&t|ddrHt|jddp>t|dd}t||||||jr|j\}}}|j |g|Ri|qbdS)Nr?Fr@rC) rrrr rrrrr1r)rrrr,r-r.rrrdebugs    zTestCase.debugcCs t|dSr(r6)rr9rrrskipTestszTestCase.skipTestcCs||dSr()rY)rrXrrrfailsz TestCase.failcCs&|r"||dt|}||dS)Nz%s is not falserWrrYrexprrXrrr assertFalseszTestCase.assertFalsecCs&|s"||dt|}||dS)Nz%s is not truerrrrr assertTrueszTestCase.assertTruecCsT|js|p |S|dur|Szd||fWStyNdt|t|fYS0dS)Nz%s : %s) longMessageUnicodeDecodeErrorr)rrXrZrrrrWs  zTestCase._formatMessagecOs*t||}z|d||Wd}Sd}0dS)N assertRaisesrirh)rexpected_exceptionr-r.contextrrrrs  zTestCase.assertRaisescOst||}|d||S)N assertWarnsr}rh)rexpected_warningr-r.rrrrrs zTestCase.assertWarnscCsddlm}||||S)Nr)_AssertLogsContext)_logr)rloggerlevelrrrr assertLogss zTestCase.assertLogscCsFt|t|ur@|jt|}|dur@t|tr.z; zMismatched values: %s) rrDeprecationWarningitemsrrrrrW) rZsubsetZ dictionaryrXmissingZ mismatchedkeyvaluerZrrrassertDictContainsSubsetrs4      z!TestCase.assertDictContainsSubsetc Cst|t|}}zt|}t|}WntyFt||}Yn0||krTdSt||}|rd}dd|D}d|} ||| }|||}| |dS)NzElement counts were not equal: cSsg|] }d|qS)z First has %d, Second has %d: %rr)rMrrrr rQz-TestCase.assertCountEqual..r) r collectionsCounterrbrrrr!rWr) rrrrXZ first_seqZ second_seqZ differencesrZr+r$rrrassertCountEquals       zTestCase.assertCountEqualcCs||td||td||krt||jks@t||jkrN|||||jdd}|jdd}t|dkr|d|kr|dg}|dg}dt||}dd t ||}| ||}| | ||dS) NzFirst argument is not a stringzSecond argument is not a stringT)keependsrz rr rC)r6rr_diffThresholdrr rrrrrr!rrW)rrrrXZ firstlinesZ secondlinesrZrrrrrs       zTestCase.assertMultiLineEqualcCs2||ks.dt|t|f}||||dS)Nz%s not less than %sr-rabrXrZrrr assertLessszTestCase.assertLesscCs2||ks.dt|t|f}||||dS)Nz%s not less than or equal to %sr-rDrrrassertLessEqualszTestCase.assertLessEqualcCs2||ks.dt|t|f}||||dS)Nz%s not greater than %sr-rDrrr assertGreaterszTestCase.assertGreatercCs2||ks.dt|t|f}||||dS)Nz"%s not greater than or equal to %sr-rDrrrassertGreaterEqualszTestCase.assertGreaterEqualcCs,|dur(dt|f}||||dS)Nz%s is not Noner-rr)rXrZrrr assertIsNoneszTestCase.assertIsNonecCs"|durd}||||dS)Nzunexpectedly None)rrWrKrrrassertIsNotNoneszTestCase.assertIsNotNonecCs0t||s,dt||f}||||dS)Nz%s is not an instance of %rr;rrrWrr)rrXrZrrrr6s zTestCase.assertIsInstancecCs0t||r,dt||f}||||dS)Nz%s is an instance of %rrNrOrrrassertNotIsInstances zTestCase.assertNotIsInstancecOst|||}|d||S)NassertRaisesRegexr)rrr_r-r.rrrrrQs zTestCase.assertRaisesRegexcOst|||}|d||S)NassertWarnsRegexr)rrr_r-r.rrrrrRs zTestCase.assertWarnsRegexcCsJt|ttfrt|}||sFd|j|f}|||}||dS)Nz&Regex didn't match: %r not found in %r) r;rbytesr]r^rrrsrWrY)rtextr_rXrZrrr assertRegexs   zTestCase.assertRegexcCs`t|ttfrt|}||}|r\d||||j|f}| ||}| |dS)Nz"Regex matched: %r matches %r in %r) r;rrSr]r^rrstartendrsrWrY)rrTZunexpected_regexrXmatchrZrrrassertNotRegex#s   zTestCase.assertNotRegexcsfdd}|S)Ncs$tdjtd|i|S)NzPlease use {0} instead.r)rrrmr r8r7 original_funcrrdeprecated_func3s  z,TestCase._deprecate..deprecated_funcr)r[r\rrZr _deprecate2s zTestCase._deprecate)r)N)N)N)N)NN)N)N)N)NNN)NNN)NN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)cr r r AssertionErrorrYrr&rCZ_classSetupFailedrrrrrzrrrrrrrrrrrrrrr&r'_subtest_msg_sentinelrrrrrrrrrrrrrrrrrrWrrrrrr r rrr%r!rrrr1r2r4r5rr=rArrGrHrIrJrLrMr6rPrQrRrUrYr]ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrr5s!         C     !     - # c +                    rcsfeZdZdfdd ZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ Z S)FunctionTestCaseNcs*tt|||_||_||_||_dSr()superr`r _setUpFunc _tearDownFunc _testFunc _description)rZtestFuncrr descriptionrrrrQs zFunctionTestCase.__init__cCs|jdur|dSr()rbrjrrrrXs zFunctionTestCase.setUpcCs|jdur|dSr()rcrjrrrr\s zFunctionTestCase.tearDowncCs |dSr()rdrjrrrr`szFunctionTestCase.runTestcCs|jjSr()rdr rjrrrrcszFunctionTestCase.idcCs@t||jstS|j|jko>|j|jko>|j|jko>|j|jkSr()r;rrrbrcrdrerrrrrfs     zFunctionTestCase.__eq__cCstt||j|j|j|jfSr()rr<rbrcrdrerjrrrroszFunctionTestCase.__hash__cCsdt|j|jjfSr)rrrdr rjrrrrss zFunctionTestCase.__str__cCsdt|j|jfS)Nz <%s tec=%s>)rrrdrjrrrrws zFunctionTestCase.__repr__cCs2|jdur|jS|jj}|r.|ddp0dSr)rerdrrrrrrrr{s z!FunctionTestCase.shortDescription)NNN)r r r rrrrrrrrrr __classcell__rrrgrr`Hs  r`csDeZdZfddZddZddZddZd d Zd d ZZ S) rcs(t||_||_||_|j|_dSr()rar_messager"rrY)rr"rrrgrrrs  z_SubTest.__init__cCs tddS)Nzsubtests cannot be run directly)rrjrrrrsz_SubTest.runTestcCs^g}|jtur |d|j|jrPddd|jD}|d|d|p\dS)Nz[{}]z, css|]\}}d||VqdS)z{}={!r}N)rm)rMrrrrrrPsz+_SubTest._subDescription..z({}) z ())rir_rrmrrr9)rpartsZ params_descrrr_subDescriptions  z_SubTest._subDescriptioncCsd|j|SNz{} {})rmr"rrlrjrrrrsz _SubTest.idcCs |jSr()r"rrjrrrrsz_SubTest.shortDescriptioncCsd|j|Srm)rmr"rlrjrrrrsz_SubTest.__str__) r r r rrrlrrrrhrrrgrrs   r)-r r=rrr]rr?r&rnrDrCrutilrrrrrZ __unittestobjectr_r'r2r rrrr*r+r/r5rFrIrJrrLrVr\rir}ChainMaprrr`rrrrrsV ( *'5 :