o 0¦iPáã@s’dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZdZeƒZdZGdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZdd„ZgZdd„Zdd„Zdd„Z dd„Z!dd„Z"dd„Z#dd„Z$Gd d!„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+eƒZ+Gd,d-„d-e+ƒZ,Gd.d/„d/e+ƒZ-dS)0zTest case implementationé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@óeZdZdZdS)ÚSkipTestz© Raise this exception in a test to skip it. Usually you can use TestCase.skipTest() or one of the skipping decorators instead of raising this directly. N©Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú4/opt/alt/python310/lib64/python3.10/unittest/case.pyr ór c@r )Ú _ShouldStopz The test should stop. Nr rrrrr!rrc@r )Ú_UnexpectedSuccessz7 The test was supposed to fail, but it didn't! Nr rrrrr&rrc@s&eZdZddd„Zejddd„ƒZdS) Ú_OutcomeNcCs4d|_||_t|dƒ|_d|_g|_d|_g|_dS)NFÚ addSubTestT)Úexpecting_failurerÚhasattrÚresult_supports_subtestsÚsuccessÚskippedÚexpectedFailureÚerrors)ÚselfrrrrÚ__init__-s  z_Outcome.__init__Fc csì�|j}d|_zgzdVWnJty‚ty3}zd|_|j |t|ƒf¡WYd}~n7d}~wty;Yn+t ¡}|j rI||_ n d|_|j  ||f¡d}Yn|j rf|jrf|j  |df¡W|jok||_dS|jos||_w)NTF) rÚKeyboardInterruptr rÚappendÚstrrÚsysÚexc_inforrrr)rÚ test_caseÚisTestZ old_successÚer$rrrÚtestPartExecutor6s0€   €  €z_Outcome.testPartExecutor©N)F)r r rrÚ contextlibÚcontextmanagerr(rrrrr,s  rcCó|Sr)r)ÚobjrrrÚ_idTór.cOst |||f¡dS)znSame as addCleanup, except the cleanup items are called even if setUpModule fails (unlike tearDownModule).N)Ú_module_cleanupsr!)ÚfunctionÚargsÚkwargsrrrÚaddModuleCleanupYsr4c Cslg}tr.t ¡\}}}z ||i|¤ŽWnty+}z | |¡WYd}~nd}~wwts|r4|d‚dS)zWExecute all module cleanup functions. Normally called for you after tearDownModule.Nr)r0ÚpopÚ Exceptionr!)Ú exceptionsr1r2r3ÚexcrrrÚdoModuleCleanups_s€ÿüýr9cs,‡fdd„}tˆtjƒrˆ}d‰||ƒS|S)z& Unconditionally skip a test. cs4t|tƒst |¡‡fdd„ƒ}|}d|_ˆ|_|S)Ncstˆƒ‚r)©r ©r2r3©ÚreasonrrÚ skip_wrapperuóz-skip..decorator..skip_wrapperT)Ú isinstanceÚtypeÚ functoolsÚwrapsÚ__unittest_skip__Ú__unittest_skip_why__)Ú test_itemr>r<rrÚ decoratorss zskip..decoratorÚ)r@ÚtypesÚ FunctionType)r=rGrFrr<rÚskipos  rKcCs|rt|ƒStS)z/ Skip a test if the condition is true. ©rKr.©Z conditionr=rrrÚskipIfƒórNcCs|st|ƒStS)z3 Skip a test unless the condition is true. rLrMrrrÚ skipUnless‹rOrPcCs d|_|S)NT)Ú__unittest_expecting_failure__)rFrrrr“srcs4t|tƒrt‡fdd„|DƒƒSt|tƒot|ˆƒS)Nc3s�|]}t|ˆƒVqdSr))Ú _is_subtype)Ú.0r'©ÚbasetyperrÚ ™s€z_is_subtype..)r@ÚtupleÚallrAÚ issubclass)ÚexpectedrUrrTrrR—s rRc@seZdZdd„Zdd„ZdS)Ú_BaseTestCaseContextcCs ||_dSr))r%)rr%rrrržó z_BaseTestCaseContext.__init__cCs|j |j|¡}|j |¡‚r))r%Ú_formatMessageÚmsgÚfailureException)rÚ standardMsgr^rrrÚ _raiseFailure¡s z"_BaseTestCaseContext._raiseFailureN)r r rrrarrrrr[œs r[c@seZdZddd„Zdd„ZdS)Ú_AssertRaisesBaseContextNcCs@t ||¡||_||_|durt |¡}||_d|_d|_dSr)) r[rrZr%ÚreÚcompileÚexpected_regexÚobj_namer^)rrZr%rerrrr§s   z!_AssertRaisesBaseContext.__init__cCsÖzgt|j|jƒstd||jfƒ‚|s,| dd¡|_|r'tdtt|ƒƒfƒ‚|Wd}S|^}}z|j |_ Wnt yDt |ƒ|_ Ynw|�||i|¤ŽWdƒn 1sYwYWd}dSWd}dSd}w)zî If args is empty, assertRaises/Warns is being used as a context manager, so check for a 'msg' kwarg and return self. If args is not empty, call a callable passing positional and keyword arguments. z%s() arg 1 must be %sr^Nz3%r is an invalid keyword argument for this function) rRrZÚ _base_typeÚ TypeErrorÚ_base_type_strr5r^ÚnextÚiterr rfÚAttributeErrorr")rÚnamer2r3Z callable_objrrrÚhandle±s2ÿ ÿ ÷  ÿÿüz_AssertRaisesBaseContext.handler))r r rrrnrrrrrb¥s  rbc@s2eZdZdZeZdZdd„Zdd„Ze e j ƒZ dS)Ú_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-an exception type or tuple of exception typescCr,r)r©rrrrÚ __enter__Õr/z_AssertRaisesContext.__enter__cCsÄ|dur0z|jj}Wntyt|jƒ}Ynw|jr'| d ||j¡¡n| d |¡¡nt |¡t ||jƒs=dS|  d¡|_ |j durJdS|j }|  t|ƒ¡s`| d |jt|ƒ¡¡dS)Nz{} not raised by {}z {} not raisedFTú"{}" does not match "{}")rZr rlr"rfraÚformatÚ tracebackÚ clear_framesrYÚwith_tracebackZ exceptionreÚsearchÚpattern)rÚexc_typeÚ exc_valueÚtbÚexc_namererrrÚ__exit__Øs.  ÿ ÿ     ÿz_AssertRaisesContext.__exit__N) r r rrÚ BaseExceptionrgrirqr}Ú classmethodrIÚ GenericAliasÚ__class_getitem__rrrrroÏsroc@s(eZdZdZeZdZdd„Zdd„ZdS)Ú_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRttj ¡ƒD] }t|ddƒri|_qtjdd�|_|j  ¡|_t  d|j ¡|S)NÚ__warningregistry__T)ÚrecordÚalways) Úlistr#ÚmodulesÚvaluesÚgetattrrƒÚwarningsÚcatch_warningsÚwarnings_managerrqÚ simplefilterrZ)rÚvrrrrqüs € z_AssertWarnsContext.__enter__cCs|j |||¡|durdSz|jj}Wnty"t|jƒ}Ynwd}|jD]-}|j}t||jƒs4q(|dur:|}|j durH|j   t|ƒ¡sHq(||_ |j |_ |j |_ dS|durg| d |j jt|ƒ¡¡|jrv| d ||j¡¡dS| d |¡¡dS)Nrrz{} not triggered by {}z{} not triggered)rŒr}rZr rlr"rŠÚmessager@rerwZwarningÚfilenameÚlinenorarsrxrf)rryrzr{r|Zfirst_matchingÚmÚwrrrr}s@  ÿ   ÿ ÿ  ÿz_AssertWarnsContext.__exit__N) r r rrÚWarningrgrirqr}rrrrr‚ös  r‚c@seZdZdd„ZdS)Ú_OrderedChainMapccs:�tƒ}|jD]}|D]}||vr| |¡|Vq qdSr))ÚsetÚmapsÚadd)rÚseenÚmappingÚkrrrÚ__iter__+s€  €ýÿz_OrderedChainMap.__iter__N)r r rrœrrrrr•*s r•cs2eZdZdZeZdZdZdZ‡fdd„Z d—dd „Z d d „Z d d „Z e dd„ƒZdd„Zdd„Ze dd„ƒZe dd„ƒZdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zejefd*d+„ƒZd,d-„Z d.d/„Z!d0d1„Z"d2d3„Z#d4d5„Z$d6d7„Z%d8d9„Z&d˜d;d<„Z'd=d>„Z(e d?d@„ƒZ)dAdB„Z*dCdD„Z+dEdF„Z,d˜dGdH„Z-d˜dIdJ„Z.d˜dKdL„Z/dMdN„Z0dOdP„Z1dQdR„Z2d™dSdT„Z3d™dUdV„Z4dWdX„Z5d˜dYdZ„Z6d˜d[d\„Z7d˜d]d^„Z8 : :dšd_d`„Z9 : :dšdadb„Z:d™dcdd„Z;dedf„Zd˜dkdl„Z?d˜dmdn„Z@d˜dodp„ZAd˜dqdr„ZBd˜dsdt„ZCd˜dudv„ZDd˜dwdx„ZEd˜dydz„ZFd˜d{d|„ZGd˜d}d~„ZHd˜dd€„ZId˜d�d‚„ZJd˜dƒd„„ZKd˜d…d†„ZLd˜d‡dˆ„ZMd˜d‰dŠ„ZNd˜d‹dŒ„ZOd�dŽ„ZPd�d�„ZQd˜d‘d’„ZRd˜d“d”„ZSd•d–„ZTeTe7ƒZUZVeTe8ƒZWZXeTe9ƒZYZZeTe:ƒZ[Z\eTe/ƒZ]Z^eTe1ƒZ_eTe.ƒZ`eTePƒZaeTeRƒZbeTeSƒZc‡ZdS)›ÚTestCaseaWA class whose instances are single test cases. By default, the test code itself should be placed in a method named 'runTest'. If the fixture may be used for many test cases, create as many test methods as are needed. When instantiating such a TestCase subclass, specify in the constructor arguments the name of the test method that the instance is to execute. Test authors should subclass TestCase for their own tests. Construction and deconstruction of the test's environment ('fixture') can be implemented by overriding the 'setUp' and 'tearDown' methods respectively. If it is necessary to override the __init__ method, the base class __init__ method must always be called. It is important that subclasses should not change the signature of their __init__ method, since instances of the classes are instantiated automatically by parts of the framework in order to be run. When subclassing TestCase, you can set these attributes: * failureException: determines which exception will be raised when the instance's assertion methods fail; test methods raising this exception will be deemed to have 'failed' rather than 'errored'. * longMessage: determines whether long messages (including repr of objects used in assert methods) will be printed on failure in *addition* to any explicit message passed. * maxDiff: sets the maximum length of a diff in failure messages by assert methods using difflib. It is looked up as an instance attribute so can be configured by individual tests if required. Ti€ics"d|_g|_tƒj|i|¤ŽdS)NF)Z_classSetupFailedÚ_class_cleanupsÚsuperÚ__init_subclass__)Úclsr2r3©Ú __class__rrr _szTestCase.__init_subclass__ÚrunTestcCs´||_d|_d|_zt||ƒ}Wnty&|dkr$td|j|fƒ‚Ynw|j|_g|_d|_ i|_ |  t d¡|  t d¡|  td¡|  td¡|  td¡|  td ¡dS) zÅCreate an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name. NzNo testr¤zno such test method in %s: %sÚassertDictEqualÚassertListEqualÚassertTupleEqualÚassertSetEqualÚassertMultiLineEqual)Ú_testMethodNameÚ_outcomeÚ_testMethodDocr‰rlÚ ValueErrorr£rÚ _cleanupsÚ_subtestÚ_type_equality_funcsÚaddTypeEqualityFuncÚdictr†rWr–Ú frozensetr")rZ methodNameÚ testMethodrrrres, ÿýÿ     zTestCase.__init__cCs||j|<dS)a[Add a type specific assertEqual style function to compare a type. This method is for use by TestCase subclasses that need to register their own type equality functions to provide nicer error messages. Args: typeobj: The data type to call this function on when both values are of the same type in assertEqual(). function: The callable taking two arguments and an optional msg= argument that raises self.failureException with a useful error message when the two arguments are not equal. N)r°)rZtypeobjr1rrrr±…s zTestCase.addTypeEqualityFunccOó|j |||f¡dS)aAdd a function, with arguments, to be called when the test is completed. Functions added are called on a LIFO basis and are called after tearDown on test failure or success. Cleanup items are called even if setUp fails (unlike tearDown).N)r®r!©rr1r2r3rrrÚ addCleanup”szTestCase.addCleanupcOrµ)zpSame as addCleanup, except the cleanup items are called even if setUpClass fails (unlike tearDownClass).N)ržr!©r¡r1r2r3rrrÚaddClassCleanupœszTestCase.addClassCleanupcCódS)zAHook method for setting up the test fixture before exercising it.NrrprrrÚsetUp¢ózTestCase.setUpcCrº)zAHook method for deconstructing the test fixture after testing it.NrrprrrÚtearDown¦r¼zTestCase.tearDowncCrº)zKHook method for setting up class fixture before running tests in the class.Nr©r¡rrrÚ setUpClassªózTestCase.setUpClasscCrº)zVHook method for deconstructing the class fixture after running all tests in the class.Nrr¾rrrÚ tearDownClass®rÀzTestCase.tearDownClasscCrº)NrrrprrrÚcountTestCases²r/zTestCase.countTestCasescCst ¡Sr))rZ TestResultrprrrÚdefaultTestResultµózTestCase.defaultTestResultcCs$|j}|r| ¡ d¡d ¡SdS)zåReturns a one-line description of the test, or None if no description has been provided. The default implementation of this method returns the first line of the specified test method's docstring. Ú rN)r¬ÚstripÚsplit©rÚdocrrrÚshortDescription¸szTestCase.shortDescriptioncCódt|jƒ|jfS)Nz%s.%s©rr£rªrprrrÚidÃóz TestCase.idcCs t|ƒt|ƒur tS|j|jkSr))rAÚNotImplementedrª©rÚotherrrrÚ__eq__Æs zTestCase.__eq__cCstt|ƒ|jfƒSr))ÚhashrArªrprrrÚ__hash__ÌózTestCase.__hash__cCsd|jt|jƒfS©Nz%s (%s))rªrr£rprrrÚ__str__ÏrÎzTestCase.__str__cCrË)Nz<%s testMethod=%s>rÌrprrrÚ__repr__ÒsÿzTestCase.__repr__cCs>t|ddƒ}|dur|||ƒdSt dtd¡| |¡dS)NÚaddSkipz4TestResult has no addSkip method, skips not reportedé)r‰rŠÚwarnÚRuntimeWarningÚ addSuccess)rrr%r=rÙrrrÚ_addSkipÖs ÿzTestCase._addSkipcksÚ�|jdus |jjsdVdS|j}|durt|ƒ}n|j |¡}t|||ƒ|_z@|jj|jdd�� dVWdƒn1s@wY|jjsW|jj }|durV|j rVt ‚n |jj r]t ‚W||_dSW||_dS||_w)aPReturn a context manager that will return the enclosed block of code in a subtest identified by the optional message and keyword parameters. A failure in the subtest marks the test case as failed but resumes execution at the end of the enclosed block, allowing further test code to be executed. NT©r&) r«rr¯r•ÚparamsÚ new_childÚ_SubTestr(rrZfailfastrr)rr^ràÚparentZ params_maprrrrÚsubTestßs0€  ÿ€ý €zTestCase.subTestcCs`|D]+\}}t|tƒr| |j||¡q|dur-t|d|jƒr'| ||¡q| ||¡qdS)Nr)r@rârr%rYr_Ú addFailureZaddError)rrrÚtestr$rrrÚ_feedErrorsToResultþs   €ùzTestCase._feedErrorsToResultcCsDz|j}Wntyt dt¡| |¡YdSw|||ƒdS)Nz@TestResult has no addExpectedFailure method, reporting as passes)ÚaddExpectedFailurerlrŠrÛrÜrÝ)rrr$rèrrrÚ_addExpectedFailures  ÿýzTestCase._addExpectedFailurec Cs`z|j}Wn$ty)t dt¡ztd‚ty(| |t ¡¡YYdSww||ƒdS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) ÚaddUnexpectedSuccessrlrŠrÛrÜrrår#r$)rrrêrrrÚ_addUnexpectedSuccesss  ÿ ÿù zTestCase._addUnexpectedSuccesscCó | ¡dSr))r»rprrrÚ _callSetUp!ó zTestCase._callSetUpcCs |ƒdSr)r)rÚmethodrrrÚ_callTestMethod$r\zTestCase._callTestMethodcCrìr))r½rprrrÚ _callTearDown'rîzTestCase._callTearDowncOs||i|¤ŽdSr)rr¶rrrÚ _callCleanup*rÕzTestCase._callCleanupNc Csh|dur| ¡}t|ddƒ}t|ddƒ}|dur|ƒnd}| |¡�zt||jƒ}t|jddƒs8t|ddƒr\t|jddƒpDt|ddƒ}| |||¡|W| |¡|dur[|ƒSSt|ddƒpgt|ddƒ}t|ƒ}z¬||_|  |¡� |  ¡Wdƒn1s„wY|j rÇ||_ |j |dd �� |  |¡Wdƒn1s¦wYd|_ |  |¡� | ¡Wdƒn1sÂwY| ¡|jD] \}} | ||| ¡qÎ| ||j¡|j rü|r÷|jrñ| ||j¡n | |¡n| |¡|W|j ¡d|_d|_W| |¡|du�r|ƒSS|j ¡d|_d|_w| |¡|du�r3|ƒww) NÚ startTestRunÚ stopTestRunrDFrErHrQTrß)rÃr‰Z startTestrªr£rÞZstopTestrr«r(rírrrðrñÚ doCleanupsrrçrrrérërÝÚclear) rrrórôr´Úskip_whyrÚoutcomerær=rrrÚrun-s„  €   ÿ ÿ ,ÿ Ö þ  ÿ ÿ  ÿ     ÿ ø  ÿz TestCase.runcCsp|jptƒ}|jr5|j ¡\}}}| |¡�|j|g|¢Ri|¤ŽWdƒn1s-wY|js |jS)zNExecute all cleanup functions. Normally called for you after tearDown.N)r«rr®r5r(ròr)rrør1r2r3rrrrõps  ÿþzTestCase.doCleanupscCs`g|_|jr.|j ¡\}}}z ||i|¤ŽWnty(|j t ¡¡Ynw|jsdSdS)zYExecute all class cleanup functions. Normally called for you after tearDownClass.N)ZtearDown_exceptionsržr5r6r!r#r$r¸rrrÚdoClassCleanups}s ÿüzTestCase.doClassCleanupscOs|j|i|¤ŽSr))rù)rr2ÚkwdsrrrÚ__call__‰szTestCase.__call__cCsžt||jƒ}t|jddƒst|ddƒr$t|jddƒpt|ddƒ}t|ƒ‚| ¡| |¡| ¡|jrM|j ¡\}}}|j |g|¢Ri|¤Ž|js4dSdS)z6Run the test without collecting errors in a TestResultrDFrErHN) r‰rªr£r rírðrñr®r5rò)rr´r÷r1r2r3rrrÚdebugŒs  ÿ ÿ þzTestCase.debugcCst|ƒ‚)zSkip this test.r:)rr=rrrÚskipTest�r?zTestCase.skipTestcCs | |¡‚)z)Fail immediately, with the given message.)r_)rr^rrrÚfail¡s z TestCase.failcCs&|r| |dt|ƒ¡}| |¡‚dS)z#Check that the expression is false.z%s is not falseN©r]rr_©rÚexprr^rrrÚ assertFalse¥ó þzTestCase.assertFalsecCs&|s| |dt|ƒ¡}| |¡‚dS)z"Check that the expression is true.z%s is not trueNrrrrrÚ assertTrue«rzTestCase.assertTruecCsP|js|p|S|dur |Szd||fWSty'dt|ƒt|ƒfYSw)a‚Honour the longMessage attribute when generating failure messages. If longMessage is False this means: * Use only an explicit message if it is provided * Otherwise use the standard message for the assert If longMessage is True: * Use the standard message * If an explicit message is provided, plus ' : ' and the explicit message Nz%s : %s)Ú longMessageÚUnicodeDecodeErrorr)rr^r`rrrr]±s  ÿzTestCase._formatMessagecOs&t||ƒ}z | d||¡Wd}Sd}w)a=Fail unless an exception of class expected_exception is raised by the callable when invoked with specified positional and keyword arguments. If a different type of exception is raised, it will not be caught, and the test case will be deemed to have suffered an error, exactly as for an unexpected exception. If called with the callable and arguments omitted, will return a context object used like this:: with self.assertRaises(SomeException): do_something() An optional keyword argument 'msg' can be provided when assertRaises is used as a context object. The context manager keeps a reference to the exception as the 'exception' attribute. This allows you to inspect the exception after the assertion:: with self.assertRaises(SomeException) as cm: do_something() the_exception = cm.exception self.assertEqual(the_exception.error_code, 3) Ú assertRaisesN©rorn)rÚexpected_exceptionr2r3ÚcontextrrrrÆs  zTestCase.assertRaisescOst||ƒ}| d||¡S)aîFail unless a warning of class warnClass is triggered by the callable when invoked with specified positional and keyword arguments. If a different type of warning is triggered, it will not be handled: depending on the other warning filtering rules in effect, it might be silenced, printed out, or raised as an exception. If called with the callable and arguments omitted, will return a context object used like this:: with self.assertWarns(SomeWarning): do_something() An optional keyword argument 'msg' can be provided when assertWarns is used as a context object. The context manager keeps a reference to the first matching warning as the 'warning' attribute; similarly, the 'filename' and 'lineno' attributes give you information about the line of Python code from which the warning was triggered. This allows you to inspect the warning after the assertion:: with self.assertWarns(SomeWarning) as cm: do_something() the_warning = cm.warning self.assertEqual(the_warning.some_attribute, 147) Ú assertWarns©r‚rn)rÚexpected_warningr2r3r rrrr çs zTestCase.assertWarnscCóddlm}||||dd�S)ažFail unless a log message of level *level* or higher is emitted on *logger_name* or its children. If omitted, *level* defaults to INFO and *logger* defaults to the root logger. This method must be used as a context manager, and will yield a recording object with two attributes: `output` and `records`. At the end of the context manager, the `output` attribute will be a list of the matching formatted log messages and the `records` attribute will be a list of the corresponding LogRecord objects. Example:: with self.assertLogs('foo', level='INFO') as cm: logging.getLogger('foo').info('first message') logging.getLogger('foo.bar').error('second message') self.assertEqual(cm.output, ['INFO:foo:first message', 'ERROR:foo.bar:second message']) r©Ú_AssertLogsContextF©Zno_logs©Z_logr©rZloggerÚlevelrrrrÚ assertLogss zTestCase.assertLogscCr)z® Fail unless no log messages of level *level* or higher are emitted on *logger_name* or its children. This method must be used as a context manager. rrTrrrrrrÚ assertNoLogss zTestCase.assertNoLogscCsFt|ƒt|ƒur |j t|ƒ¡}|dur t|tƒrt||ƒ}|S|jS)aGet a detailed comparison function for the types of the two args. Returns: A callable accepting (first, second, msg=None) that will raise a failure exception if first != second with a useful human readable error message for those types. N)rAr°Úgetr@r"r‰Ú_baseAssertEqual)rÚfirstÚsecondZasserterrrrÚ_getAssertEqualityFunc's  zTestCase._getAssertEqualityFunccCs0||ksdt||ƒ}| ||¡}| |¡‚dS)z:The default assertEqual implementation, not type specific.ú%s != %sN)rr]r_)rrrr^r`rrrrAs   ýzTestCase._baseAssertEqualcCs| ||¡}||||d�dS)z[Fail if the two objects are unequal as determined by the '==' operator. )r^N)r)rrrr^Zassertion_funcrrrÚ assertEqualHs zTestCase.assertEqualcCs2||ks| |dt|ƒt|ƒf¡}| |¡‚dS)zYFail if the two objects are equal as determined by the '!=' operator. z%s == %sNr)rrrr^rrrÚassertNotEqualOs ÿ ýzTestCase.assertNotEqualcCs¶||krdS|dur|durtdƒ‚t||ƒ}|dur3||kr"dSdt|ƒt|ƒt|ƒt|ƒf}n|dur9d}t||ƒdkrBdSdt|ƒt|ƒ|t|ƒf}| ||¡}| |¡‚)a'Fail if the two objects are unequal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is more than the given delta. Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit). If the two objects compare equal then they will automatically compare almost equal. Nú specify delta or places not bothz(%s != %s within %s delta (%s difference)érz)%s != %s within %r places (%s difference)©rhÚabsrÚroundr]r_©rrrZplacesr^ZdeltaÚdiffr`rrrÚassertAlmostEqualXs4 üü  zTestCase.assertAlmostEqualcCs´|dur |dur tdƒ‚t||ƒ}|dur1||ks ||kr dSdt|ƒt|ƒt|ƒt|ƒf}n|dur7d}||ksDt||ƒdkrDdSdt|ƒt|ƒ|f}| ||¡}| |¡‚)aæFail if the two objects are equal as determined by their difference rounded to the given number of decimal places (default 7) and comparing to zero, or by comparing that the difference between the two objects is less than the given delta. Note that decimal places (from zero) are usually not the same as significant digits (measured from the most significant digit). Objects that are equal automatically fail. Nr z(%s == %s within %s delta (%s difference)r!rz%s == %s within %r placesr"r%rrrÚassertNotAlmostEqual…s,  üþ  zTestCase.assertNotAlmostEqualc CsÒ|dur(|j}t||ƒs| d|t|ƒf¡‚t||ƒs'| d|t|ƒf¡‚nd}d}zt|ƒ}WnttfyAd|}Ynw|dur\zt|ƒ}Wnttfy[d|}Ynw|du�r?||krgdSd| ¡ft||ƒ}t t ||ƒƒD]L} z|| } Wntt tfy—|d| |f7}YnBwz|| } Wntt tfy³|d | |f7}Yn&w| | krÆ|d | ft| | ƒ7}nqz||krÙ|durÙt |ƒt |ƒkrÙdS||k�r |d |||f7}z|d |t||ƒf7}WnHtt tf�y |d ||f7}Yn4w||k�r?|d|||f7}z|d |t||ƒf7}Wntt tf�y>|d||f7}Ynw|} dd  t t |¡ ¡t |¡ ¡¡¡} | | | ¡} | || ¡}| |¡dS)aAAn equality assertion for ordered sequences (like lists and tuples). For the purposes of this function, a valid ordered sequence type is one which can be indexed, has a length, and has an equality operator. Args: seq1: The first sequence to compare. seq2: The second sequence to compare. seq_type: The expected datatype of the sequences, or None if no datatype should be enforced. msg: Optional message to use on failure instead of a list of differences. NzFirst sequence is not a %s: %szSecond sequence is not a %s: %sZsequencez(First %s has no length. Non-sequence?z)Second %s has no length. Non-sequence?z%ss differ: %s != %s z( Unable to index element %d of first %s z) Unable to index element %d of second %s z# First differing element %d: %s %s z+ First %s contains %d additional elements. zFirst extra element %d: %s z'Unable to index element %d of first %s z, Second %s contains %d additional elements. z(Unable to index element %d of second %s rÅ)r r@r_rÚlenrhÚNotImplementedErrorÚ capitalizerÚrangeÚminÚ IndexErrorrAÚjoinÚdifflibÚndiffÚpprintÚpformatÚ splitlinesÚ_truncateMessager]rÿ)rZseq1Zseq2r^Úseq_typeZ seq_type_nameZ differingZlen1Zlen2ÚiZitem1Zitem2r`ÚdiffMsgrrrÚassertSequenceEqual¨s  ÿ  ÿÿ ÿÿ ÿÿ ÿÿ ÿý ÿýÿý  ÿ ÿ ÿÿ  ÿ ÿ ÿÿ ÿÿ  zTestCase.assertSequenceEqualcCs2|j}|dus t|ƒ|kr||S|tt|ƒSr))ÚmaxDiffr)Ú DIFF_OMITTED)rr�r&Zmax_diffrrrr5 szTestCase._truncateMessagecCó|j|||td�dS)aA list-specific equality assertion. Args: list1: The first list to compare. list2: The second list to compare. msg: Optional message to use on failure instead of a list of differences. ©r6N)r9r†)rZlist1Zlist2r^rrrr¦s zTestCase.assertListEqualcCr<)aA tuple-specific equality assertion. Args: tuple1: The first tuple to compare. tuple2: The second tuple to compare. msg: Optional message to use on failure instead of a list of differences. r=N)r9rW)rZtuple1Ztuple2r^rrrr§s zTestCase.assertTupleEqualc Cs`z| |¡}Wn1ty }z | d|¡WYd}~nd}~wty8}z | d|¡WYd}~nd}~wwz| |¡}Wn1tyY}z | d|¡WYd}~nd}~wtyq}z | d|¡WYd}~nd}~ww|sx|sxdSg}|r�| d¡|D] }| t|ƒ¡qƒ|r | d¡|D] }| t|ƒ¡q–d |¡} | | || ¡¡dS)a¯A set-specific equality assertion. Args: set1: The first set to compare. set2: The second set to compare. msg: Optional message to use on failure instead of a list of differences. assertSetEqual uses ducktyping to support different types of sets, and is optimized for sets specifically (parameters must support a difference method). z/invalid type when attempting set difference: %sNz2first argument does not support set difference: %sz3second argument does not support set difference: %sz*Items in the first set but not the second:z*Items in the second set but not the first:rÅ)Ú differencerhrÿrlr!Úreprr/r]) rZset1Zset2r^Z difference1r'Z difference2ÚlinesÚitemr`rrrr¨(s> €€ÿ€€ÿ   zTestCase.assertSetEqualcCs6||vrdt|ƒt|ƒf}| | ||¡¡dSdS)zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sN©rrÿr]©rÚmemberZ containerr^r`rrrÚassertInSó ÿýzTestCase.assertIncCs6||vrdt|ƒt|ƒf}| | ||¡¡dSdS)zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sNrBrCrrrÚ assertNotInZrFzTestCase.assertNotIncCs6||urdt|ƒt|ƒf}| | ||¡¡dSdS)zDJust like self.assertTrue(a is b), but with a nicer default message.z %s is not %sNrB©rZexpr1Zexpr2r^r`rrrÚassertIsarFzTestCase.assertIscCs0||urdt|ƒf}| | ||¡¡dSdS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sNrBrHrrrÚ assertIsNothóþzTestCase.assertIsNotc Cs‚| |td¡| |td¡||kr?dt||ƒ}dd t t |¡ ¡t |¡ ¡¡¡}|  ||¡}|  |  ||¡¡dSdS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryrrÅ) ÚassertIsInstancer²rr/r0r1r2r3r4r5rÿr])rZd1Zd2r^r`r&rrrr¥ns   þ úzTestCase.assertDictEqualc CsÒtjdtdd�g}g}| ¡D]&\}}||vr| |¡q|||kr6| dt|ƒt|ƒt||ƒf¡q|s=|s=dSd}|rMdd d d „|Dƒ¡}|r^|rU|d 7}|d d |¡7}| | ||¡¡dS) z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedrÚ)Ú stacklevelz%s, expected: %s, actual: %sNrHz Missing: %sú,css�|]}t|ƒVqdSr))r)rSr’rrrrVŽs€z4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rŠrÛÚDeprecationWarningÚitemsr!rr/rÿr]) rZsubsetZ dictionaryr^ZmissingZ mismatchedÚkeyÚvaluer`rrrÚassertDictContainsSubsetzs8þ    ÿÿ€  ÿz!TestCase.assertDictContainsSubsetc Cs¨t|ƒt|ƒ}}z t |¡}t |¡}Wnty#t||ƒ}Yn w||kr*dSt||ƒ}|rRd}dd„|Dƒ}d |¡} | || ¡}| ||¡}|  |¡dSdS)a[Asserts that two iterables have the same elements, the same number of times, without regard to order. self.assertEqual(Counter(list(first)), Counter(list(second))) Example: - [0, 1, 1] and [1, 0, 1] compare equal. - [0, 0, 1] and [0, 1] compare unequal. NzElement counts were not equal: cSsg|]}d|‘qS)z First has %d, Second has %d: %rr)rSr&rrrÚ ²sz-TestCase.assertCountEqual..rÅ) r†Ú collectionsÚCounterrhrrr/r5r]rÿ) rrrr^Z first_seqZ second_seqZ differencesr`r@r8rrrÚassertCountEqual˜s$   þ    úzTestCase.assertCountEqualcCsÞ| |td¡| |td¡||krmt|ƒ|jks t|ƒ|jkr'| |||¡|jdd�}|jdd�}t|ƒdkrJ| d¡|krJ|dg}|dg}dt||ƒ}dd  t   ||¡¡}|  ||¡}|  |  ||¡¡d Sd S) z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringT)Úkeependsrz rÅrrHN)rLr"r)Ú_diffThresholdrr4rÆrr/r0r1r5rÿr])rrrr^Z firstlinesZ secondlinesr`r&rrrr©¸s      ózTestCase.assertMultiLineEqualcCs6||ksdt|ƒt|ƒf}| | ||¡¡dSdS)zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sNrB©rÚaÚbr^r`rrrÚ assertLessÌóþzTestCase.assertLesscCs6||ksdt|ƒt|ƒf}| | ||¡¡dSdS)zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sNrBrZrrrÚassertLessEqualÒr^zTestCase.assertLessEqualcCs6||ksdt|ƒt|ƒf}| | ||¡¡dSdS)zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sNrBrZrrrÚ assertGreaterØr^zTestCase.assertGreatercCs6||ksdt|ƒt|ƒf}| | ||¡¡dSdS)zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sNrBrZrrrÚassertGreaterEqualÞr^zTestCase.assertGreaterEqualcCs0|durdt|ƒf}| | ||¡¡dSdS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not NonerB©rr-r^r`rrrÚ assertIsNoneärKzTestCase.assertIsNonecCs&|durd}| | ||¡¡dSdS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)rÿr]rbrrrÚassertIsNotNoneêsþzTestCase.assertIsNotNonecCs4t||ƒsdt|ƒ|f}| | ||¡¡dSdS)zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer default message.z%s is not an instance of %rN©r@rrÿr]©rr-r¡r^r`rrrrLðs þzTestCase.assertIsInstancecCs4t||ƒrdt|ƒ|f}| | ||¡¡dSdS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rNrerfrrrÚassertNotIsInstance÷s þzTestCase.assertNotIsInstancecOót|||ƒ}| d||¡S)aAsserts that the message in a raised exception matches a regex. Args: expected_exception: Exception class expected to be raised. expected_regex: Regex (re.Pattern object or string) expected to be found in error message. args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used when assertRaisesRegex is used as a context manager. ÚassertRaisesRegexr )rr rer2r3r rrrriýs zTestCase.assertRaisesRegexcOrh)aÒAsserts that the message in a triggered warning matches a regexp. Basic functioning is similar to assertWarns() with the addition that only warnings whose messages also match the regular expression are considered successful matches. Args: expected_warning: Warning class expected to be triggered. expected_regex: Regex (re.Pattern object or string) expected to be found in error message. args: Function to be called and extra positional args. kwargs: Extra kwargs. msg: Optional message used in case of failure. Can only be used when assertWarnsRegex is used as a context manager. ÚassertWarnsRegexr )rrrer2r3r rrrrj s zTestCase.assertWarnsRegexcCsJt|ttfƒr t |¡}| |¡s#d|j|f}| ||¡}| |¡‚dS)z=Fail the test unless the text matches the regular expression.z&Regex didn't match: %r not found in %rN) r@r"Úbytesrcrdrwrxr]r_)rÚtextrer^r`rrrÚ assertRegex s  ÿ  ûzTestCase.assertRegexcCs`t|ttfƒr t |¡}| |¡}|r.d|| ¡| ¡…|j|f}|  ||¡}|  |¡‚dS)z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN) r@r"rkrcrdrwÚstartÚendrxr]r_)rrlZunexpected_regexr^Úmatchr`rrrÚassertNotRegex,s  ý  ùzTestCase.assertNotRegexcs‡fdd„}|S)Ncs$t d ˆj¡td¡ˆ|i|¤ŽS)NzPlease use {0} instead.rÚ)rŠrÛrsr rOr;©Ú original_funcrrÚdeprecated_func<s  þz,TestCase._deprecate..deprecated_funcr)rsrtrrrrÚ _deprecate;s zTestCase._deprecate)r¤r))NN©NNN)er r rrÚAssertionErrorr_rr:rYr rr±r·rr¹r»r½r¿rÁrÂrÃrÊrÍrÒrÔr×rØrÞr*r+Ú_subtest_msg_sentinelrärçrérërírðrñròrùrõrúrürýrþrÿrrr]rr rrrrrrr'r(r9r5r¦r§r¨rErGrIrJr¥rSrWr©r]r_r`rarcrdrLrgrirjrmrqruZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesÚ __classcell__rrr¢rr�4s            C     !       ÿ- ÿ #c  +                   r�csjeZdZdZd‡fdd„ Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z ‡ZS)ÚFunctionTestCaseaIA test case that wraps a test function. This is useful for slipping pre-existing test functions into the unittest framework. Optionally, set-up and tidy-up functions can be supplied. As with TestCase, the tidy-up ('tearDown') function will always be called if the set-up ('setUp') function ran successfully. Ncs*tt|ƒ ¡||_||_||_||_dSr))rŸrzrÚ _setUpFuncÚ _tearDownFuncÚ _testFuncÚ _description)rZtestFuncr»r½Ú descriptionr¢rrrZs  zFunctionTestCase.__init__cCó|jdur | ¡dSdSr))r{rprrrr»aó  ÿzFunctionTestCase.setUpcCr€r))r|rprrrr½er�zFunctionTestCase.tearDowncCrìr))r}rprrrr¤irîzFunctionTestCase.runTestcCs|jjSr))r}r rprrrrÍlrÄzFunctionTestCase.idcCs@t||jƒstS|j|jko|j|jko|j|jko|j|jkSr))r@r£rÏr{r|r}r~rÐrrrrÒos   ÿ þ ýzFunctionTestCase.__eq__cCstt|ƒ|j|j|j|jfƒSr))rÓrAr{r|r}r~rprrrrÔxsÿzFunctionTestCase.__hash__cCsdt|jƒ|jjfSrÖ)rr£r}r rprrrr×|s ÿzFunctionTestCase.__str__cCrË)Nz <%s tec=%s>)rr£r}rprrrrØ€s ÿzFunctionTestCase.__repr__cCs2|jdur|jS|jj}|r| d¡d ¡pdS)NrÅr)r~r}rrÇrÆrÈrrrrÊ„s z!FunctionTestCase.shortDescriptionrv)r r rrrr»r½r¤rÍrÒrÔr×rØrÊryrrr¢rrzQs rzcsDeZdZ‡fdd„Zdd„Zdd„Zdd„Zd d „Zd d „Z‡Z S) râcs(tƒ ¡||_||_||_|j|_dSr))rŸrÚ_messager%ràr_)rr%r�ràr¢rrr�s  z_SubTest.__init__cCstdƒ‚)Nzsubtests cannot be run directly)r*rprrrr¤”rÄz_SubTest.runTestcCs^g}|jtur| d |j¡¡|jr(d dd„|j ¡Dƒ¡}| d |¡¡d |¡p.dS)Nz[{}]z, css �|] \}}d ||¡VqdS)z{}={!r}N)rs)rSr›rŽrrrrVœs € ÿ ÿz+_SubTest._subDescription..z({})ú z ())r‚rxr!rsràr/rP)rÚpartsZ params_descrrrÚ_subDescription—s  þz_SubTest._subDescriptioncCsd |j ¡| ¡¡S©Nz{} {})rsr%rÍr…rprrrrÍ¢sz _SubTest.idcCs |j ¡S)zlReturns a one-line description of the subtest, or None if no description has been provided. )r%rÊrprrrrÊ¥s z_SubTest.shortDescriptioncCsd |j| ¡¡Sr†)rsr%r…rprrrr׫rÕz_SubTest.__str__) r r rrr¤r…rÍrÊr×ryrrr¢rrâ‹s  râ).rr#rBr0r2rcrŠrUr*rtrIrHrÚutilrrrrrZ __unittestÚobjectrxr;r6r rrrr.r0r4r9rKrNrPrrRr[rbror‚ÚChainMapr•r�rzrârrrrÚsZ ( *'4 %: