PNG  IHDR;IDATxܻn0K )(pA 7LeG{ §㻢|ذaÆ 6lذaÆ 6lذaÆ 6lom$^yذag5bÆ 6lذaÆ 6lذa{ 6lذaÆ `}HFkm,mӪôô! x|'ܢ˟;E:9&ᶒ}{v]n&6 h_tڠ͵-ҫZ;Z$.Pkž)!o>}leQfJTu іچ\X=8Rن4`Vwl>nG^is"ms$ui?wbs[m6K4O.4%/bC%t Mז -lG6mrz2s%9s@-k9=)kB5\+͂Zsٲ Rn~GRC wIcIn7jJhۛNCS|j08yiHKֶۛkɈ+;SzL/F*\Ԕ#"5m2[S=gnaPeғL lذaÆ 6l^ḵaÆ 6lذaÆ 6lذa; _ذaÆ 6lذaÆ 6lذaÆ RIENDB`  qY`@sMdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZdZeZdZGdd d eZGd d d eZGd d d eZGdddeZddZddZddZddZddZ ddZ!GdddZ"Gddde"Z#Gd d!d!e#Z$Gd"d#d#e#Z%ej&d$d%d&gZ'Gd'd(d(ej(Z)Gd)d*d*e"Z*Gd+d,d,eZ+Gd-d.d.e+Z,Gd/d0d0e+Z-dS)1zTest case implementationN)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#/opt/python35/lib/python3.5/case.pyr s r c@seZdZdZdS) _ShouldStopz The test should stop. N)r r r r rrrrr!s rc@seZdZdZdS)_UnexpectedSuccessz7 The test was supposed to fail, but it didn't! N)r r r r rrrrr&s rc@s7eZdZdddZejdddZdS)_OutcomeNcCsLd|_||_t|d|_d|_g|_d|_g|_dS)NF addSubTestT)expecting_failurerhasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfrrrr__init__-s     z_Outcome.__init__Fccs |j}d|_zy dVWntk r5Yntk r~}z*d|_|jj|t|fWYdd}~Xntk rYnvtj}|j r||_ nd|_|j j||fd}Yn)X|j r|jr|j j|dfWd|jo||_XdS)NTF) rKeyboardInterruptr rappendstrrsysexc_inforrrr)r test_caseisTestZ old_successer!rrrtestPartExecutor6s*     .      z_Outcome.testPartExecutor)r r r r contextlibcontextmanagerr%rrrrr,s  rcCs|S)Nr)objrrr_idTsr)csfdd}|S)z& Unconditionally skip a test. csLt|ts6tj|fdd}|}d|_|_|S)NcstdS)N)r )argskwargs)reasonrr skip_wrapper]sz-skip..decorator..skip_wrapperT) isinstancetype functoolswraps__unittest_skip____unittest_skip_why__) test_itemr-)r,rr decorator[s !  zskip..decoratorr)r,r5r)r,rskipWs r6cCs|rt|StS)z/ Skip a test if the condition is true. )r6r)) conditionr,rrrskipIfgs r8cCs|st|StS)z3 Skip a test unless the condition is true. )r6r))r7r,rrr skipUnlessos r9cCs d|_|S)NT)__unittest_expecting_failure__)r4rrrrws rcsHt|tr,tfdd|DSt|toGt|S)Nc3s|]}t|VqdS)N) _is_subtype).0r$)basetyperr }sz_is_subtype..)r.tupleallr/ issubclass)expectedr=r)r=rr;{sr;c@s(eZdZddZddZdS)_BaseTestCaseContextcCs ||_dS)N)r")rr"rrrrsz_BaseTestCaseContext.__init__cCs.|jj|j|}|jj|dS)N)r"_formatMessagemsgfailureException)r standardMsgrErrr _raiseFailuresz"_BaseTestCaseContext._raiseFailureN)r r r rrHrrrrrCs  rCc@s+eZdZdddZddZdS)_AssertRaisesBaseContextNcCs\tj||||_||_|dk r=tj|}||_d|_d|_dS)N) rCrrBr"recompileexpected_regexobj_namerE)rrBr"rLrrrrs     z!_AssertRaisesBaseContext.__init__cCszt|j|js1td||jf|r`|ddkr`tjdtdf}|s|jdd|_ |rtjdt t |td|S|^}}y|j |_ Wn!tk rt||_ 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 NonerEz3%r is an invalid keyword argument for this function)r;rB _base_type TypeError_base_type_strwarningswarnDeprecationWarningpoprEnextiterr rMAttributeErrorr)rnamer*r+Z callable_objrrrhandles.      z_AssertRaisesBaseContext.handle)r r r rrZrrrrrIs  rIc@s:eZdZdZeZdZddZddZdS)_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__c Cs |dkry|jj}Wn!tk r?t|j}YnX|jrh|jdj||jq|jdj|n tj|t ||jsdS|j d|_ |j dkrdS|j }|j t|s |jdj|jt|dS)Nz{} not raised by {}z {} not raisedFTz"{}" does not match "{}")rBr rXrrMrHformat traceback clear_framesrAwith_traceback exceptionrLsearchpattern)rexc_type exc_valuetbexc_namerLrrr__exit__s(      z_AssertRaisesContext.__exit__N) r r r r BaseExceptionrOrQr\rhrrrrr[s  r[c@s:eZdZdZeZdZddZddZdS)_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCssx2tjjD]!}t|ddri|_qWtjdd|_|jj|_tj d|j |S)N__warningregistry__recordTalways) r modulesvaluesgetattrrkrRcatch_warningswarnings_managerr\ simplefilterrB)rvrrrr\s z_AssertWarnsContext.__enter__c Csd|jj||||dk r&dSy|jj}Wn!tk rYt|j}YnXd}x|jD]}|j}t||jsqj|dkr|}|j dk r|j j t| rqj||_ |j |_ |j |_ dSW|dk r"|jdj|j jt||jrJ|jdj||jn|jdj|dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rrrhrBr rXrrRmessager.rLrbwarningfilenamelinenorHr]rcrM)rrdrerfrgZfirst_matchingmwrrrrhs8          z_AssertWarnsContext.__exit__N) r r r r WarningrOrQr\rhrrrrrjs  rj_LoggingWatcherrecordsoutputc@s:eZdZdZddZddZddZdS) _CapturingHandlerzM A logging handler capturing all (raw and formatted) logging output. cCs&tjj|tgg|_dS)N)loggingHandlerrr|watcher)rrrrrsz_CapturingHandler.__init__cCsdS)Nr)rrrrflushsz_CapturingHandler.flushcCs9|jjj||j|}|jjj|dS)N)rr}rr]r~)rrlrErrremit"sz_CapturingHandler.emitN)r r r r rrrrrrrrs   rc@s@eZdZdZdZddZddZddZd S) _AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)scCsStj||||_|r:tjj|||_n tj|_d|_dS)N) rCr logger_namer _nameToLevelgetlevelINFOrE)rr"rrrrrr.s   z_AssertLogsContext.__init__cCst|jtjr(|j}|_ntj|j}|_tj|j}t}|j ||j |_ |j dd|_ |j |_|j|_|g|_ |j|j d|_|j S)NF)r.rrLoggerlogger getLogger FormatterLOGGING_FORMATr setFormatterrhandlers old_handlersr old_level propagate old_propagatesetLevel)rr formatterhandlerrrrr\7s       z_AssertLogsContext.__enter__cCs|j|j_|j|j_|jj|j|dk rAdSt|jj dkr|j dj t j |j|jjdS)NFrz-no logs of level {} or higher triggered on {})rrrrrrrlenrr}rHr]r getLevelNamerrY)rrdrerfrrrrhHs z_AssertLogsContext.__exit__N)r r r r rrr\rhrrrrr)s  rc@sMeZdZdZeZdZdZdZdZ dd d Z d d Z d dZ ddZ ddZeddZeddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zejed)d*Zd+d,Zd-d.Z d/d0Z!d1d2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&d1d<d=Z'd1d>d?Z(d1d@dAZ)dBdCZ*dDdEZ+dFdGZ,d1d1dHdIZ-dJdKZ.d1dLdMZ/d1dNdOZ0d1dPdQZ1d1d1d1dRdSZ2d1d1d1dTdUZ3d1d1dVdWZ4dXdYZ5d1dZd[Z6d1d\d]Z7d1d^d_Z8d1d`daZ9d1dbdcZ:d1dddeZ;d1dfdgZ<d1dhdiZ=d1djdkZ>d1dldmZ?d1dndoZ@d1dpdqZAd1drdsZBd1dtduZCd1dvdwZDd1dxdyZEd1dzd{ZFd1d|d}ZGd1d~dZHddZIddZJd1ddZKd1ddZLddZMeMe0ZNZOeMe1ZPZQeMe2ZRZSeMe3ZTZUeMe)ZVZWeMe+ZXeMe(ZYeMeIZZeMeKZ[eMeLZ\d1S)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. TPFrunTestc Cs||_d|_d|_yt||}Wn7tk rg|dkrctd|j|fYn X|j|_g|_d|_ i|_ |j t d|j t d|j td|j td|j td|j td dS) zCreate 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 testrzno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocrprX ValueError __class__r _cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictlistr?set frozensetr)rZ methodName testMethodrrrrs&         zTestCase.__init__cCs||j|)rrr)rrrr__repr__szTestCase.__repr__cCsRt|dd}|dk r.|||n tjdtd|j|dS)NaddSkipz4TestResult has no addSkip method, skips not reportedr)rprRrSRuntimeWarning addSuccess)rrr"r,rrrr_addSkips    zTestCase._addSkipcks|jjsdVdS|j}|dkr<tj|}n|jj|}t||||_zt|jj|jdd dVWdQRX|jj s|jj }|dk r|j rt n|jj rt 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. Nr#T)rrr collectionsChainMapparams new_child_SubTestr%rrZfailfastrr)rrErparentZ params_maprrrrsubTests$         zTestCase.subTestcCsx|D]y\}}t|tr;|j|j||q|dk rt|d|jrp|j||q|j||qWdS)Nr)r.rrr"rArF addFailureZaddError)rrrtestr!rrr_feedErrorsToResults zTestCase._feedErrorsToResultc CsPy |j}Wn/tk r>tjdt|j|YnX|||dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurerXrRrSrr)rrr!rrrr_addExpectedFailure!s   zTestCase._addExpectedFailurecCsxy |j}WnZtk ritjdty tdWn(tk rd|j|tjYnXYn X||dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) addUnexpectedSuccessrXrRrSrrrr r!)rrrrrr_addUnexpectedSuccess+s      zTestCase._addUnexpectedSuccessNc (Cs|}|dkrC|j}t|dd}|dk rC||j|t||j}t|jddst|ddrz>t|jddpt|dd}|j|||Wd|j|XdSt|dd}t|dd}|p |}t|} z'| |_| j ||j WdQRX| j r|| _ | j |dd |WdQRXd| _ | j ||j WdQRX|jx*| jD]\} } |j|| | qW|j|| j| j r:|r-| jr|j|| jq:|j|n |j||SWd|j||dkrt|d d} | dk r| | jjd| _d|_XdS) N startTestRunr2Fr3r:r#T stopTestRun)rrpZ startTestrrrZstopTestrrr%rrrr doCleanupsrrrrrrrclear) rrZ orig_resultrrZskip_whyZexpecting_failure_methodZexpecting_failure_classroutcomerr,rrrrrun:sh                     z TestCase.runc Cse|jpt}xI|jr]|jj\}}}|j||||WdQRXqW|jS)zNExecute all cleanup functions. Normally called for you after tearDown.N)rrrrUr%r)rrrr*r+rrrrs  zTestCase.doCleanupscOs|j||S)N)r)rr*kwdsrrr__call__szTestCase.__call__cCsc|jt||j|jx5|jr^|jjd\}}}|||q*WdS)z6Run the test without collecting errors in a TestResultrN)rrprrrrU)rrr*r+rrrdebugs    zTestCase.debugcCst|dS)zSkip this test.N)r )rr,rrrskipTestszTestCase.skipTestcCs|j|dS)z)Fail immediately, with the given message.N)rF)rrErrrfailsz TestCase.failcCs5|r1|j|dt|}|j|dS)z#Check that the expression is false.z%s is not falseN)rDrrF)rexprrErrr assertFalseszTestCase.assertFalsecCs5|s1|j|dt|}|j|dS)z"Check that the expression is true.z%s is not trueN)rDrrF)rrrErrr assertTrueszTestCase.assertTruec Csh|js|p|S|dkr#|Syd||fSWn,tk rcdt|t|fSYnXdS)aHonour 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) longMessageUnicodeDecodeErrorr)rrErGrrrrDs    zTestCase._formatMessagec Os4t||}z|jd||SWdd}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)rexpected_exceptionr*r+contextrrrrszTestCase.assertRaisescOs"t||}|jd||S)aFail 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)rjrZ)rexpected_warningr*r+rrrrrszTestCase.assertWarnscCst|||S)aFail 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)rrrrrr assertLogsszTestCase.assertLogscCset|t|kr^|jjt|}|dk r^t|trZt||}|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)r/rrr.rrp_baseAssertEqual)rfirstsecondZasserterrrr_getAssertEqualityFuncs zTestCase._getAssertEqualityFunccCsD||ks@dt||}|j||}|j|dS)z:The default assertEqual implementation, not type specific.z%s != %sN)rrDrF)rrrrErGrrrr1s zTestCase._baseAssertEqualcCs)|j||}|||d|dS)z[Fail if the two objects are unequal as determined by the '==' operator. rEN)r)rrrrEZassertion_funcrrr assertEqual8szTestCase.assertEqualcCsG||ksC|j|dt|t|f}|j|dS)zYFail if the two objects are equal as determined by the '!=' operator. z%s == %sN)rDrrF)rrrrErrrassertNotEqual?s zTestCase.assertNotEqualcCs||krdS|dk r4|dk r4td|dk rt|||krZdSdt|t|t|f}nT|dkrd}tt|||dkrdSdt|t||f}|j||}|j|dS)aFail 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 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. Nz specify delta or places not bothz%s != %s within %s deltarz%s != %s within %r places)rPabsrroundrDrF)rrrplacesrEdeltarGrrrassertAlmostEqualHs&         zTestCase.assertAlmostEqualcCs|dk r$|dk r$td|dk r||k rWt|||krWdSdt|t|t|f}na|dkrd}||k rtt|||dkrdSdt|t||f}|j||}|j|dS)aFail 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 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. Nz specify delta or places not bothz%s == %s within %s deltarrz%s == %s within %r places)rPrrrrDrF)rrrrrErrGrrrassertNotAlmostEqualos"   #   ,   zTestCase.assertNotAlmostEqualc'Cs|dk rt|j}t||sC|jd|t|ft||sz|jd|t|fnd}d}yt|}Wn"ttfk rd|}YnX|dkryt|}Wn"ttfk rd|}YnX|dkr&||krdSd|jft||}xt t ||D]} y|| } Wn0tt tfk r|d| |f7}PYnXy|| } Wn0tt tfk r|d | |f7}PYnX| | krH|d | ft| | 7}PqHW||kr3|dkr3t |t |kr3dS||kr|d |||f7}y"|d |t||f7}Wq&tt tfk r|d ||f7}Yq&Xnx||kr&|d|||f7}y"|d |t||f7}Wn/tt tfk r%|d||f7}YnX|} ddj tjtj|jtj|j} |j| | } |j|| }|j|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.rFrrrPNotImplementedError capitalizerrangemin IndexErrorr/joindifflibndiffpprintpformat splitlines_truncateMessagerDr)rZseq1Zseq2rEseq_typeZ seq_type_nameZ differingZlen1Zlen2iZitem1Zitem2rGdiffMsgrrrassertSequenceEquals              zTestCase.assertSequenceEqualcCsA|j}|dks't||kr/||S|tt|S)N)maxDiffr DIFF_OMITTED)rrudiffZmax_diffrrrr s zTestCase._truncateMessagecCs|j|||dtdS)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. r N)rr)rZlist1Zlist2rErrrrs zTestCase.assertListEqualcCs|j|||dtdS)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)rr?)rZtuple1Ztuple2rErrrrs zTestCase.assertTupleEqualc Csy|j|}Wnktk rK}z|jd|WYdd}~Xn6tk r}z|jd|WYdd}~XnXy|j|}Wnktk r}z|jd|WYdd}~Xn6tk r}z|jd|WYdd}~XnX|p |sdSg}|rO|jdx!|D]}|jt|q2W|r|jdx!|D]}|jt|qiWdj|} |j|j|| dS)aA 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) differencerPrrXrreprrrD) rZset1Zset2rEZ difference1r$Z difference2linesitemrGrrrrs2 #$#$     zTestCase.assertSetEqualcCsE||krAdt|t|f}|j|j||dS)zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sN)rrrD)rmember containerrErGrrrassertIn;s  zTestCase.assertIncCsE||krAdt|t|f}|j|j||dS)zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sN)rrrD)rrrrErGrrr assertNotInBs  zTestCase.assertNotIncCsE||k rAdt|t|f}|j|j||dS)zDJust like self.assertTrue(a is b), but with a nicer default message.z %s is not %sN)rrrD)rexpr1expr2rErGrrrassertIsIs  zTestCase.assertIscCs<||kr8dt|f}|j|j||dS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sN)rrrD)rrrrErGrrr assertIsNotPs zTestCase.assertIsNotcCs|j|td|j|td||krdt||}ddjtjtj|jtj|j}|j ||}|j |j ||dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr) assertIsInstancerrrrrr r r r rrD)rZd1Zd2rErGrrrrrVs zTestCase.assertDictEqualc Cstjdtg}g}xv|jD]h\}}||krQ|j|q)|||kr)|jdt|t|t||fq)W|p|sdSd}|rddjdd|D}|r|r|d 7}|d dj|7}|j|j||dS) z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %sNrz Missing: %s,css|]}t|VqdS)N)r)r<ryrrrr>usz4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rRrSrTitemsrrrrrD) rZsubsetZ dictionaryrEmissingZ mismatchedkeyvaluerGrrrassertDictContainsSubsetbs,     z!TestCase.assertDictContainsSubsetc Cst|t|}}y"tj|}tj|}Wn!tk r^t||}Yn X||krodSt||}|rd}dd|D}dj|} |j|| }|j||}|j |dS)aAn 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<rrrr s z-TestCase.assertCountEqual..r) rrCounterrPrrrr rDr) rrrrEZ first_seqZ second_seqZ differencesrGrrrrrassertCountEquals   zTestCase.assertCountEqualcCs5|j|td|j|td||kr1t||jks\t||jkro|j||||jdd}|jdd}t|dkr|jd|kr|dg}|dg}dt||}dd jt j ||}|j ||}|j |j ||d S) z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringkeependsTrz rz%s != %srN)r rr_diffThresholdrr rrrrrr rrD)rrrrEZ firstlinesZ secondlinesrGrrrrrs '  zTestCase.assertMultiLineEqualcCsE||ksAdt|t|f}|j|j||dS)zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sN)rrrD)rabrErGrrr assertLesss zTestCase.assertLesscCsE||ksAdt|t|f}|j|j||dS)zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sN)rrrD)rr,r-rErGrrrassertLessEquals zTestCase.assertLessEqualcCsE||ksAdt|t|f}|j|j||dS)zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sN)rrrD)rr,r-rErGrrr assertGreaters zTestCase.assertGreatercCsE||ksAdt|t|f}|j|j||dS)zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sN)rrrD)rr,r-rErGrrrassertGreaterEquals zTestCase.assertGreaterEqualcCs<|dk r8dt|f}|j|j||dS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not None)rrrD)rr(rErGrrr assertIsNones zTestCase.assertIsNonecCs/|dkr+d}|j|j||dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)rrD)rr(rErGrrrassertIsNotNones zTestCase.assertIsNotNonecCsBt||s>dt||f}|j|j||dS)zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer default message.z%s is not an instance of %rN)r.rrrD)rr(rrErGrrrr szTestCase.assertIsInstancecCsBt||r>dt||f}|j|j||dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rN)r.rrrD)rr(rrErGrrrassertNotIsInstanceszTestCase.assertNotIsInstancecOs%t|||}|jd||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)rrrLr*r+rrrrr5s zTestCase.assertRaisesRegexcOs%t|||}|jd||S)aAsserts 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)rjrZ)rrrLr*r+rrrrr6szTestCase.assertWarnsRegexcCskt|ttfr$tj|}|j|sgd|j|f}|j||}|j|dS)z=Fail the test unless the text matches the regular expression.z&Regex didn't match: %r not found in %rN) r.rbytesrJrKrbrcrDrF)rtextrLrErGrrr assertRegexszTestCase.assertRegexcCst|ttfr$tj|}|j|}|rd||j|j|j|f}|j ||}|j |dS)z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN) r.rr7rJrKrbstartendrcrDrF)rr8Zunexpected_regexrEmatchrGrrrassertNotRegexs zTestCase.assertNotRegexcsfdd}|S)Ncs,tjdjjtd||S)NzPlease use {0} instead.r)rRrSr]r rT)r*r+) original_funcrrdeprecated_func$s z,TestCase._deprecate..deprecated_funcr)r>r?r)r>r _deprecate#szTestCase._deprecateii)]r r r r AssertionErrorrFrrr+Z_classSetupFailedrrrrr classmethodrrrrrrrrrrrr&r'_subtest_msg_sentinelrrrrrrrrrrrrrDrrrrrrrrrrr rrrrrrrrr&r)rr.r/r0r1r2r3r r4r5r6r9r=r@ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrrUs              E    !   & c   + !        rcseZdZdZdddfddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ S)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|j||_||_||_||_dS)N)superrDr _setUpFunc _tearDownFunc _testFunc _description)rZtestFuncrr description)rrrrBs    zFunctionTestCase.__init__cCs|jdk r|jdS)N)rF)rrrrrIszFunctionTestCase.setUpcCs|jdk r|jdS)N)rG)rrrrrMszFunctionTestCase.tearDowncCs|jdS)N)rH)rrrrrQszFunctionTestCase.runTestcCs |jjS)N)rHr )rrrrrTszFunctionTestCase.idcCs\t||jstS|j|jko[|j|jko[|j|jko[|j|jkS)N)r.rrrFrGrHrI)rrrrrrWs zFunctionTestCase.__eq__cCs+tt||j|j|j|jfS)N)rr/rFrGrHrI)rrrrr`szFunctionTestCase.__hash__cCsdt|j|jjfS)Nz%s (%s))rrrHr )rrrrrdszFunctionTestCase.__str__cCsdt|j|jfS)Nz <%s tec=%s>)rrrH)rrrrrhszFunctionTestCase.__repr__cCsE|jdk r|jS|jj}|rA|jddjpDdS)Nrr)rIrHr rr)rrrrrrls z!FunctionTestCase.shortDescription)r r r r rrrrrrrrrrrr)rrrD9s        rDcs^eZdZfddZddZddZddZd d Zd d ZS) rcs8tj||_||_||_|j|_dS)N)rEr_messager"rrF)rr"rur)rrrrus     z_SubTest.__init__cCstddS)Nzsubtests cannot be run directly)r)rrrrr|sz_SubTest.runTestcCsg}|jtk r.|jdj|j|jrxdjddt|jjD}|jdj|dj|pdS)Nz[{}]z, css'|]\}}dj||VqdS)z{}={!r}N)r])r<krtrrrr>sz+_SubTest._subDescription..z({}) z ())rKrCrr]rrsortedr")rpartsZ params_descrrr_subDescriptions  z_SubTest._subDescriptioncCsdj|jj|jS)Nz{} {})r]r"rrP)rrrrrsz _SubTest.idcCs |jjS)zlReturns a one-line description of the subtest, or None if no description has been provided. )r"r)rrrrrsz_SubTest.shortDescriptioncCsdj|j|jS)Nz{} {})r]r"rP)rrrrrsz_SubTest.__str__) r r r rrrPrrrrr)rrrss    r).r r r0rrr rJrRrr&r^rrutilrrrrrZ __unittestobjectrCr Exceptionr rrrr)r6r8r9rr;rCrIr[rj namedtupler|rrrrrDrrrrrsN          ( (       /%5 ,: