B °-_hßã@s°dZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZdZeƒZdZGdd „d eƒZGd d „d eƒZGd d „d eƒZGdd„deƒZdd„Zdd„Zdd„Zdd„Zdd„Z dd„Z!Gdd„dƒZ"Gdd„de"ƒZ#Gd d!„d!e#ƒZ$Gd"d#„d#e#ƒZ%e &d$d%d&g¡Z'Gd'd(„d(ej(ƒZ)Gd)d*„d*e"ƒZ*Gd+d,„d,ej+ƒZ,Gd-d.„d.eƒZ-Gd/d0„d0e-ƒZ.Gd1d2„d2e-ƒZ/dS)3zTest 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@seZdZdZdS)Ú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ú#/usr/lib/python3.7/unittest/case.pyr sr c@seZdZdZdS)Ú _ShouldStopz The test should stop. N)r r r r rrrrr!src@seZdZdZdS)Ú_UnexpectedSuccessz7 The test was supposed to fail, but it didn't! N)r r r r rrrrr&src@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|_zÈy dVWnœtk r.‚Yn¤tk rh}zd|_|j |t|ƒf¡Wdd}~XYnjtk rzYnXt ¡}|j r–||_ nd|_|j  ||f¡d}YnX|j rÒ|jrÒ|j  |df¡Wd|joÞ||_XdS)NTF) rÚKeyboardInterruptr rÚappendÚstrrÚsysÚexc_inforrrr)rÚ test_caseÚisTestZ old_successÚer!rrrÚtestPartExecutor6s* $  z_Outcome.testPartExecutor)N)F)r r r rÚ contextlibÚcontextmanagerr%rrrrr,s rcCs|S)Nr)ÚobjrrrÚ_idTsr)cs‡fdd„}|S)z& Unconditionally skip a test. cs4t|tƒs$t |¡‡fdd„ƒ}|}d|_ˆ|_|S)Ncs tˆƒ‚dS)N)r )ÚargsÚkwargs)ÚreasonrrÚ skip_wrapper]sz-skip..decorator..skip_wrapperT)Ú isinstanceÚtypeÚ functoolsÚwrapsÚ__unittest_skip__Ú__unittest_skip_why__)Ú test_itemr-)r,rrÚ decorator[s  zskip..decoratorr)r,r5r)r,rÚskipWs r6cCs|r t|ƒStS)z/ Skip a test if the condition is true. )r6r))Ú conditionr,rrrÚskipIfgsr8cCs|s t|ƒStS)z3 Skip a test unless the condition is true. )r6r))r7r,rrrÚ skipUnlessosr9cCs d|_|S)NT)Ú__unittest_expecting_failure__)r4rrrrwsrcs4t|tƒr t‡fdd„|DƒƒSt|tƒo2t|ˆƒS)Nc3s|]}t|ˆƒVqdS)N)Ú _is_subtype)Ú.0r$)Úbasetyperrú }sz_is_subtype..)r.ÚtupleÚallr/Ú issubclass)Úexpectedr=r)r=rr;{s r;c@seZdZdd„Zdd„ZdS)Ú_BaseTestCaseContextcCs ||_dS)N)r")rr"rrrr‚sz_BaseTestCaseContext.__init__cCs |j |j|¡}|j |¡‚dS)N)r"Ú_formatMessageÚmsgÚfailureException)rÚ standardMsgrErrrÚ _raiseFailure…sz"_BaseTestCaseContext._raiseFailureN)r r r rrHrrrrrC€srCc@seZdZddd„Zdd„ZdS)Ú_AssertRaisesBaseContextNcCs@t ||¡||_||_|dk r*t |¡}||_d|_d|_dS)N) rCrrBr"ÚreÚcompileÚexpected_regexÚobj_namerE)rrBr"rLrrrr‹s  z!_AssertRaisesBaseContext.__init__c CsÔzÈt|j|jƒs"td||jfƒ‚|rD|ddkrDt dtd¡d}|sx| dd¡|_ |rtt dt t |ƒƒtd¡|S|^}}y |j |_ Wntk rªt|ƒ|_ YnX||||ŽWdQRXWdd}XdS) 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 %srNzcallable is NoneérrEz3%r is an invalid keyword argument for this function)r;rBÚ _base_typeÚ TypeErrorÚ_base_type_strÚwarningsÚwarnÚDeprecationWarningÚpoprEÚnextÚiterr rMÚAttributeErrorr)rÚnamer*r+Z callable_objrrrÚhandle•s.  z_AssertRaisesBaseContext.handle)N)r r r rrZrrrrrI‰s rIc@s(eZdZdZeZdZdd„Zdd„ZdS)Ú_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-an exception type or tuple of exception typescCs|S)Nr)rrrrÚ __enter__¾sz_AssertRaisesContext.__enter__cCsÆ|dkrby |jj}Wntk r2t|jƒ}YnX|jrP| d ||j¡¡ql| d |¡¡n t |¡t ||jƒs|dS|  d¡|_ |j dkr–dS|j }|  t|ƒ¡sÂ| d |jt|ƒ¡¡dS)Nz{} not raised by {}z {} not raisedFTz"{}" does not match "{}")rBr rXrrMrHÚformatÚ tracebackÚ clear_framesrAÚwith_tracebackZ exceptionrLÚsearchÚpattern)rÚexc_typeÚ exc_valueÚtbÚexc_namerLrrrÚ__exit__Ás(       z_AssertRaisesContext.__exit__N) r r r r Ú BaseExceptionrOrQr\rgrrrrr[¸s r[c@s(eZdZdZeZdZdd„Zdd„ZdS)Ú_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRx$tj ¡D]}t|ddƒr i|_q Wtjdd|_|j ¡|_t  d|j ¡|S)NÚ__warningregistry__T)ÚrecordÚalways) r ÚmodulesÚvaluesÚgetattrrjrRÚcatch_warningsÚwarnings_managerr\Ú simplefilterrB)rÚvrrrr\ãs   z_AssertWarnsContext.__enter__cCs|j |||¡|dk rdSy |jj}Wntk rFt|jƒ}YnXd}xb|jD]X}|j}t||jƒslqT|dkrx|}|j dk r”|j   t|ƒ¡s”qT||_ |j |_ |j |_ dSW|dk rÒ| d |j jt|ƒ¡¡|jrî| d ||j¡¡n| d |¡¡dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rqrgrBr rXrrRÚmessager.rLraZwarningÚfilenameÚlinenorHr]rbrM)rrcrdrerfZfirst_matchingÚmÚwrrrrgîs8      z_AssertWarnsContext.__exit__N) r r r r ÚWarningrOrQr\rgrrrrriÝs  riÚ_LoggingWatcherÚrecordsÚoutputc@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú_CapturingHandlerzM A logging handler capturing all (raw and formatted) logging output. cCstj |¡tggƒ|_dS)N)ÚloggingÚHandlerrrzÚwatcher)rrrrrs z_CapturingHandler.__init__cCsdS)Nr)rrrrÚflushsz_CapturingHandler.flushcCs*|jj |¡| |¡}|jj |¡dS)N)r€r{rr]r|)rrkrErrrÚemit"s z_CapturingHandler.emitN)r r r r rrr‚rrrrr}sr}c@s,eZdZdZdZdd„Zdd„Zdd„Zd S) Ú_AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)scCs:t ||¡||_|r(tj ||¡|_ntj|_d|_dS)N) rCrÚ logger_namer~Z _nameToLevelÚgetÚlevelÚINFOrE)rr"r„r†rrrr.s  z_AssertLogsContext.__init__cCs’t|jtjƒr|j}|_nt |j¡}|_t |j¡}tƒ}|  |¡|j |_ |j dd…|_ |j |_|j|_|g|_ | |j ¡d|_|j S)NF)r.r„r~ZLoggerÚloggerZ getLoggerZ FormatterÚLOGGING_FORMATr}Z setFormatterr€ÚhandlersÚ old_handlersr†Ú old_levelÚ propagateÚ old_propagateÚsetLevel)rrˆZ formatterZhandlerrrrr\7s   z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|j |j¡|dk r.dSt|jj ƒdkr\|  d  t   |j¡|jj¡¡dS)NFrz-no logs of level {} or higher triggered on {})r‹rˆrŠrŽrrrŒÚlenr€r{rHr]r~Z getLevelNamer†rY)rrcrdrerrrrgHs  z_AssertLogsContext.__exit__N)r r r r r‰rr\rgrrrrrƒ)s  rƒc@seZdZdd„ZdS)Ú_OrderedChainMapccs@tƒ}x4|jD]*}x$|D]}||kr| |¡|VqWqWdS)N)ÚsetÚmapsÚadd)rÚseenÚmappingÚkrrrÚ__iter__Vs    z_OrderedChainMap.__iter__N)r r r r˜rrrrr‘Usr‘c@sÜeZdZdZeZdZdZdZdZ dˆdd„Z d d „Z d d „Z d d„Z dd„Zedd„ƒZedd„ƒZdd„Zdd„Zdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zejefd'd(„ƒZd)d*„Zd+d,„Z d-d.„Z!d‰d0d1„Z"d2d3„Z#d4d5„Z$d6d7„Z%d8d9„Z&dŠd:d;„Z'd‹dd?„Z)d@dA„Z*dBdC„Z+dDdE„Z,ddFdG„Z-dHdI„Z.dŽdJdK„Z/ddLdM„Z0ddNdO„Z1d‘dPdQ„Z2d’dRdS„Z3d“dTdU„Z4dVdW„Z5d”dXdY„Z6d•dZd[„Z7d–d\d]„Z8d—d^d_„Z9d˜d`da„Z:d™dbdc„Z;dšddde„Zddjdk„Z?dždldm„Z@dŸdndo„ZAd dpdq„ZBd¡drds„ZCd¢dtdu„ZDd£dvdw„ZEd¤dxdy„ZFd¥dzd{„ZGd¦d|d}„ZHd~d„ZId€d„ZJd§d‚dƒ„ZKd¨d„d…„ZLd†d‡„ZMeMe0ƒZNZOeMe1ƒZPZQeMe2ƒZRZSeMe3ƒZTZUeMe)ƒZVZWeMe+ƒZXeMe(ƒZYeMeIƒZZeMeKƒZ[eMeLƒZ\d/S)©Ú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€iFÚrunTestcCs¶||_d|_d|_yt||ƒ}Wn.tk rN|dkrJtd|j|fƒ‚Yn X|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Ú_testMethodDocrorXÚ ValueErrorÚ __class__r Ú _cleanupsÚ_subtestÚ_type_equality_funcsÚaddTypeEqualityFuncÚdictÚlistr?r’Ú frozensetr)rZ methodNameÚ testMethodrrrrŽs&     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§)rZtypeobjÚfunctionrrrr¨®s zTestCase.addTypeEqualityFunccOs|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)rr­r*r+rrrÚ addCleanup½szTestCase.addCleanupcCsdS)zAHook method for setting up the test fixture before exercising it.Nr)rrrrÚsetUpÅszTestCase.setUpcCsdS)zAHook method for deconstructing the test fixture after testing it.Nr)rrrrÚtearDownÉszTestCase.tearDowncCsdS)zKHook method for setting up class fixture before running tests in the class.Nr)ÚclsrrrÚ setUpClassÍszTestCase.setUpClasscCsdS)zVHook method for deconstructing the class fixture after running all tests in the class.Nr)r±rrrÚ tearDownClassÑszTestCase.tearDownClasscCsdS)Nrr)rrrrÚcountTestCasesÕszTestCase.countTestCasescCst ¡S)N)rZ TestResult)rrrrÚdefaultTestResultØszTestCase.defaultTestResultcCs |j}|r| d¡d ¡pdS)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¢ÚsplitÚstrip)rÚdocrrrÚshortDescriptionÛszTestCase.shortDescriptioncCsdt|jƒ|jfS)Nz%s.%s)rr¤r )rrrrÚidæsz TestCase.idcCs t|ƒt|ƒk rtS|j|jkS)N)r/ÚNotImplementedr )rÚotherrrrÚ__eq__észTestCase.__eq__cCstt|ƒ|jfƒS)N)Úhashr/r )rrrrÚ__hash__ïszTestCase.__hash__cCsd|jt|jƒfS)Nz%s (%s))r rr¤)rrrrÚ__str__òszTestCase.__str__cCsdt|jƒ|jfS)Nz<%s testMethod=%s>)rr¤r )rrrrÚ__repr__õszTestCase.__repr__cCs<t|ddƒ}|dk r |||ƒnt dtd¡| |¡dS)NÚaddSkipz4TestResult has no addSkip method, skips not reportedé)rorRrSÚRuntimeWarningÚ addSuccess)rrr"r,rÃrrrÚ_addSkipùs   zTestCase._addSkipc ks´|jdks|jjsdVdS|j}|dkr4t|ƒ}n |j |¡}t|||ƒ|_zX|jj|jdd dVWdQRX|jjs˜|jj }|dk r¤|j r¤t ‚n |jj r¤t ‚Wd||_XdS)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)rrErÈÚparentZ params_maprrrrÚsubTests$  zTestCase.subTestcCsdx^|D]V\}}t|tƒr*| |j||¡q|dk rt|d|jƒrP| ||¡q| ||¡qWdS)Nr)r.rÊrr"rArFÚ addFailureZaddError)rrrÚtestr!rrrÚ_feedErrorsToResult!s zTestCase._feedErrorsToResultcCsDy |j}Wn*tk r4t dt¡| |¡Yn X|||ƒdS)Nz@TestResult has no addExpectedFailure method, reporting as passes)ÚaddExpectedFailurerXrRrSrÅrÆ)rrr!rÐrrrÚ_addExpectedFailure+s zTestCase._addExpectedFailurec Cshy |j}WnPtk rZt dt¡y td‚Wn$tk rT| |t ¡¡YnXYn X||ƒdS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) ÚaddUnexpectedSuccessrXrRrSrÅrrÍr r!)rrrÒrrrÚ_addUnexpectedSuccess5s  zTestCase._addUnexpectedSuccessNc Cs|}|dkr.| ¡}t|ddƒ}|dk r.|ƒ| |¡t||jƒ}t|jddƒs^t|ddƒrœz,t|jddƒpxt|ddƒ}| |||¡Wd| |¡XdSt|ddƒ}t|ddƒ}|pº|}t|ƒ} zð| |_|   |¡|  ¡WdQRX| j r<|| _ | j |dd |ƒWdQRXd| _ |   |¡|  ¡WdQRX| ¡x"| jD]\} } | || | ¡qLW| || j¡| j r²|r¨| jrœ| || j¡n | |¡n | |¡|S| |¡|dkræt|d dƒ} | dk ræ| ƒ| j ¡d| _d|_XdS) NÚ startTestRunr2Fr3Úr:T)r#Ú stopTestRun)rµroZ startTestr r¤rÇZstopTestrr¡r%r¯rrr°Ú doCleanupsrrÏrrrÑrÓrÆÚclear) rrZ orig_resultrÔr¬Zskip_whyZexpecting_failure_methodZexpecting_failure_classrÚoutcomerÎr,rÖrrrÚrunDsh               z TestCase.runc CsN|jp tƒ}x:|jrF|j ¡\}}}| |¡|||ŽWdQRXqW|jS)zNExecute all cleanup functions. Normally called for you after tearDown.N)r¡rr¥rUr%r)rrÙr­r*r+rrrr׉s   zTestCase.doCleanupscOs |j||ŽS)N)rÚ)rr*ÚkwdsrrrÚ__call__–szTestCase.__call__cCsJ| ¡t||jƒƒ| ¡x&|jrD|j d¡\}}}|||Žq WdS)z6Run the test without collecting errors in a TestResultéÿÿÿÿN)r¯ror r°r¥rU)rr­r*r+rrrÚdebug™s zTestCase.debugcCs t|ƒ‚dS)zSkip this test.N)r )rr,rrrÚskipTest¢szTestCase.skipTestcCs| |¡‚dS)z)Fail immediately, with the given message.N)rF)rrErrrÚfail¦sz TestCase.failcCs&|r"| |dt|ƒ¡}| |¡‚dS)z#Check that the expression is false.z%s is not falseN)rDrrF)rÚexprrErrrÚ assertFalseªszTestCase.assertFalsecCs&|s"| |dt|ƒ¡}| |¡‚dS)z"Check that the expression is true.z%s is not trueN)rDrrF)rrárErrrÚ assertTrue°szTestCase.assertTruecCsP|js|p |S|dkr|Sy d||fStk rJdt|ƒt|ƒfSXdS)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)rrErGrrrrD¶s  zTestCase._formatMessagecOs$t||ƒ}z| d||¡Sd}XdS)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)r[rZ)rÚexpected_exceptionr*r+Ú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)rirZ)rÚexpected_warningr*r+rèrrrréìs zTestCase.assertWarnscCs t|||ƒ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ƒ)rrˆr†rrrÚ assertLogs szTestCase.assertLogscCsFt|ƒt|ƒkr@|j t|ƒ¡}|dk r@t|tƒr}z| d|¡Wdd}~XYn0tk rl}z| d|¡Wdd}~XYnXy| |¡}Wn^tk r¬}z| d|¡Wdd}~XYn0tk rÚ}z| d|¡Wdd}~XYnX|sè|sèdSg}|r| d¡x|D]}| t|ƒ¡qW|rH| d¡x|D]}| t|ƒ¡q0Wd |¡} | | || ¡¡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¶)Ú differencerPràrXrÚreprrÿrD) rZset1Zset2rEZ difference1r$Z difference2ÚlinesÚitemrGrrrrž"s2        zTestCase.assertSetEqualcCs2||kr.dt|ƒt|ƒf}| | ||¡¡dS)zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sN)rràrD)rÚmemberÚ containerrErGrrrÚassertInMs zTestCase.assertIncCs2||kr.dt|ƒt|ƒf}| | ||¡¡dS)zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sN)rràrD)rrrrErGrrrÚ assertNotInTs zTestCase.assertNotIncCs2||k r.dt|ƒt|ƒf}| | ||¡¡dS)zDJust like self.assertTrue(a is b), but with a nicer default message.z %s is not %sN)rràrD)rÚexpr1Úexpr2rErGrrrÚassertIs[s zTestCase.assertIscCs,||kr(dt|ƒf}| | ||¡¡dS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sN)rràrD)rrrrErGrrrÚ assertIsNotbszTestCase.assertIsNotc Cs~| |td¡| |td¡||krzdt||ƒ}dd t t |¡ ¡t |¡ ¡¡¡}|  ||¡}|  |  ||¡¡dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr¶) ÚassertIsInstancer©rrÿrrrrrrràrD)rZd1Zd2rErGr÷rrrr›hs   zTestCase.assertDictEqualc CsÒt dt¡g}g}xX| ¡D]L\}}||kr:| |¡q|||kr| dt|ƒt|ƒt||ƒf¡qW|sz|szdSd}|ršdd dd„|Dƒ¡}|r¼|rª|d 7}|d d |¡7}| | ||¡¡dS) z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %sNrÕz Missing: %sú,css|]}t|ƒVqdS)N)r)r<rwrrrr>‡sz4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rRrSrTÚitemsrrrÿràrD) rZsubsetZ dictionaryrEZmissingZ mismatchedÚkeyÚvaluerGrrrÚassertDictContainsSubsetts,     z!TestCase.assertDictContainsSubsetc Cs¦t|ƒt|ƒ}}yt |¡}t |¡}Wntk rHt||ƒ}YnX||krVdSt||ƒ}|r¢d}dd„|Dƒ}d |¡} | || ¡}| ||¡}|  |¡dS)a¿An unordered sequence comparison asserting that the same elements, regardless of order. If the same element occurs more than once, it verifies that the elements occur the same number of times. 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)r<r÷rrrú ¬sz-TestCase.assertCountEqual..r¶) rªÚ collectionsÚCounterrPrrrÿrrDrà) rrírîrEZ first_seqZ second_seqZ differencesrGrrrrrÚassertCountEqual‘s      zTestCase.assertCountEqualcCsÚ| |td¡| |td¡||krÖt|ƒ|jks@t|ƒ|jkrN| |||¡|jdd}|jdd}t|ƒdkr”| d¡|kr”|dg}|dg}dt||ƒ}dd  t   ||¡¡}|  ||¡}|  |  ||¡¡d S) z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringT)Úkeependsrz r¶z%s != %srÕN)rrrÚ_diffThresholdrìrr¸rrÿrrrràrD)rrírîrEZ firstlinesZ secondlinesrGr÷rrrrŸ²s     zTestCase.assertMultiLineEqualcCs2||ks.dt|ƒt|ƒf}| | ||¡¡dS)zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sN)rràrD)rÚaÚbrErGrrrÚ assertLessÆszTestCase.assertLesscCs2||ks.dt|ƒt|ƒf}| | ||¡¡dS)zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sN)rràrD)rr$r%rErGrrrÚassertLessEqualÌszTestCase.assertLessEqualcCs2||ks.dt|ƒt|ƒf}| | ||¡¡dS)zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sN)rràrD)rr$r%rErGrrrÚ assertGreaterÒszTestCase.assertGreatercCs2||ks.dt|ƒt|ƒf}| | ||¡¡dS)zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sN)rràrD)rr$r%rErGrrrÚassertGreaterEqualØszTestCase.assertGreaterEqualcCs,|dk r(dt|ƒf}| | ||¡¡dS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not None)rràrD)rr(rErGrrrÚ assertIsNoneÞszTestCase.assertIsNonecCs"|dkrd}| | ||¡¡dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)ràrD)rr(rErGrrrÚassertIsNotNoneäszTestCase.assertIsNotNonecCs0t||ƒs,dt|ƒ|f}| | ||¡¡dS)zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer default message.z%s is not an instance of %rN)r.rràrD)rr(r±rErGrrrrês zTestCase.assertIsInstancecCs0t||ƒr,dt|ƒ|f}| | ||¡¡dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rN)r.rràrD)rr(r±rErGrrrÚassertNotIsInstanceñs zTestCase.assertNotIsInstancecOst|||ƒ}| 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. ÚassertRaisesRegex)r[rZ)rrçrLr*r+rèrrrr-÷s zTestCase.assertRaisesRegexcOst|||ƒ}| d||¡S)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. ÚassertWarnsRegex)rirZ)rrêrLr*r+rèrrrr.s zTestCase.assertWarnsRegexcCsVt|ttfƒr$|stdƒ‚t |¡}| |¡sRd|j|f}| ||¡}|  |¡‚dS)z=Fail the test unless the text matches the regular expression.z!expected_regex must not be empty.z&Regex didn't match: %r not found in %rN) r.rÚbytesÚAssertionErrorrJrKrarbrDrF)rÚtextrLrErGrrrÚ assertRegexs     zTestCase.assertRegexcCs`t|ttfƒrt |¡}| |¡}|r\d|| ¡| ¡…|j|f}|  ||¡}|  |¡‚dS)z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN) r.rr/rJrKraÚstartÚendrbrDrF)rr1Zunexpected_regexrEÚmatchrGrrrÚassertNotRegex&s   zTestCase.assertNotRegexcs‡fdd„}|S)Ncs t d ˆj¡td¡ˆ||ŽS)NzPlease use {0} instead.rÄ)rRrSr]r rT)r*r+)Ú original_funcrrÚdeprecated_func6s z,TestCase._deprecate..deprecated_funcr)r7r8r)r7rÚ _deprecate5s 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)]r r r r r0rFrär r#Z_classSetupFailedrr¨r®r¯r°Ú classmethodr²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ãrDrærérërïrìrðrñrørùr rrœrržrrrrr›rr!rŸr&r'r(r)r*r+rr,r-r.r2r6r9ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrr™_s¦        E     !     , " 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|ƒ ¡||_||_||_||_dS)N)Úsuperr<rÚ _setUpFuncÚ _tearDownFuncÚ _testFuncÚ _description)rZtestFuncr¯r°Z description)r¤rrrTs zFunctionTestCase.__init__cCs|jdk r| ¡dS)N)r>)rrrrr¯[s zFunctionTestCase.setUpcCs|jdk r| ¡dS)N)r?)rrrrr°_s zFunctionTestCase.tearDowncCs | ¡dS)N)r@)rrrrršcszFunctionTestCase.runTestcCs|jjS)N)r@r )rrrrr»fszFunctionTestCase.idcCs@t||jƒstS|j|jko>|j|jko>|j|jko>|j|jkS)N)r.r¤r¼r>r?r@rA)rr½rrrr¾is     zFunctionTestCase.__eq__cCstt|ƒ|j|j|j|jfƒS)N)r¿r/r>r?r@rA)rrrrrÀrszFunctionTestCase.__hash__cCsdt|jƒ|jjfS)Nz%s (%s))rr¤r@r )rrrrrÁvs zFunctionTestCase.__str__cCsdt|jƒ|jfS)Nz <%s tec=%s>)rr¤r@)rrrrrÂzs zFunctionTestCase.__repr__cCs2|jdk r|jS|jj}|r.| d¡d ¡p0dS)Nr¶r)rAr@r r·r¸)rr¹rrrrº~s z!FunctionTestCase.shortDescription)NNN)r r r r rr¯r°ršr»r¾rÀrÁrÂrºÚ __classcell__rr)r¤rr<Ks r<csDeZdZ‡fdd„Zdd„Zdd„Zdd„Zd d „Zd d „Z‡Z S) rÊcs(tƒ ¡||_||_||_|j|_dS)N)r=rÚ_messager"rÈrF)rr"rtrÈ)r¤rrr‡s  z_SubTest.__init__cCs tdƒ‚dS)Nzsubtests cannot be run directly)rú)rrrrršŽsz_SubTest.runTestcCs^g}|jtk r | d |j¡¡|jrPd dd„|j ¡Dƒ¡}| d |¡¡d |¡p\dS)Nz[{}]z, css|]\}}d ||¡VqdS)z{}={!r}N)r])r<r—rsrrrr>—sz+_SubTest._subDescription..z({})ú z ())rCr;rr]rÈrÿr)rÚpartsZ params_descrrrÚ_subDescription‘s z_SubTest._subDescriptioncCsd |j ¡| ¡¡S)Nz{} {})r]r"r»rF)rrrrr»œsz _SubTest.idcCs |j ¡S)zlReturns a one-line description of the subtest, or None if no description has been provided. )r"rº)rrrrrºŸsz_SubTest.shortDescriptioncCsd |j| ¡¡S)Nz{} {})r]r"rF)rrrrrÁ¥sz_SubTest.__str__) r r r rršrFr»rºrÁrBrr)r¤rrÊ…s   rÊ)0r r r0rr~rrJrRrr&r^rÕrÚutilrrrrrZ __unittestÚobjectr;r Ú Exceptionr rrrr)r6r8r9rr;rCrIr[riÚ namedtuplerzrr}rƒÚChainMapr‘r™r<rÊrrrrÚsX ( /%5 , s: