Warning: Cannot modify header information - headers already sent by (output started at /var/www/jonas-eriksen.dk/pic/private/index.php:1) in /var/www/jonas-eriksen.dk/pic/private/index.php on line 215
PK!&%util.cpython-36.pycnu[3 \9@sdZddlmZmZddlmZdZdZdZdZ dZ dZ ee ee ee Z e dks\t dd Zd d Zd d dZddZddZddZddZeddZddZddZddZdS)!zVarious utility functions.) namedtuple OrderedDict) commonprefixTP cCsBt|||}|tkr>d|d|||t||df}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlenZ suffixlenskipr %/usr/lib64/python3.6/unittest/util.py_shortens&rcsttt|}ttt|}|tkr(|St|tt|tt}|t krttt |tkspt t t|tfdd|DSt tt tfdd|DS)Nc3s|]}|dVqdS)Nr ).0r )prefixr r r 'sz'_common_shorten_repr..c3s&|]}t|dttVqdS)N)r _MIN_DIFF_LEN _MIN_END_LEN)rr )rr r rr*s) tuplemap safe_reprmaxr _MAX_LENGTHr_MIN_BEGIN_LENr _MIN_COMMON_LENAssertionErrorr)argsmaxlenZ common_lenr )rr r_common_shorten_reprs    rFc CsRy t|}Wntk r*tj|}YnX| s>t|tkrB|S|dtdS)Nz [truncated]...)repr Exceptionobject__repr__rr)objZshortresultr r rr-s rcCsd|j|jfS)Nz%s.%s) __module__ __qualname__)clsr r rstrclass6sr)cCs*d}}g}g}xy||}||}||kr\|j||d7}x|||krX|d7}qBWn||kr|j||d7}xf|||kr|d7}qxWnL|d7}zx|||kr|d7}qWWd|d7}x|||kr|d7}qWXWqtk r|j||d|j||dPYqXqW||fS)arFinds elements in only one or the other of two, sorted input lists. Returns a two-element tuple of lists. The first list contains those elements in the "expected" list but not in the "actual" list, and the second contains those elements in the "actual" list but not in the "expected" list. Duplicate elements in either input list are ignored. rN)append IndexErrorextend)expectedactualijmissingZ unexpectedear r rsorted_list_difference9s:   r5c CsLg}x>|rB|j}y|j|Wqtk r>|j|YqXqW||fS)zSame behavior as sorted_list_difference but for lists of unorderable items (like dicts). As it does a linear search per item (remove) it has O(n*n) performance.)popremove ValueErrorr+)r.r/r2itemr r runorderable_list_differencebsr:cCs||k||kS)z.Return -1 if x < y, 0 if x == y and 1 if x > yr )xyr r r three_way_cmpssr=ZMismatchzactual expected valuecCsDt|t|}}t|t|}}t}g}xt|D]\}} | |krJq8d} } x.t||D] } || | kr^| d7} ||| <q^Wx,t|D] \} } | | kr| d7} ||| <qW| | kr8t| | | }|j|q8Wxlt|D]`\}} | |krqd} x2t||D]$} || | kr| d7} ||| <qWtd| | }|j|qW|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr*)listrr" enumeraterange _Mismatchr+)r/r.r tmnZNULLr%r0elemcnt_scnt_tr1Z other_elemdiffr r r_count_diff_all_purposeys<     rIcCs,t}x |D]}|j|dd||<q W|S)z@Return dict of element counts, in the order they were first seenrr*)rget)iterablecrEr r r_ordered_counts rMc Cst|t|}}g}x>|jD]2\}}|j|d}||kr t|||}|j|q Wx2|jD]&\}}||kr`td||}|j|q`W|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr)rMitemsrJrAr+) r/r.r rBr%rErFrGrHr r r_count_diff_hashables   rON)F)__doc__ collectionsrrZos.pathrZ __unittestrr rrrrrrrrr)r5r:r=rArIrMrOr r r rs,   ) #PK!u __init__.cpython-36.opt-1.pycnu[3 _Vjk @sdZddddddddd d d d d dddddgZejdddgdZddlmZddlmZmZm Z m Z m Z m Z m Z mZddlmZmZddlmZmZmZmZmZddlmZmZddlmZmZddlmZmZm Z m!Z!eZ"dd Z#d!S)"a Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's Smalltalk testing framework (used with permission). This module contains the core framework classes that form the basis of specific test cases and suites (TestCase, TestSuite etc.), and also a text-based utility class for running the tests and reporting the results (TextTestRunner). Simple usage: import unittest class IntegerArithmeticTestCase(unittest.TestCase): def testAdd(self): # test method names begin with 'test' self.assertEqual((1 + 2), 3) self.assertEqual(0 + 1, 1) def testMultiply(self): self.assertEqual((0 * 10), 0) self.assertEqual((5 * 8), 40) if __name__ == '__main__': unittest.main() Further information is available in the bundled documentation, and from http://docs.python.org/library/unittest.html Copyright (c) 1999-2003 Steve Purcell Copyright (c) 2003-2010 Python Software Foundation This module is free software, and you may redistribute it and/or modify it under the same terms as Python itself, so long as this copyright message and disclaimer are retained in their original form. IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. TestResultTestCase TestSuiteTextTestRunner TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResult removeResult removeHandlergetTestCaseNames makeSuite findTestCasesT)r)rrr r r r r _skipInRpmBuild) BaseTestSuiter)rrrrr) TestProgramr)rr)rrrrcCs"ddl}|jjt}|j||dS)N)Z start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsrosZthis_dirr!)/usr/lib64/python3.6/unittest/__init__.py load_testsKs r#N)$__doc____all__extendZ __unittestresultrZcaserrr r r r r rZsuiterrrrrrrrrrZrunnerrrZsignalsrrrrZ_TextTestResultr#r!r!r!r"-s    (PK!kR__init__.cpython-36.opt-2.pycnu[3 _Vjk @sdddddddddd d d d d ddddgZejdddgdZddlmZddlmZmZmZm Z m Z m Z m Z m Z ddlmZmZddlmZmZmZmZmZddlmZmZddlmZmZddlmZmZmZm Z eZ!ddZ"d S)! TestResultTestCase TestSuiteTextTestRunner TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResult removeResult removeHandlergetTestCaseNames makeSuite findTestCasesT)r)rrr r r r r _skipInRpmBuild) BaseTestSuiter)rrrrr) TestProgramr)rr)rrrrcCs"ddl}|jjt}|j||dS)N)Z start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsrosZthis_dirr!)/usr/lib64/python3.6/unittest/__init__.py load_testsKs r#N)#__all__extendZ __unittestresultrZcaserrr r r r r rZsuiterrrrrrrrrrZrunnerrrZsignalsrrrrZ_TextTestResultr#r!r!r!r"/s   (PK!u __init__.cpython-36.pycnu[3 _Vjk @sdZddddddddd d d d d dddddgZejdddgdZddlmZddlmZmZm Z m Z m Z m Z m Z mZddlmZmZddlmZmZmZmZmZddlmZmZddlmZmZddlmZmZm Z m!Z!eZ"dd Z#d!S)"a Python unit testing framework, based on Erich Gamma's JUnit and Kent Beck's Smalltalk testing framework (used with permission). This module contains the core framework classes that form the basis of specific test cases and suites (TestCase, TestSuite etc.), and also a text-based utility class for running the tests and reporting the results (TextTestRunner). Simple usage: import unittest class IntegerArithmeticTestCase(unittest.TestCase): def testAdd(self): # test method names begin with 'test' self.assertEqual((1 + 2), 3) self.assertEqual(0 + 1, 1) def testMultiply(self): self.assertEqual((0 * 10), 0) self.assertEqual((5 * 8), 40) if __name__ == '__main__': unittest.main() Further information is available in the bundled documentation, and from http://docs.python.org/library/unittest.html Copyright (c) 1999-2003 Steve Purcell Copyright (c) 2003-2010 Python Software Foundation This module is free software, and you may redistribute it and/or modify it under the same terms as Python itself, so long as this copyright message and disclaimer are retained in their original form. IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. TestResultTestCase TestSuiteTextTestRunner TestLoaderFunctionTestCasemaindefaultTestLoaderSkipTestskipskipIf skipUnlessexpectedFailureTextTestResultinstallHandlerregisterResult removeResult removeHandlergetTestCaseNames makeSuite findTestCasesT)r)rrr r r r r _skipInRpmBuild) BaseTestSuiter)rrrrr) TestProgramr)rr)rrrrcCs"ddl}|jjt}|j||dS)N)Z start_dirpattern)Zos.pathpathdirname__file__Zdiscover)loaderZtestsrosZthis_dirr!)/usr/lib64/python3.6/unittest/__init__.py load_testsKs r#N)$__doc____all__extendZ __unittestresultrZcaserrr r r r r rZsuiterrrrrrrrrrZrunnerrrZsignalsrrrrZ_TextTestResultr#r!r!r!r"-s    (PK!v?__main__.cpython-36.opt-1.pycnu[3 \@sddZddlZejdjdrBddlZejjejZedejd<[dZ ddl m Z m Z e dddS) zMain entry pointNz __main__.pyz -m unittestT)main TestProgram)module) __doc__sysargvendswithZos.pathospathbasename executableZ __unittestrrrr)/usr/lib64/python3.6/unittest/__main__.pysPK!ݥ~~__main__.cpython-36.opt-2.pycnu[3 \@s`ddlZejdjdr>ddlZejjejZedejd<[dZddl m Z m Z e dddS)Nz __main__.pyz -m unittestT)main TestProgram)module) sysargvendswithZos.pathospathbasename executableZ __unittestrrr r )/usr/lib64/python3.6/unittest/__main__.pysPK!v?__main__.cpython-36.pycnu[3 \@sddZddlZejdjdrBddlZejjejZedejd<[dZ ddl m Z m Z e dddS) zMain entry pointNz __main__.pyz -m unittestT)main TestProgram)module) __doc__sysargvendswithZos.pathospathbasename executableZ __unittestrrrr)/usr/lib64/python3.6/unittest/__main__.pysPK!0ĻĻcase.cpython-36.opt-1.pycnu[3 _Vj@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZmZmZmZdZeZdZGdd d eZGd d d eZGd d d eZGdddeZddZddZddZddZ ddZ!ddZ"GdddZ#ddZ$Gd d!d!e#Z%Gd"d#d#e%Z&Gd$d%d%e%Z'e j(d&d'd(gZ)Gd)d*d*ej*Z+Gd+d,d,e#Z,Gd-d.d.eZ-Gd/d0d0e-Z.Gd1d2d2e-Z/dS)3zTest 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%/usr/lib64/python3.6/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&eZdZdddZejdddZdS) _OutcomeNcCs4d|_||_t|d|_d|_g|_d|_g|_dS)NF addSubTestT)expecting_failurerhasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfrrrr__init__.s z_Outcome.__init__Fccs|j}d|_zy dVWntk r.Yntk rh}z d|_|jj|t|fWYdd}~Xnjtk rzYnXtj}|j r||_ nd|_|j j||fd}YnX|j r|jr|j j|dfWd|jo||_XdS)NTF) rKeyboardInterruptr rappendstrrsysexc_inforrrr)r test_caseisTestZ old_successer!rrrtestPartExecutor7s* $  z_Outcome.testPartExecutor)N)F)r r r r contextlibcontextmanagerr%rrrrr-s rcCs|S)Nr)objrrr_idUsr)csfdd}|S)z& Unconditionally skip a test. cs4t|ts$tj|fdd}|}d|_|_|S)Ncs tdS)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,rskipXs r6cCs|r t|StS)z/ Skip a test if the condition is true. )r6r)) conditionr,rrrskipIfhsr8cCs|s t|StS)z3 Skip a test unless the condition is true. )r6r))r7r,rrr skipUnlesspsr9cCs d|_|S)NT)__unittest_expecting_failure__)r4rrrrxsrcs4t|tr tfdd|DSt|to2t|S)Nc3s|]}t|VqdS)N) _is_subtype).0r$)basetyperr ~sz_is_subtype..)r.tupleallr/ issubclass)expectedr=r)r=rr;|s r;c@seZdZddZddZdS)_BaseTestCaseContextcCs ||_dS)N)r")rr"rrrrsz_BaseTestCaseContext.__init__cCs |jj|j|}|jj|dS)N)r"_formatMessagemsgfailureException)r standardMsgrErrr _raiseFailuresz"_BaseTestCaseContext._raiseFailureN)r r r rrHrrrrrCsrCcCsdtjkrt|StSdS)a Non-standard/downstream-only decorator for marking a specific unit test to be skipped when run within the %check of an rpmbuild. Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within the environment, and has no effect otherwise. ZWITHIN_PYTHON_RPM_BUILDN)osenvironr6r))r,rrr_skipInRpmBuilds rKc@seZdZdddZddZdS)_AssertRaisesBaseContextNcCs@tj||||_||_|dk r*tj|}||_d|_d|_dS)N) rCrrBr"recompileexpected_regexobj_namerE)rrBr"rOrrrrs  z!_AssertRaisesBaseContext.__init__cCszt|j|js"td||jf|rD|ddkrDtjdtdf}|sx|jdd|_ |rttjdt t |td|S|^}}y |j |_ Wntk 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 rPAttributeErrorr)rnamer*r+Z callable_objrrrhandles.  z_AssertRaisesBaseContext.handle)N)r r r rr]rrrrrLs rLc@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|dkrby |jj}Wntk r2t|j}YnX|jrP|jdj||jql|jdj|n tj|t ||js|dS|j d|_ |j dkrdS|j }|j t|s|jdj|jt|dS)Nz{} not raised by {}z {} not raisedFTz"{}" does not match "{}")rBr r[rrPrHformat traceback clear_framesrAwith_tracebackZ exceptionrOsearchpattern)rexc_type exc_valuetbexc_namerOrrr__exit__s(       z_AssertRaisesContext.__exit__N) r r r r BaseExceptionrRrTr_rjrrrrr^s r^c@s(eZdZdZeZdZddZddZdS)_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRx$tjjD]}t|ddr i|_q Wtjdd|_|jj|_tj d|j |S)N__warningregistry__T)recordalways) r modulesvaluesgetattrrmrUcatch_warningswarnings_managerr_ simplefilterrB)rvrrrr_s   z_AssertWarnsContext.__enter__c Cs|jj||||dk rdSy |jj}Wntk rFt|j}YnXd}xd|jD]Z}|j}t||jslqT|dkrx|}|j dk r|j j t| rqT||_ |j |_ |j |_ dSW|dk r|jdj|j jt||jr|jdj||jn|jdj|dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rtrjrBr r[rrUmessager.rOrdZwarningfilenamelinenorHr`rerP)rrfrgrhriZfirst_matchingmwrrrrjs8      z_AssertWarnsContext.__exit__N) r r r r WarningrRrTr_rjrrrrrls  rl_LoggingWatcherrecordsoutputc@s(eZdZdZddZddZddZdS) _CapturingHandlerzM A logging handler capturing all (raw and formatted) logging output. cCstjj|tgg|_dS)N)loggingHandlerrr}watcher)rrrrr,s z_CapturingHandler.__init__cCsdS)Nr)rrrrflush0sz_CapturingHandler.flushcCs*|jjj||j|}|jjj|dS)N)rr~rr`r)rrnrErrremit3s z_CapturingHandler.emitN)r r r r rrrrrrrr'src@s,eZdZdZdZddZddZddZd S) _AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)scCs:tj||||_|r(tjj|||_ntj|_d|_dS)N) rCr logger_namerZ _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.rrZLoggerloggerZ getLoggerZ FormatterLOGGING_FORMATrZ setFormatterrhandlers old_handlersr old_level propagate old_propagatesetLevel)rrZ formatterZhandlerrrrr_Hs   z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|jj|j|dk r.dSt|jj dkr\|j dj t j |j|jjdS)NFrz-no logs of level {} or higher triggered on {})rrrrrrrlenrr~rHr`rZ getLevelNamerr\)rrfrgrhrrrrjYs  z_AssertLogsContext.__exit__N)r r r r rrr_rjrrrrr:s  rc@seZdZdZeZdZdZdZdZ dd d Z d d Z d dZ ddZ ddZeddZeddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zejefd)d*Zd+d,Zd-d.Z d/d0Z!dd2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&ddd?Z(dd@dAZ)dBdCZ*dDdEZ+dFdGZ,ddHdIZ-dJdKZ.ddLdMZ/ddNdOZ0ddPdQZ1ddRdSZ2ddTdUZ3ddVdWZ4dXdYZ5ddZd[Z6dd\d]Z7dd^d_Z8dd`daZ9ddbdcZ:ddddeZ;ddfdgZddldmZ?ddndoZ@ddpdqZAddrdsZBddtduZCddvdwZDddxdyZEddzd{ZFdd|d}ZGdd~dZHddZIddZJdddZKdddZLddZMeMe0ZNZOeMe1ZPZQeMe2ZRZSeMe3ZTZUeMe)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||}Wn.tk rN|dkrJtd|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_testMethodDocrrr[ ValueError __class__r _cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictlistr?set frozensetr)rZ methodName testMethodrrrrs&     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)rZtypeobjfunctionrrrrs zTestCase.addTypeEqualityFunccOs|jj|||fdS)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)rr)rrr*r+rrr addCleanupszTestCase.addCleanupcCsdS)zAHook method for setting up the test fixture before exercising it.Nr)rrrrsetUpszTestCase.setUpcCsdS)zAHook method for deconstructing the test fixture after testing it.Nr)rrrrtearDownszTestCase.tearDowncCsdS)zKHook method for setting up class fixture before running tests in the class.Nr)clsrrr setUpClassszTestCase.setUpClasscCsdS)zVHook method for deconstructing the class fixture after running all tests in the class.Nr)rrrr tearDownClassszTestCase.tearDownClasscCsdS)Nrr)rrrrcountTestCasesszTestCase.countTestCasescCstjS)N)rZ TestResult)rrrrdefaultTestResultszTestCase.defaultTestResultcCs |j}|r|jddjpdS)zReturns 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)rsplitstrip)rdocrrrshortDescriptionszTestCase.shortDescriptioncCsdt|j|jfS)Nz%s.%s)rrr)rrrridsz TestCase.idcCs t|t|k rtS|j|jkS)N)r/NotImplementedr)rotherrrr__eq__szTestCase.__eq__cCstt||jfS)N)hashr/r)rrrr__hash__szTestCase.__hash__cCsd|jt|jfS)Nz%s (%s))rrr)rrrr__str__szTestCase.__str__cCsdt|j|jfS)Nz<%s testMethod=%s>)rrr)rrrr__repr__szTestCase.__repr__cCs<t|dd}|dk r |||ntjdtd|j|dS)NaddSkipz4TestResult has no addSkip method, skips not reportedr)rrrUrVRuntimeWarning addSuccess)rrr"r,rrrr_addSkips   zTestCase._addSkipcks|jdks|jj rdVdS|j}|dkr8tj|}n |jj|}t||||_zX|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. NT)r#)rrr collectionsChainMapparams new_child_SubTestr%rrZfailfastrr)rrErparentZ params_maprrrrsubTest s$  zTestCase.subTestcCsdx^|D]V\}}t|tr*|j|j||q|dk rt|d|jrP|j||q|j||qWdS)Nr)r.rrr"rArF addFailureZaddError)rrrtestr!rrr_feedErrorsToResult(s zTestCase._feedErrorsToResultc CsDy |j}Wn*tk r4tjdt|j|Yn X|||dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurer[rUrVrr)rrr!rrrr_addExpectedFailure2s zTestCase._addExpectedFailurecCshy |j}WnPtk rZtjdty tdWn$tk rT|j|tjYnXYn X||dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) addUnexpectedSuccessr[rUrVrrrr r!)rrrrrr_addUnexpectedSuccess<s  zTestCase._addUnexpectedSuccessNc (Cs|}|dkr.|j}t|dd}|dk r.||j|t||j}t|jdds^t|ddrz,t|jddpxt|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|| | qLW|j|| j| j r|r| jr|j|| jn |j|n |j||S|j||dkrt|d d} | dk r| | jjd| _d|_XdS) N startTestRunr2Fr3r:T)r# stopTestRun)rrrZ startTestrrrZstopTestrrr%rrrr doCleanupsrrrrrrrclear) rrZ orig_resultrrZskip_whyZexpecting_failure_methodZexpecting_failure_classroutcomerr,rrrrrunKsh               z TestCase.runc CsN|jp t}x:|jrF|jj\}}}|j||||WdQRXqW|jS)zNExecute all cleanup functions. Normally called for you after tearDown.N)rrrrXr%r)rrrr*r+rrrrs   zTestCase.doCleanupscOs |j||S)N)r)rr*kwdsrrr__call__szTestCase.__call__cCsJ|jt||j|jx&|jrD|jjd\}}}|||q WdS)z6Run the test without collecting errors in a TestResultrN)rrrrrrrX)rrr*r+rrrdebugs zTestCase.debugcCs t|dS)zSkip this test.N)r )rr,rrrskipTestszTestCase.skipTestcCs|j|dS)z)Fail immediately, with the given message.N)rF)rrErrrfailsz TestCase.failcCs&|r"|j|dt|}|j|dS)z#Check that the expression is false.z%s is not falseN)rDrrF)rexprrErrr assertFalseszTestCase.assertFalsecCs&|s"|j|dt|}|j|dS)z"Check that the expression is true.z%s is not trueN)rDrrF)rrrErrr assertTrueszTestCase.assertTruec CsP|js|p |S|dkr|Sy d||fStk rJdt|t|fSXdS)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 Os$t||}z|jd||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^r])rexpected_exceptionr*r+contextrrrrs zTestCase.assertRaisescOst||}|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)rlr])rexpected_warningr*r+rrrrrs zTestCase.assertWarnscCs t|||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.assertLogscCsFt|t|kr@|jjt|}|dk r@t|trt|||kr>dSdt|t|t|f}nF|dkrfd}||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 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. Nz specify delta or places not bothz%s == %s within %s deltarrz%s == %s within %r places)rSrrrrDrF)rrrrrErrGrrrassertNotAlmostEquals"   zTestCase.assertNotAlmostEqualc'Cs|dk rP|j}t||s.|jd|t|ft||sT|jd|t|fnd}d}y t|}Wn ttfk rd|}YnX|dkry t|}Wn ttfk rd|}YnX|dkr||krdSd|jft||}xt t ||D]} y || } Wn.tt tfk r8|d| |f7}PYnXy || } Wn.tt tfk rt|d | |f7}PYnX| | kr|d | ft| | 7}PqW||kr|dkrt |t |krdS||kr0|d |||f7}y|d |t||f7}Wn,tt tfk r,|d ||f7}YnXnh||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.rFrrrSNotImplementedError capitalizerrangemin IndexErrorr/joindifflibndiffpprintpformat splitlines_truncateMessagerDr)rZseq1Zseq2rEseq_typeZ seq_type_nameZ differingZlen1Zlen2iZitem1Zitem2rGdiffMsgrrrassertSequenceEquals               zTestCase.assertSequenceEqualcCs2|j}|dkst||kr"||S|tt|S)N)maxDiffr DIFF_OMITTED)rrwdiffZmax_diffrrrrszTestCase._truncateMessagecCs|j|||tddS)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. )rN)r r)rZlist1Zlist2rErrrr s zTestCase.assertListEqualcCs|j|||tddS)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. )rN)r r?)rZtuple1Ztuple2rErrrrs zTestCase.assertTupleEqualc Cshy|j|}Wn^tk r>}z|jd|WYdd}~Xn0tk rl}z|jd|WYdd}~XnXy|j|}Wn^tk r}z|jd|WYdd}~Xn0tk r}z|jd|WYdd}~XnX|p|sdSg}|r|jdx|D]}|jt|qW|rH|jdx|D]}|jt|q0Wdj|} |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) differencerSrr[rreprrrD) rZset1Zset2rEZ difference1r$Z difference2linesitemrGrrrr"s2        zTestCase.assertSetEqualcCs2||kr.dt|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 containerrErGrrrassertInMs zTestCase.assertIncCs2||kr.dt|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 assertNotInTs zTestCase.assertNotIncCs2||k r.dt|t|f}|j|j||dS)zDJust like self.assertTrue(a is b), but with a nicer default message.z %s is not %sN)rrrD)rexpr1expr2rErGrrrassertIs[s zTestCase.assertIscCs,||kr(dt|f}|j|j||dS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sN)rrrD)rrrrErGrrr assertIsNotbszTestCase.assertIsNotcCs~|j|td|j|td||krzdt||}ddjtjtj|jtj|j}|j ||}|j |j ||dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr) assertIsInstancerrrrrrrrrrrD)rZd1Zd2rErGr rrrrhs   zTestCase.assertDictEqualc Cstjdtg}g}xX|jD]L\}}||kr:|j|q|||kr|jdt|t|t||fqW|pt|szdSd}|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<rzrrrr>sz4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rUrVrWitemsrrrrrD) rZsubsetZ dictionaryrEZmissingZ mismatchedkeyvaluerGrrrassertDictContainsSubsetts,     z!TestCase.assertDictContainsSubsetc Cst|t|}}ytj|}tj|}Wntk rHt||}YnX||krVdSt||}|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<r rrr sz-TestCase.assertCountEqual..r) rrCounterrSrrrrrDr) rrrrEZ first_seqZ second_seqZ differencesrGrrrrrassertCountEquals      zTestCase.assertCountEqualcCs|j|td|j|td||krt||jks@t||jkrN|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 stringT)keependsrz rz%s != %srN)rrr_diffThresholdrrrrrrrrrrD)rrrrEZ firstlinesZ secondlinesrGr rrrrs     zTestCase.assertMultiLineEqualcCs2||ks.dt|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 assertLessszTestCase.assertLesscCs2||ks.dt|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%rErGrrrassertLessEqualszTestCase.assertLessEqualcCs2||ks.dt|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 assertGreaterszTestCase.assertGreatercCs2||ks.dt|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%rErGrrrassertGreaterEqualszTestCase.assertGreaterEqualcCs,|dk r(dt|f}|j|j||dS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not None)rrrD)rr(rErGrrr assertIsNoneszTestCase.assertIsNonecCs"|dkrd}|j|j||dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)rrD)rr(rErGrrrassertIsNotNoneszTestCase.assertIsNotNonecCs0t||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(rrErGrrrrs zTestCase.assertIsInstancecCs0t||r,dt||f}|j|j||dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rN)r.rrrD)rr(rrErGrrrassertNotIsInstances zTestCase.assertNotIsInstancecOst|||}|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^r])rrrOr*r+rrrrr-s zTestCase.assertRaisesRegexcOst|||}|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)rlr])rrrOr*r+rrrrr.s zTestCase.assertWarnsRegexcCsJt|ttfrtj|}|j|sFd|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.rbytesrMrNrdrerDrF)rtextrOrErGrrr assertRegexs    zTestCase.assertRegexcCs`t|ttfrtj|}|j|}|r\d||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.rr/rMrNrdstartendrerDrF)rr0Zunexpected_regexrEmatchrGrrrassertNotRegex&s   zTestCase.assertNotRegexcsfdd}|S)Ncs tjdjjtd||S)NzPlease use {0} instead.r)rUrVr`r rW)r*r+) original_funcrrdeprecated_func6s z,TestCase._deprecate..deprecated_funcr)r6r7r)r6r _deprecate5s zTestCase._deprecateii)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 AssertionErrorrFrr r#Z_classSetupFailedrrrrr classmethodrrrrrrrrrrrr&r'_subtest_msg_sentinelrrrrrrrrrrrrrDrrrrrrrrrr rrrrrrrrrrr!rr&r'r(r)r*r+rr,r-r.r1r5r8ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrrfs        E     !     ' c +      !               rcsjeZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ 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|j||_||_||_||_dS)N)superr<r _setUpFunc _tearDownFunc _testFunc _description)rZtestFuncrrZ description)rrrrTs zFunctionTestCase.__init__cCs|jdk r|jdS)N)r>)rrrrr[s zFunctionTestCase.setUpcCs|jdk r|jdS)N)r?)rrrrr_s zFunctionTestCase.tearDowncCs |jdS)N)r@)rrrrrcszFunctionTestCase.runTestcCs|jjS)N)r@r )rrrrrfszFunctionTestCase.idcCs@t||jstS|j|jko>|j|jko>|j|jko>|j|jkS)N)r.rrr>r?r@rA)rrrrrris     zFunctionTestCase.__eq__cCstt||j|j|j|jfS)N)rr/r>r?r@rA)rrrrrrszFunctionTestCase.__hash__cCsdt|j|jjfS)Nz%s (%s))rrr@r )rrrrrvs zFunctionTestCase.__str__cCsdt|j|jfS)Nz <%s tec=%s>)rrr@)rrrrrzs zFunctionTestCase.__repr__cCs2|jdk r|jS|jj}|r.|jddjp0dS)Nrr)rAr@r rr)rrrrrr~s z!FunctionTestCase.shortDescription)NNN)r r r r rrrrrrrrrr __classcell__rr)rrr<Ks r<csDeZdZfddZddZddZddZd d Zd d ZZ S) rcs(tj||_||_||_|j|_dS)N)r=r_messager"rrF)rr"rwr)rrrrs  z_SubTest.__init__cCs tddS)Nzsubtests cannot be run directly)r)rrrrrsz_SubTest.runTestcCsbg}|jtk r |jdj|j|jrTdjddt|jjD}|jdj|dj|p`dS)Nz[{}]z, css|]\}}dj||VqdS)z{}={!r}N)r`)r<krvrrrr>sz+_SubTest._subDescription..z({}) z ())rCr;rr`rrsortedr)rpartsZ params_descrrr_subDescriptions z_SubTest._subDescriptioncCsdj|jj|jS)Nz{} {})r`r"rrH)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"rH)rrrrrsz_SubTest.__str__) r r r rrrHrrrrBrr)rrrs   r)0r r r0rrIrrrMrUrr&rarrutilrrrrrZ __unittestobjectr;r  Exceptionr rrrr)r6r8r9rr;rCrKrLr^rl namedtupler}rrrrr<rrrrrsZ (  /%5 ,l:PK!+!case.cpython-36.opt-2.pycnu[3 _Vj@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl m Z ddl mZmZmZmZmZdZeZdZGdddeZGd d d eZGd d d eZGd ddeZddZddZddZddZddZ ddZ!GdddZ"ddZ#Gdd d e"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-Gd0d1d1e,Z.dS)2N)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__r r %/usr/lib64/python3.6/unittest/case.pyr sr c@s eZdZdS) _ShouldStopN)r r r r r r rr"src@s eZdZdS)_UnexpectedSuccessN)r r r r r r rr'src@s&eZdZdddZejdddZdS) _OutcomeNcCs4d|_||_t|d|_d|_g|_d|_g|_dS)NF addSubTestT)expecting_failurerhasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfrr r r__init__.s z_Outcome.__init__Fccs|j}d|_zy dVWntk r.Yntk rh}z d|_|jj|t|fWYdd}~Xnjtk rzYnXtj}|j r||_ nd|_|j j||fd}YnX|j r|jr|j j|dfWd|jo||_XdS)NTF) rKeyboardInterruptr rappendstrrsysexc_inforrrr)r test_caseisTestZ old_successer r r rtestPartExecutor7s* $  z_Outcome.testPartExecutor)N)F)r r r r contextlibcontextmanagerr$r r r rr-s rcCs|S)Nr )objr r r_idUsr(csfdd}|S)Ncs4t|ts$tj|fdd}|}d|_|_|S)Ncs tdS)N)r )argskwargs)reasonr r skip_wrapper^sz-skip..decorator..skip_wrapperT) isinstancetype functoolswraps__unittest_skip____unittest_skip_why__) test_itemr,)r+r r decorator\s  zskip..decoratorr )r+r4r )r+rskipXs r5cCs|r t|StS)N)r5r() conditionr+r r rskipIfhsr7cCs|s t|StS)N)r5r()r6r+r r r skipUnlesspsr8cCs d|_|S)NT)__unittest_expecting_failure__)r3r r rrxsrcs4t|tr tfdd|DSt|to2t|S)Nc3s|]}t|VqdS)N) _is_subtype).0r#)basetyper r ~sz_is_subtype..)r-tupleallr. issubclass)expectedr<r )r<rr:|s r:c@seZdZddZddZdS)_BaseTestCaseContextcCs ||_dS)N)r!)rr!r r rrsz_BaseTestCaseContext.__init__cCs |jj|j|}|jj|dS)N)r!_formatMessagemsgfailureException)r standardMsgrDr r r _raiseFailuresz"_BaseTestCaseContext._raiseFailureN)r r r rrGr r r rrBsrBcCsdtjkrt|StSdS)NZWITHIN_PYTHON_RPM_BUILD)osenvironr5r()r+r r r_skipInRpmBuilds rJc@seZdZdddZddZdS)_AssertRaisesBaseContextNcCs@tj||||_||_|dk r*tj|}||_d|_d|_dS)N) rBrrAr!recompileexpected_regexobj_namerD)rrAr!rNr r rrs  z!_AssertRaisesBaseContext.__init__cCszt|j|js"td||jf|rD|ddkrDtjdtdf}|sx|jdd|_ |rttjdt t |td|S|^}}y |j |_ Wntk rt||_ YnX||||WdQRXWdd}XdS)Nz%s() arg 1 must be %srzcallable is NonerDz3%r is an invalid keyword argument for this function)r:rA _base_type TypeError_base_type_strwarningswarnDeprecationWarningpoprDnextiterr rOAttributeErrorr)rnamer)r*Z callable_objr r rhandles.  z_AssertRaisesBaseContext.handle)N)r r r rr\r r r rrKs rKc@s$eZdZeZdZddZddZdS)_AssertRaisesContextz-an exception type or tuple of exception typescCs|S)Nr )rr r r __enter__sz_AssertRaisesContext.__enter__c Cs|dkrby |jj}Wntk r2t|j}YnX|jrP|jdj||jql|jdj|n tj|t ||js|dS|j d|_ |j dkrdS|j }|j t|s|jdj|jt|dS)Nz{} not raised by {}z {} not raisedFTz"{}" does not match "{}")rAr rZrrOrGformat traceback clear_framesr@with_tracebackZ exceptionrNsearchpattern)rexc_type exc_valuetbexc_namerNr r r__exit__s(       z_AssertRaisesContext.__exit__N)r r r BaseExceptionrQrSr^rir r r rr]sr]c@s$eZdZeZdZddZddZdS)_AssertWarnsContextz(a warning type or tuple of warning typescCsRx$tjjD]}t|ddr i|_q Wtjdd|_|jj|_tj d|j |S)N__warningregistry__T)recordalways) rmodulesvaluesgetattrrlrTcatch_warningswarnings_managerr^ simplefilterrA)rvr r rr^s   z_AssertWarnsContext.__enter__c Cs|jj||||dk rdSy |jj}Wntk rFt|j}YnXd}xd|jD]Z}|j}t||jslqT|dkrx|}|j dk r|j j t| rqT||_ |j |_ |j |_ dSW|dk r|jdj|j jt||jr|jdj||jn|jdj|dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rsrirAr rZrrTmessager-rNrcZwarningfilenamelinenorGr_rdrO)rrerfrgrhZfirst_matchingmwr r rris8      z_AssertWarnsContext.__exit__N)r r r WarningrQrSr^rir r r rrks rk_LoggingWatcherrecordsoutputc@s$eZdZddZddZddZdS)_CapturingHandlercCstjj|tgg|_dS)N)loggingHandlerrr|watcher)rr r rr,s z_CapturingHandler.__init__cCsdS)Nr )rr r rflush0sz_CapturingHandler.flushcCs*|jjj||j|}|jjj|dS)N)rr}rr_r~)rrmrDr r remit3s z_CapturingHandler.emitN)r r r rrrr r r rr'src@s(eZdZdZddZddZddZdS) _AssertLogsContextz"%(levelname)s:%(name)s:%(message)scCs:tj||||_|r(tjj|||_ntj|_d|_dS)N) rBr logger_namerZ _nameToLevelgetlevelINFOrD)rr!rrr r rr?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-rrZLoggerloggerZ getLoggerZ FormatterLOGGING_FORMATrZ setFormatterrhandlers old_handlersr old_level propagate old_propagatesetLevel)rrZ formatterZhandlerr r rr^Hs   z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|jj|j|dk r.dSt|jj dkr\|j dj t j |j|jjdS)NFrz-no logs of level {} or higher triggered on {})rrrrrrrlenrr}rGr_rZ getLevelNamerr[)rrerfrgr r rriYs  z_AssertLogsContext.__exit__N)r r r rrr^rir r r rr:s rc@seZdZeZdZdZdZdZddd Z d d Z d d Z ddZ ddZ eddZeddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'Zejefd(d)Zd*d+Zd,d-Zd.d/Z dd1d2Z!d3d4Z"d5d6Z#d7d8Z$d9d:Z%dd;d<Z&dd=d>Z'dd?d@Z(dAdBZ)dCdDZ*dEdFZ+ddGdHZ,dIdJZ-ddKdLZ.ddMdNZ/ddOdPZ0ddQdRZ1ddSdTZ2ddUdVZ3dWdXZ4ddYdZZ5dd[d\Z6dd]d^Z7dd_d`Z8ddadbZ9ddcddZ:ddedfZ;ddgdhZddmdnZ?ddodpZ@ddqdrZAddsdtZBddudvZCddwdxZDddydzZEdd{d|ZFdd}d~ZGddZHddZIdddZJdddZKddZLeLe/ZMZNeLe0ZOZPeLe1ZQZReLe2ZSZTeLe(ZUZVeLe*ZWeLe'ZXeLeHZYeLeJZZeLeKZ[d0S)TestCaseTPFrunTestc Cs||_d|_d|_yt||}Wn.tk rN|dkrJtd|j|fYn X|j|_g|_d|_ i|_ |j t d|j t d|j td|j td|j td|j tddS) NzNo testrzno such test method in %s: %sassertDictEqualassertListEqualassertTupleEqualassertSetEqualassertMultiLineEqual)_testMethodName_outcome_testMethodDocrqrZ ValueError __class____doc__ _cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictlistr>set frozensetr)rZ methodName testMethodr r rrs&     zTestCase.__init__cCs||j|<dS)N)r)rZtypeobjfunctionr r rrs zTestCase.addTypeEqualityFunccOs|jj|||fdS)N)rr)rrr)r*r r r addCleanupszTestCase.addCleanupcCsdS)Nr )rr r rsetUpszTestCase.setUpcCsdS)Nr )rr r rtearDownszTestCase.tearDowncCsdS)Nr )clsr r r setUpClassszTestCase.setUpClasscCsdS)Nr )rr r r tearDownClassszTestCase.tearDownClasscCsdS)Nrr )rr r rcountTestCasesszTestCase.countTestCasescCstjS)N)rZ TestResult)rr r rdefaultTestResultszTestCase.defaultTestResultcCs |j}|r|jddjpdS)N r)rsplitstrip)rdocr r rshortDescriptionszTestCase.shortDescriptioncCsdt|j|jfS)Nz%s.%s)rrr)rr r ridsz TestCase.idcCs t|t|k rtS|j|jkS)N)r.NotImplementedr)rotherr r r__eq__szTestCase.__eq__cCstt||jfS)N)hashr.r)rr r r__hash__szTestCase.__hash__cCsd|jt|jfS)Nz%s (%s))rrr)rr r r__str__szTestCase.__str__cCsdt|j|jfS)Nz<%s testMethod=%s>)rrr)rr r r__repr__szTestCase.__repr__cCs<t|dd}|dk r |||ntjdtd|j|dS)NaddSkipz4TestResult has no addSkip method, skips not reportedr)rqrTrURuntimeWarning addSuccess)rrr!r+rr r r_addSkips   zTestCase._addSkipcks|jdks|jj rdVdS|j}|dkr8tj|}n |jj|}t||||_zX|jj|jdd dVWdQRX|jj s|jj }|dk r|j rt n |jj rt Wd||_XdS)NT)r")rrr collectionsChainMapparams new_child_SubTestr$rrZfailfastrr)rrDrparentZ params_maprr r rsubTest s$  zTestCase.subTestcCsdx^|D]V\}}t|tr*|j|j||q|dk rt|d|jrP|j||q|j||qWdS)Nr)r-rrr!r@rE addFailureZaddError)rrrtestr r r r_feedErrorsToResult(s zTestCase._feedErrorsToResultc CsDy |j}Wn*tk r4tjdt|j|Yn X|||dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurerZrTrUrr)rrr rr r r_addExpectedFailure2s zTestCase._addExpectedFailurecCshy |j}WnPtk rZtjdty tdWn$tk rT|j|tjYnXYn X||dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) addUnexpectedSuccessrZrTrUrrrrr )rrrr r r_addUnexpectedSuccess<s  zTestCase._addUnexpectedSuccessNc (Cs|}|dkr.|j}t|dd}|dk r.||j|t||j}t|jdds^t|ddrz,t|jddpxt|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|| | qLW|j|| j| j r|r| jr|j|| jn |j|n |j||S|j||dkrt|d d} | dk r| | jjd| _d|_XdS) N startTestRunr1Fr2r9T)r" stopTestRun)rrqZ startTestrrrZstopTestrrr$rrrr doCleanupsrrrrrrrclear) rrZ orig_resultrrZskip_whyZexpecting_failure_methodZexpecting_failure_classroutcomerr+rr r rrunKsh               z TestCase.runc CsN|jp t}x:|jrF|jj\}}}|j||||WdQRXqW|jS)N)rrrrWr$r)rrrr)r*r r rrs   zTestCase.doCleanupscOs |j||S)N)r)rr)kwdsr r r__call__szTestCase.__call__cCsJ|jt||j|jx&|jrD|jjd\}}}|||q WdS)Nr)rrqrrrrW)rrr)r*r r rdebugs zTestCase.debugcCs t|dS)N)r )rr+r r rskipTestszTestCase.skipTestcCs|j|dS)N)rE)rrDr r rfailsz TestCase.failcCs&|r"|j|dt|}|j|dS)Nz%s is not false)rCrrE)rexprrDr r r assertFalseszTestCase.assertFalsecCs&|s"|j|dt|}|j|dS)Nz%s is not true)rCrrE)rrrDr r r assertTrueszTestCase.assertTruec CsP|js|p |S|dkr|Sy d||fStk rJdt|t|fSXdS)Nz%s : %s) longMessageUnicodeDecodeErrorr)rrDrFr r rrCs  zTestCase._formatMessagec Os$t||}z|jd||Sd}XdS)N assertRaises)r]r\)rexpected_exceptionr)r*contextr r rrs zTestCase.assertRaisescOst||}|jd||S)N assertWarns)rkr\)rexpected_warningr)r*rr r rrs zTestCase.assertWarnscCs t|||S)N)r)rrrr r r assertLogsszTestCase.assertLogscCsFt|t|kr@|jjt|}|dk r@t|trt|||kr>dSdt|t|t|f}nF|dkrfd}||k rtt|||dkrdSdt|t||f}|j||}|j|dS)Nz specify delta or places not bothz%s == %s within %s deltarrz%s == %s within %r places)rRrrrrCrE)rrrrrDrrFr r rassertNotAlmostEquals"   zTestCase.assertNotAlmostEqualc'Cs|dk rP|j}t||s.|jd|t|ft||sT|jd|t|fnd}d}y t|}Wn ttfk rd|}YnX|dkry t|}Wn ttfk rd|}YnX|dkr||krdSd|jft||}xt t ||D]} y || } Wn.tt tfk r8|d| |f7}PYnXy || } Wn.tt tfk rt|d| |f7}PYnX| | kr|d | ft| | 7}PqW||kr|dkrt |t |krdS||kr0|d |||f7}y|d |t||f7}Wn,tt tfk r,|d ||f7}YnXnh||kr|d |||f7}y|d |t||f7}Wn,tt tfk r|d||f7}YnX|} ddj tjtj|jtj|j} |j| | } |j|| }|j|dS)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-rErrrRNotImplementedError capitalizerrangemin IndexErrorr.joindifflibndiffpprintpformat splitlines_truncateMessagerCr)rZseq1Zseq2rDseq_typeZ seq_type_nameZ differingZlen1Zlen2iZitem1Zitem2rFdiffMsgr r rassertSequenceEquals               zTestCase.assertSequenceEqualcCs2|j}|dkst||kr"||S|tt|S)N)maxDiffr DIFF_OMITTED)rrvdiffZmax_diffr r rrszTestCase._truncateMessagecCs|j|||tddS)N)r)r r)rZlist1Zlist2rDr r rr s zTestCase.assertListEqualcCs|j|||tddS)N)r)r r>)rZtuple1Ztuple2rDr r rrs zTestCase.assertTupleEqualc Cshy|j|}Wn^tk r>}z|jd|WYdd}~Xn0tk rl}z|jd|WYdd}~XnXy|j|}Wn^tk r}z|jd|WYdd}~Xn0tk r}z|jd|WYdd}~XnX|p|sdSg}|r|jdx|D]}|jt|qW|rH|jdx|D]}|jt|q0Wdj|} |j|j|| dS)Nz/invalid type when attempting set difference: %sz2first 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) differencerRrrZrreprrrC) rZset1Zset2rDZ difference1r#Z difference2linesitemrFr r rr"s2        zTestCase.assertSetEqualcCs2||kr.dt|t|f}|j|j||dS)Nz%s not found in %s)rrrC)rmember containerrDrFr r rassertInMs zTestCase.assertIncCs2||kr.dt|t|f}|j|j||dS)Nz%s unexpectedly found in %s)rrrC)rrrrDrFr r r assertNotInTs zTestCase.assertNotIncCs2||k r.dt|t|f}|j|j||dS)Nz %s is not %s)rrrC)rexpr1expr2rDrFr r rassertIs[s zTestCase.assertIscCs,||kr(dt|f}|j|j||dS)Nzunexpectedly identical: %s)rrrC)rrrrDrFr r r assertIsNotbszTestCase.assertIsNotcCs~|j|td|j|td||krzdt||}ddjtjtj|jtj|j}|j ||}|j |j ||dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr) assertIsInstancerrrrrrrrrrrC)rZd1Zd2rDrFr r r rrhs   zTestCase.assertDictEqualc Cstjdtg}g}xX|jD]L\}}||kr:|j|q|||kr|jdt|t|t||fqW|pt|szdSd}|rddjdd|D}|r|r|d7}|d dj|7}|j|j||dS) Nz&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %srz Missing: %s,css|]}t|VqdS)N)r)r;ryr r rr=sz4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rTrUrVitemsrrrrrC) rZsubsetZ dictionaryrDZmissingZ mismatchedkeyvaluerFr r rassertDictContainsSubsetts,     z!TestCase.assertDictContainsSubsetc Cst|t|}}ytj|}tj|}Wntk rHt||}YnX||krVdSt||}|rd}dd|D}dj|} |j|| }|j||}|j |dS)NzElement counts were not equal: cSsg|] }d|qS)z First has %d, Second has %d: %rr )r;r r r r sz-TestCase.assertCountEqual..r) rrCounterrRrrrrrCr) rrrrDZ first_seqZ second_seqZ differencesrFrrr r rassertCountEquals      zTestCase.assertCountEqualcCs|j|td|j|td||krt||jks@t||jkrN|j||||jdd}|jdd}t|dkr|jd|kr|dg}|dg}dt||}dd jt j ||}|j ||}|j |j ||dS) NzFirst argument is not a stringzSecond argument is not a stringT)keependsrz rz%s != %sr)rrr_diffThresholdrrrrrrrrrrC)rrrrDZ firstlinesZ secondlinesrFr r r rrs     zTestCase.assertMultiLineEqualcCs2||ks.dt|t|f}|j|j||dS)Nz%s not less than %s)rrrC)rabrDrFr r r assertLessszTestCase.assertLesscCs2||ks.dt|t|f}|j|j||dS)Nz%s not less than or equal to %s)rrrC)rr$r%rDrFr r rassertLessEqualszTestCase.assertLessEqualcCs2||ks.dt|t|f}|j|j||dS)Nz%s not greater than %s)rrrC)rr$r%rDrFr r r assertGreaterszTestCase.assertGreatercCs2||ks.dt|t|f}|j|j||dS)Nz"%s not greater than or equal to %s)rrrC)rr$r%rDrFr r rassertGreaterEqualszTestCase.assertGreaterEqualcCs,|dk r(dt|f}|j|j||dS)Nz%s is not None)rrrC)rr'rDrFr r r assertIsNoneszTestCase.assertIsNonecCs"|dkrd}|j|j||dS)Nzunexpectedly None)rrC)rr'rDrFr r rassertIsNotNoneszTestCase.assertIsNotNonecCs0t||s,dt||f}|j|j||dS)Nz%s is not an instance of %r)r-rrrC)rr'rrDrFr r rrs zTestCase.assertIsInstancecCs0t||r,dt||f}|j|j||dS)Nz%s is an instance of %r)r-rrrC)rr'rrDrFr r rassertNotIsInstances zTestCase.assertNotIsInstancecOst|||}|jd||S)NassertRaisesRegex)r]r\)rrrNr)r*rr r rr-s zTestCase.assertRaisesRegexcOst|||}|jd||S)NassertWarnsRegex)rkr\)rrrNr)r*rr r rr.s zTestCase.assertWarnsRegexcCsJt|ttfrtj|}|j|sFd|j|f}|j||}|j|dS)Nz&Regex didn't match: %r not found in %r) r-rbytesrLrMrcrdrCrE)rtextrNrDrFr r r assertRegexs    zTestCase.assertRegexcCs`t|ttfrtj|}|j|}|r\d||j|j|j|f}|j ||}|j |dS)Nz"Regex matched: %r matches %r in %r) r-rr/rLrMrcstartendrdrCrE)rr0Zunexpected_regexrDmatchrFr r rassertNotRegex&s   zTestCase.assertNotRegexcsfdd}|S)Ncs tjdjjtd||S)NzPlease use {0} instead.r)rTrUr_r rV)r)r*) original_funcr rdeprecated_func6s z,TestCase._deprecate..deprecated_funcr )r6r7r )r6r _deprecate5s zTestCase._deprecateii)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 AssertionErrorrErr r#Z_classSetupFailedrrrrr classmethodrrrrrrrrrrrr%r&_subtest_msg_sentinelrrrrrrrrrrrrrCrrrrrrrrrr rrrrrrrrrrr!rr&r'r(r)r*r+rr,r-r.r1r5r8ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesr r r rrfs!        E     !     ' c +      !               rcsfeZdZdfdd ZddZddZdd Zd d Zd d ZddZ ddZ ddZ ddZ Z S)FunctionTestCaseNcs*tt|j||_||_||_||_dS)N)superr<r _setUpFunc _tearDownFunc _testFunc _description)rZtestFuncrrZ description)rr rrTs zFunctionTestCase.__init__cCs|jdk r|jdS)N)r>)rr r rr[s zFunctionTestCase.setUpcCs|jdk r|jdS)N)r?)rr r rr_s zFunctionTestCase.tearDowncCs |jdS)N)r@)rr r rrcszFunctionTestCase.runTestcCs|jjS)N)r@r )rr r rrfszFunctionTestCase.idcCs@t||jstS|j|jko>|j|jko>|j|jko>|j|jkS)N)r-rrr>r?r@rA)rrr r rris     zFunctionTestCase.__eq__cCstt||j|j|j|jfS)N)rr.r>r?r@rA)rr r rrrszFunctionTestCase.__hash__cCsdt|j|jjfS)Nz%s (%s))rrr@r )rr r rrvs zFunctionTestCase.__str__cCsdt|j|jfS)Nz <%s tec=%s>)rrr@)rr r rrzs zFunctionTestCase.__repr__cCs2|jdk r|jS|jj}|r.|jddjp0dS)Nrr)rAr@rrr)rrr r rr~s z!FunctionTestCase.shortDescription)NNN)r r r rrrrrrrrrr __classcell__r r )rrr<Ks  r<csDeZdZfddZddZddZddZd d Zd d ZZ S) rcs(tj||_||_||_|j|_dS)N)r=r_messager!rrE)rr!rvr)rr rrs  z_SubTest.__init__cCs tddS)Nzsubtests cannot be run directly)r)rr r rrsz_SubTest.runTestcCsbg}|jtk r |jdj|j|jrTdjddt|jjD}|jdj|dj|p`dS)Nz[{}]z, css|]\}}dj||VqdS)z{}={!r}N)r_)r;krur r rr=sz+_SubTest._subDescription..z({}) z ())rCr;rr_rrsortedr)rpartsZ params_descr r r_subDescriptions z_SubTest._subDescriptioncCsdj|jj|jS)Nz{} {})r_r!rrH)rr r rrsz _SubTest.idcCs |jjS)N)r!r)rr r rrsz_SubTest.shortDescriptioncCsdj|j|jS)Nz{} {})r_r!rH)rr r rrsz_SubTest.__str__) r r r rrrHrrrrBr r )rrrs   r)/rr/rrHrrrLrTrr%r`rrutilrrrrrZ __unittestobjectr;r  Exceptionr rrrr(r5r7r8rr:rBrJrKr]rk namedtupler|rrrrr<rr r r rsX (  /%5 ,l:PK!(case.cpython-36.pycnu[3 _Vj@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z ddlmZmZmZmZmZdZeZdZGdd d eZGd d d eZGd d d eZGdddeZddZddZddZddZ ddZ!ddZ"GdddZ#ddZ$Gd d!d!e#Z%Gd"d#d#e%Z&Gd$d%d%e%Z'e j(d&d'd(gZ)Gd)d*d*ej*Z+Gd+d,d,e#Z,Gd-d.d.eZ-Gd/d0d0e-Z.Gd1d2d2e-Z/dS)3zTest 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%/usr/lib64/python3.6/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&eZdZdddZejdddZdS) _OutcomeNcCs4d|_||_t|d|_d|_g|_d|_g|_dS)NF addSubTestT)expecting_failurerhasattrresult_supports_subtestssuccessskippedexpectedFailureerrors)selfrrrr__init__.s z_Outcome.__init__Fccs|j}d|_zy dVWntk r.Yntk rh}z d|_|jj|t|fWYdd}~Xnjtk rzYnXtj}|j r||_ nd|_|j j||fd}YnX|j r|jr|j j|dfWd|jo||_XdS)NTF) rKeyboardInterruptr rappendstrrsysexc_inforrrr)r test_caseisTestZ old_successer!rrrtestPartExecutor7s* $  z_Outcome.testPartExecutor)N)F)r r r r contextlibcontextmanagerr%rrrrr-s rcCs|S)Nr)objrrr_idUsr)csfdd}|S)z& Unconditionally skip a test. cs4t|ts$tj|fdd}|}d|_|_|S)Ncs tdS)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,rskipXs r6cCs|r t|StS)z/ Skip a test if the condition is true. )r6r)) conditionr,rrrskipIfhsr8cCs|s t|StS)z3 Skip a test unless the condition is true. )r6r))r7r,rrr skipUnlesspsr9cCs d|_|S)NT)__unittest_expecting_failure__)r4rrrrxsrcs4t|tr tfdd|DSt|to2t|S)Nc3s|]}t|VqdS)N) _is_subtype).0r$)basetyperr ~sz_is_subtype..)r.tupleallr/ issubclass)expectedr=r)r=rr;|s r;c@seZdZddZddZdS)_BaseTestCaseContextcCs ||_dS)N)r")rr"rrrrsz_BaseTestCaseContext.__init__cCs |jj|j|}|jj|dS)N)r"_formatMessagemsgfailureException)r standardMsgrErrr _raiseFailuresz"_BaseTestCaseContext._raiseFailureN)r r r rrHrrrrrCsrCcCsdtjkrt|StSdS)a Non-standard/downstream-only decorator for marking a specific unit test to be skipped when run within the %check of an rpmbuild. Specifically, this takes effect when WITHIN_PYTHON_RPM_BUILD is set within the environment, and has no effect otherwise. ZWITHIN_PYTHON_RPM_BUILDN)osenvironr6r))r,rrr_skipInRpmBuilds rKc@seZdZdddZddZdS)_AssertRaisesBaseContextNcCs@tj||||_||_|dk r*tj|}||_d|_d|_dS)N) rCrrBr"recompileexpected_regexobj_namerE)rrBr"rOrrrrs  z!_AssertRaisesBaseContext.__init__cCszt|j|js"td||jf|rD|ddkrDtjdtdf}|sx|jdd|_ |rttjdt t |td|S|^}}y |j |_ Wntk 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 rPAttributeErrorr)rnamer*r+Z callable_objrrrhandles.  z_AssertRaisesBaseContext.handle)N)r r r rr]rrrrrLs rLc@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|dkrby |jj}Wntk r2t|j}YnX|jrP|jdj||jql|jdj|n tj|t ||js|dS|j d|_ |j dkrdS|j }|j t|s|jdj|jt|dS)Nz{} not raised by {}z {} not raisedFTz"{}" does not match "{}")rBr r[rrPrHformat traceback clear_framesrAwith_tracebackZ exceptionrOsearchpattern)rexc_type exc_valuetbexc_namerOrrr__exit__s(       z_AssertRaisesContext.__exit__N) r r r r BaseExceptionrRrTr_rjrrrrr^s r^c@s(eZdZdZeZdZddZddZdS)_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRx$tjjD]}t|ddr i|_q Wtjdd|_|jj|_tj d|j |S)N__warningregistry__T)recordalways) r modulesvaluesgetattrrmrUcatch_warningswarnings_managerr_ simplefilterrB)rvrrrr_s   z_AssertWarnsContext.__enter__c Cs|jj||||dk rdSy |jj}Wntk rFt|j}YnXd}xd|jD]Z}|j}t||jslqT|dkrx|}|j dk r|j j t| rqT||_ |j |_ |j |_ dSW|dk r|jdj|j jt||jr|jdj||jn|jdj|dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rtrjrBr r[rrUmessager.rOrdZwarningfilenamelinenorHr`rerP)rrfrgrhriZfirst_matchingmwrrrrjs8      z_AssertWarnsContext.__exit__N) r r r r WarningrRrTr_rjrrrrrls  rl_LoggingWatcherrecordsoutputc@s(eZdZdZddZddZddZdS) _CapturingHandlerzM A logging handler capturing all (raw and formatted) logging output. cCstjj|tgg|_dS)N)loggingHandlerrr}watcher)rrrrr,s z_CapturingHandler.__init__cCsdS)Nr)rrrrflush0sz_CapturingHandler.flushcCs*|jjj||j|}|jjj|dS)N)rr~rr`r)rrnrErrremit3s z_CapturingHandler.emitN)r r r r rrrrrrrr'src@s,eZdZdZdZddZddZddZd S) _AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)scCs:tj||||_|r(tjj|||_ntj|_d|_dS)N) rCr logger_namerZ _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.rrZLoggerloggerZ getLoggerZ FormatterLOGGING_FORMATrZ setFormatterrhandlers old_handlersr old_level propagate old_propagatesetLevel)rrZ formatterZhandlerrrrr_Hs   z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|jj|j|dk r.dSt|jj dkr\|j dj t j |j|jjdS)NFrz-no logs of level {} or higher triggered on {})rrrrrrrlenrr~rHr`rZ getLevelNamerr\)rrfrgrhrrrrjYs  z_AssertLogsContext.__exit__N)r r r r rrr_rjrrrrr:s  rc@seZdZdZeZdZdZdZdZ dd d Z d d Z d dZ ddZ ddZeddZeddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zejefd)d*Zd+d,Zd-d.Z d/d0Z!dd2d3Z"d4d5Z#d6d7Z$d8d9Z%d:d;Z&ddd?Z(dd@dAZ)dBdCZ*dDdEZ+dFdGZ,ddHdIZ-dJdKZ.ddLdMZ/ddNdOZ0ddPdQZ1ddRdSZ2ddTdUZ3ddVdWZ4dXdYZ5ddZd[Z6dd\d]Z7dd^d_Z8dd`daZ9ddbdcZ:ddddeZ;ddfdgZddldmZ?ddndoZ@ddpdqZAddrdsZBddtduZCddvdwZDddxdyZEddzd{ZFdd|d}ZGdd~dZHddZIddZJdddZKdddZLddZMeMe0ZNZOeMe1ZPZQeMe2ZRZSeMe3ZTZUeMe)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||}Wn.tk rN|dkrJtd|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_testMethodDocrrr[ ValueError __class__r _cleanups_subtest_type_equality_funcsaddTypeEqualityFuncdictlistr?set frozensetr)rZ methodName testMethodrrrrs&     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)rZtypeobjfunctionrrrrs zTestCase.addTypeEqualityFunccOs|jj|||fdS)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)rr)rrr*r+rrr addCleanupszTestCase.addCleanupcCsdS)zAHook method for setting up the test fixture before exercising it.Nr)rrrrsetUpszTestCase.setUpcCsdS)zAHook method for deconstructing the test fixture after testing it.Nr)rrrrtearDownszTestCase.tearDowncCsdS)zKHook method for setting up class fixture before running tests in the class.Nr)clsrrr setUpClassszTestCase.setUpClasscCsdS)zVHook method for deconstructing the class fixture after running all tests in the class.Nr)rrrr tearDownClassszTestCase.tearDownClasscCsdS)Nrr)rrrrcountTestCasesszTestCase.countTestCasescCstjS)N)rZ TestResult)rrrrdefaultTestResultszTestCase.defaultTestResultcCs |j}|r|jddjpdS)zReturns 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)rsplitstrip)rdocrrrshortDescriptionszTestCase.shortDescriptioncCsdt|j|jfS)Nz%s.%s)rrr)rrrridsz TestCase.idcCs t|t|k rtS|j|jkS)N)r/NotImplementedr)rotherrrr__eq__szTestCase.__eq__cCstt||jfS)N)hashr/r)rrrr__hash__szTestCase.__hash__cCsd|jt|jfS)Nz%s (%s))rrr)rrrr__str__szTestCase.__str__cCsdt|j|jfS)Nz<%s testMethod=%s>)rrr)rrrr__repr__szTestCase.__repr__cCs<t|dd}|dk r |||ntjdtd|j|dS)NaddSkipz4TestResult has no addSkip method, skips not reportedr)rrrUrVRuntimeWarning addSuccess)rrr"r,rrrr_addSkips   zTestCase._addSkipcks|jdks|jj rdVdS|j}|dkr8tj|}n |jj|}t||||_zX|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. NT)r#)rrr collectionsChainMapparams new_child_SubTestr%rrZfailfastrr)rrErparentZ params_maprrrrsubTest s$  zTestCase.subTestcCsdx^|D]V\}}t|tr*|j|j||q|dk rt|d|jrP|j||q|j||qWdS)Nr)r.rrr"rArF addFailureZaddError)rrrtestr!rrr_feedErrorsToResult(s zTestCase._feedErrorsToResultc CsDy |j}Wn*tk r4tjdt|j|Yn X|||dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)addExpectedFailurer[rUrVrr)rrr!rrrr_addExpectedFailure2s zTestCase._addExpectedFailurecCshy |j}WnPtk rZtjdty tdWn$tk rT|j|tjYnXYn X||dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure) addUnexpectedSuccessr[rUrVrrrr r!)rrrrrr_addUnexpectedSuccess<s  zTestCase._addUnexpectedSuccessNc (Cs|}|dkr.|j}t|dd}|dk r.||j|t||j}t|jdds^t|ddrz,t|jddpxt|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|| | qLW|j|| j| j r|r| jr|j|| jn |j|n |j||S|j||dkrt|d d} | dk r| | jjd| _d|_XdS) N startTestRunr2Fr3r:T)r# stopTestRun)rrrZ startTestrrrZstopTestrrr%rrrr doCleanupsrrrrrrrclear) rrZ orig_resultrrZskip_whyZexpecting_failure_methodZexpecting_failure_classroutcomerr,rrrrrunKsh               z TestCase.runc CsN|jp t}x:|jrF|jj\}}}|j||||WdQRXqW|jS)zNExecute all cleanup functions. Normally called for you after tearDown.N)rrrrXr%r)rrrr*r+rrrrs   zTestCase.doCleanupscOs |j||S)N)r)rr*kwdsrrr__call__szTestCase.__call__cCsJ|jt||j|jx&|jrD|jjd\}}}|||q WdS)z6Run the test without collecting errors in a TestResultrN)rrrrrrrX)rrr*r+rrrdebugs zTestCase.debugcCs t|dS)zSkip this test.N)r )rr,rrrskipTestszTestCase.skipTestcCs|j|dS)z)Fail immediately, with the given message.N)rF)rrErrrfailsz TestCase.failcCs&|r"|j|dt|}|j|dS)z#Check that the expression is false.z%s is not falseN)rDrrF)rexprrErrr assertFalseszTestCase.assertFalsecCs&|s"|j|dt|}|j|dS)z"Check that the expression is true.z%s is not trueN)rDrrF)rrrErrr assertTrueszTestCase.assertTruec CsP|js|p |S|dkr|Sy d||fStk rJdt|t|fSXdS)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 Os$t||}z|jd||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^r])rexpected_exceptionr*r+contextrrrrs zTestCase.assertRaisescOst||}|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)rlr])rexpected_warningr*r+rrrrrs zTestCase.assertWarnscCs t|||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.assertLogscCsFt|t|kr@|jjt|}|dk r@t|trt|||kr>dSdt|t|t|f}nF|dkrfd}||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 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. Nz specify delta or places not bothz%s == %s within %s deltarrz%s == %s within %r places)rSrrrrDrF)rrrrrErrGrrrassertNotAlmostEquals"   zTestCase.assertNotAlmostEqualc'Cs|dk rP|j}t||s.|jd|t|ft||sT|jd|t|fnd}d}y t|}Wn ttfk rd|}YnX|dkry t|}Wn ttfk rd|}YnX|dkr||krdSd|jft||}xt t ||D]} y || } Wn.tt tfk r8|d| |f7}PYnXy || } Wn.tt tfk rt|d | |f7}PYnX| | kr|d | ft| | 7}PqW||kr|dkrt |t |krdS||kr0|d |||f7}y|d |t||f7}Wn,tt tfk r,|d ||f7}YnXnh||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.rFrrrSNotImplementedError capitalizerrangemin IndexErrorr/joindifflibndiffpprintpformat splitlines_truncateMessagerDr)rZseq1Zseq2rEseq_typeZ seq_type_nameZ differingZlen1Zlen2iZitem1Zitem2rGdiffMsgrrrassertSequenceEquals               zTestCase.assertSequenceEqualcCs2|j}|dkst||kr"||S|tt|S)N)maxDiffr DIFF_OMITTED)rrwdiffZmax_diffrrrrszTestCase._truncateMessagecCs|j|||tddS)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. )rN)r r)rZlist1Zlist2rErrrr s zTestCase.assertListEqualcCs|j|||tddS)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. )rN)r r?)rZtuple1Ztuple2rErrrrs zTestCase.assertTupleEqualc Cshy|j|}Wn^tk r>}z|jd|WYdd}~Xn0tk rl}z|jd|WYdd}~XnXy|j|}Wn^tk r}z|jd|WYdd}~Xn0tk r}z|jd|WYdd}~XnX|p|sdSg}|r|jdx|D]}|jt|qW|rH|jdx|D]}|jt|q0Wdj|} |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) differencerSrr[rreprrrD) rZset1Zset2rEZ difference1r$Z difference2linesitemrGrrrr"s2        zTestCase.assertSetEqualcCs2||kr.dt|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 containerrErGrrrassertInMs zTestCase.assertIncCs2||kr.dt|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 assertNotInTs zTestCase.assertNotIncCs2||k r.dt|t|f}|j|j||dS)zDJust like self.assertTrue(a is b), but with a nicer default message.z %s is not %sN)rrrD)rexpr1expr2rErGrrrassertIs[s zTestCase.assertIscCs,||kr(dt|f}|j|j||dS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sN)rrrD)rrrrErGrrr assertIsNotbszTestCase.assertIsNotcCs~|j|td|j|td||krzdt||}ddjtjtj|jtj|j}|j ||}|j |j ||dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr) assertIsInstancerrrrrrrrrrrD)rZd1Zd2rErGr rrrrhs   zTestCase.assertDictEqualc Cstjdtg}g}xX|jD]L\}}||kr:|j|q|||kr|jdt|t|t||fqW|pt|szdSd}|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<rzrrrr>sz4TestCase.assertDictContainsSubset..z; zMismatched values: %s) rUrVrWitemsrrrrrD) rZsubsetZ dictionaryrEZmissingZ mismatchedkeyvaluerGrrrassertDictContainsSubsetts,     z!TestCase.assertDictContainsSubsetc Cst|t|}}ytj|}tj|}Wntk rHt||}YnX||krVdSt||}|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<r rrr sz-TestCase.assertCountEqual..r) rrCounterrSrrrrrDr) rrrrEZ first_seqZ second_seqZ differencesrGrrrrrassertCountEquals      zTestCase.assertCountEqualcCs|j|td|j|td||krt||jks@t||jkrN|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 stringT)keependsrz rz%s != %srN)rrr_diffThresholdrrrrrrrrrrD)rrrrEZ firstlinesZ secondlinesrGr rrrrs     zTestCase.assertMultiLineEqualcCs2||ks.dt|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 assertLessszTestCase.assertLesscCs2||ks.dt|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%rErGrrrassertLessEqualszTestCase.assertLessEqualcCs2||ks.dt|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 assertGreaterszTestCase.assertGreatercCs2||ks.dt|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%rErGrrrassertGreaterEqualszTestCase.assertGreaterEqualcCs,|dk r(dt|f}|j|j||dS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not None)rrrD)rr(rErGrrr assertIsNoneszTestCase.assertIsNonecCs"|dkrd}|j|j||dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)rrD)rr(rErGrrrassertIsNotNoneszTestCase.assertIsNotNonecCs0t||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(rrErGrrrrs zTestCase.assertIsInstancecCs0t||r,dt||f}|j|j||dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rN)r.rrrD)rr(rrErGrrrassertNotIsInstances zTestCase.assertNotIsInstancecOst|||}|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^r])rrrOr*r+rrrrr-s zTestCase.assertRaisesRegexcOst|||}|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)rlr])rrrOr*r+rrrrr.s zTestCase.assertWarnsRegexcCsVt|ttfr$|stdtj|}|j|sRd|j|f}|j||}|j |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.rbytesAssertionErrorrMrNrdrerDrF)rtextrOrErGrrr assertRegexs     zTestCase.assertRegexcCs`t|ttfrtj|}|j|}|r\d||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.rr/rMrNrdstartendrerDrF)rr1Zunexpected_regexrEmatchrGrrrassertNotRegex&s   zTestCase.assertNotRegexcsfdd}|S)Ncs tjdjjtd||S)NzPlease use {0} instead.r)rUrVr`r rW)r*r+) original_funcrrdeprecated_func6s z,TestCase._deprecate..deprecated_funcr)r7r8r)r7r _deprecate5s zTestCase._deprecateii)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 r0rFrr r#Z_classSetupFailedrrrrr classmethodrrrrrrrrrrrr&r'_subtest_msg_sentinelrrrrrrrrrrrrrDrrrrrrrrrr rrrrrrrrrrr!rr&r'r(r)r*r+rr,r-r.r2r6r9ZfailUnlessEqualZ assertEqualsZ failIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrrfs        E     !     ' c +      !               rcsjeZdZdZdfdd ZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ 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|j||_||_||_||_dS)N)superr<r _setUpFunc _tearDownFunc _testFunc _description)rZtestFuncrrZ description)rrrrTs zFunctionTestCase.__init__cCs|jdk r|jdS)N)r>)rrrrr[s zFunctionTestCase.setUpcCs|jdk r|jdS)N)r?)rrrrr_s zFunctionTestCase.tearDowncCs |jdS)N)r@)rrrrrcszFunctionTestCase.runTestcCs|jjS)N)r@r )rrrrrfszFunctionTestCase.idcCs@t||jstS|j|jko>|j|jko>|j|jko>|j|jkS)N)r.rrr>r?r@rA)rrrrrris     zFunctionTestCase.__eq__cCstt||j|j|j|jfS)N)rr/r>r?r@rA)rrrrrrszFunctionTestCase.__hash__cCsdt|j|jjfS)Nz%s (%s))rrr@r )rrrrrvs zFunctionTestCase.__str__cCsdt|j|jfS)Nz <%s tec=%s>)rrr@)rrrrrzs zFunctionTestCase.__repr__cCs2|jdk r|jS|jj}|r.|jddjp0dS)Nrr)rAr@r rr)rrrrrr~s z!FunctionTestCase.shortDescription)NNN)r r r r rrrrrrrrrr __classcell__rr)rrr<Ks r<csDeZdZfddZddZddZddZd d Zd d ZZ S) rcs(tj||_||_||_|j|_dS)N)r=r_messager"rrF)rr"rwr)rrrrs  z_SubTest.__init__cCs tddS)Nzsubtests cannot be run directly)r)rrrrrsz_SubTest.runTestcCsbg}|jtk r |jdj|j|jrTdjddt|jjD}|jdj|dj|p`dS)Nz[{}]z, css|]\}}dj||VqdS)z{}={!r}N)r`)r<krvrrrr>sz+_SubTest._subDescription..z({}) z ())rCr;rr`rrsortedr)rpartsZ params_descrrr_subDescriptions z_SubTest._subDescriptioncCsdj|jj|jS)Nz{} {})r`r"rrH)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"rH)rrrrrsz_SubTest.__str__) r r r rrrHrrrrBrr)rrrs   r)0r r r0rrIrrrMrUrr&rarrutilrrrrrZ __unittestobjectr;r  Exceptionr rrrr)r6r8r9rr;rCrKrLr^rl namedtupler}rrrrr<rrrrrsZ (  /%5 ,l:PK!Fk955loader.cpython-36.opt-1.pycnu[3 \V@sdZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z dZ ejdejZGdd d e jZd d Zd d ZddZddZddZGdddeZeZdddZe jfddZde je jfddZde je jfddZ dS) zLoading unittests.N)fnmatch)casesuiteutilTz[_a-z]\w*\.py$cs,eZdZdZfddZfddZZS) _FailedTestNcs||_tt|j|dS)N) _exceptionsuperr__init__)selfZ method_name exception) __class__'/usr/lib64/python3.6/unittest/loader.pyr sz_FailedTest.__init__cs*|jkrttj|Sfdd}|S)Ncs jdS)N)rr)r rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namer)r )r rrs  z_FailedTest.__getattr__)__name__ __module__ __qualname__rr r __classcell__rr)r rrs rcCs"d|tjf}t|t|||S)Nz#Failed to import test module: %s %s) traceback format_exc_make_failed_test ImportError)r suiteClassmessagerrr_make_failed_import_test&srcCsdtjf}t||||S)NzFailed to call load_tests: %s)rrr)rr rrrrr_make_failed_load_tests+srcCst||}||f|fS)N)r) methodnamer rrtestrrrr0s rcCs<tjt|dd}||i}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)r r rr"ZattrsZ TestClassrrr_make_skipped_test4sr'cCs*|jjdr|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r,rrr_jython_aware_splitext<s r.cseZdZdZdZeejZe j Z dZ fddZ ddZddd d Zd!d d Zd"d dZddZd#ddZddZddZddZddZd$ddZd%dd ZZS)& TestLoaderz This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r!Ncs tt|jg|_t|_dS)N)r r/r errorsset_loading_packages)r )r rrr LszTestLoader.__init__cCsHt|tjrtd|j|}| r4t|dr4dg}|jt||}|S)z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest) issubclassr TestSuite TypeErrorgetTestCaseNameshasattrrmap)r testCaseClassZ testCaseNamesZ loaded_suiterrrloadTestsFromTestCaseSs  z TestLoader.loadTestsFromTestCase)patternc Os2t|dksd|kr,tjdt|jddt|dkrRt|d}tdj|t|dkrxt|d}tdj|g}x@t|D]4}t ||}t |t rt |t jr|j|j|qWt |dd} |j|}| dk r.y | |||Stk r,} z$t|j| |j\} } |jj| | Sd} ~ XnX|S) z>Return a suite of all test cases contained in the given modulerZuse_load_testsz(use_load_tests is deprecated and ignoredNrzCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}' load_tests)lenwarningswarnDeprecationWarningpopr5formatsorteddirgetattr isinstancer%r3rr&appendr:r Exceptionrrr0) r moduler;argsZkwsZ complainttestsrobjr<e error_case error_messagerrrloadTestsFromModuleas4           zTestLoader.loadTestsFromModulecCs>|jd}d\}}|dkr|dd}xb|rydj|}t|}PWq(tk r|j}t||j\}}|s|jj||SYq(Xq(W|dd}|} x|D]} y| t | | } } Wqt k r2} z\t | dddk r|dk r|jj||St | | |jdt j f\}}|jj||SWYdd} ~ XqXqWt| tjrP|j| St| trtt| tjrt|j| St| tjrt| trt| tjr|d }| |} tt | |tjs|j| gSnt| tjr| St| r.| }t|tjr|St|tjr|j|gStd| |fn td| dS) aSReturn a suite of all test cases given a string specifier. The name may resolve either to a module, a test case class, a test method within a test case class, or a callable object which returns a TestCase or TestSuite instance. The method optionally resolves the names relative to a given module. .Nr__path__zFailed to access attribute: %sz"calling %s returned %s, not a testz$don't know how to make test from: %s)NN)splitjoin __import__rrArrr0rGrEAttributeErrorrrrrFtypes ModuleTyperPr%r3rr&r: FunctionTyperr4callabler5)r rrIpartsrNrOZ parts_copy module_nameZnext_attributerLpartparentrMZinstr!rrrloadTestsFromNamesl             zTestLoader.loadTestsFromNamecsfdd|D}j|S)zReturn a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. csg|]}j|qSr)r`).0r)rIr rr sz1TestLoader.loadTestsFromNames..)r)r namesrIZsuitesr)rIr rloadTestsFromNamesszTestLoader.loadTestsFromNamescCs@||jfdd}tt|t|}|jr<|jtj|jd|S)zLReturn a sorted sequence of method names found within testCaseClass cSs|j|ott||S)N) startswithr[rE)Zattrnamer9prefixrrr isTestMethods z1TestLoader.getTestCaseNames..isTestMethod)key)testMethodPrefixlistfilterrDsortTestMethodsUsingsort functools cmp_to_key)r r9rgZ testFnNamesrrrr6s zTestLoader.getTestCaseNamestest*.pyc CsRd}|dkr|jdk r|j}n|dkr.d}|}tjj|}|tjkrRtjjd|||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }nxy t |Wnt k rd}YnRXtj |}|j dd} ytjjtjj |j}Wntk ry |j} Wntk r8d} YnX| r| jdkr| jdk rd}x|jD]T} | r| j| rqd| j |jjdtjjd|_|j|j| |ddqdWn*|jtjkrtddntd j|dYnX|r |s|j| |_tjj|n tjj||r2t d ||sHt|j||}|j |S) a%Find and return all test modules from the specified start directory, recursing into subdirectories to find them and return all tests found within them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.) All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately. If a test package name (directory with '__init__.py') matches the pattern then the package will be checked for a 'load_tests' function. If this exists then it will be called with (loader, tests, pattern) unless the package has already had load_tests called from the same discovery invocation, in which case the package module object is not scanned for tests - this ensures that when a package uses discover to further discover child tests that infinite recursion does not happen. If load_tests exists then discovery does *not* recurse into the package, load_tests is responsible for loading all tests in the package. The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). Paths are sorted before being imported to ensure reproducible execution order even on filesystems with non-alphabetical ordering like ext3/4. FNTrz __init__.pyrQ) namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr+r,abspathsysinsertisdirisfilerUrVrmodulesrTdirname__file__rW__spec__loadersubmodule_search_locationsrRrerreplacesepextend _find_testsbuiltin_module_namesr5rB _get_directory_containing_moduleremoverjr) r start_dirr;Z top_level_dirZset_implicit_topZis_not_importable is_namespacerKZ the_moduleZtop_partspecr,rrrdiscoversv               zTestLoader.discovercCsRtj|}tjj|j}tjj|jjdrBtjj tjj |Stjj |SdS)Nz __init__.py) rtrxr+r,rsrzbasenamer)rery)r r]rI full_pathrrrrXs  z+TestLoader._get_directory_containing_modulecCsB||jkrdSttjj|}tjj||j}|jtjjd}|S)NrQ)rrr.r+r,normpathrelpathr~r)r r,Z_relpathrrrr_get_name_from_pathds  zTestLoader._get_name_from_pathcCst|tj|S)N)rVrtrx)r rrrr_get_module_from_namepsz TestLoader._get_module_from_namecCs t||S)N)r)r r,rr;rrr _match_pathtszTestLoader._match_pathFc cs|j|}|dkrD||jkrD|j|||\}}|dk r<|V|sDdSttj|}x||D]t}tjj||} |j| ||\}}|dk r|V|rX|j| }|jj|z|j | ||EdHWd|jj |XqXWdS)z/Used by discovery. Yields test suites it loads.rQN) rr2_find_test_pathrCr+listdirr,rUaddrdiscard) r rr;rqrrKZshould_recursepathsr,rrrrrxs*    zTestLoader._find_testscCsPtjj|}tjj|rFtj|s(d S|j|||s:d S|j|}y|j|}WnXt j k r}zt |||j dfSd}~Xnt ||j \}} |jj| |dfStjjt|d|} ttjj| } ttjj|} | j| jkr0tjj| } ttjj|}tjj|}d}t||| |f|j||ddfSntjj|rH| rztjjtjj|d rzd Sd}d}|j|}y|j|}WnZt j k r}zt |||j dfSd}~Xnzt ||j \}} |jj| |dfSt|dd}|jj|z(|j||d}|dk r0|dfS|dfS|jj|Xnd SdS) zUsed by discovery. Loads tests from a single file, or a directories' __init__.py when passed the directory. Returns a tuple (None_or_tests_from_file, should_recurse). NFrzzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?)r;z __init__.pyr<T)NF)NF)NF)NF)r+r,rrwVALID_MODULE_NAMEmatchrrrrZSkipTestr'rrr0rGrsrEr.realpathr)ryrrPrvrUr2rr)r rr;rqrrrIrMrNrOZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr<rKpackagerrrrsl           zTestLoader._find_test_path)N)N)rpN)F)F)rrr__doc__ri staticmethodr three_way_cmprlrr4rrrr r:rPr`rdr6rrrrrrrrrr)r rr/Bs$  ( N  n   "r/cCs t}||_||_|r||_|S)N)r/rlrir)rf sortUsingrr|rrr _makeLoaders rcCst||j|S)N)rr6)r9rfrrrrr6sr6r!cCst|||j|S)N)rr:)r9rfrrrrr makeSuites rcCst|||j|S)N)rrP)rIrfrrrrr findTestCasess r)N)!rr+rertrrXrnr>rrrrZ __unittestcompile IGNORECASErr&rrrrr'r.objectr/ZdefaultTestLoaderrrr6r4rrrrrrs8 ' PK!bC+C+loader.cpython-36.opt-2.pycnu[3 \V@sddlZddlZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z dZ ej dejZGddde jZd d Zd d Zd dZddZddZGdddeZeZdddZe jfddZde je jfddZde je jfddZdS)N)fnmatch)casesuiteutilTz[_a-z]\w*\.py$cs,eZdZdZfddZfddZZS) _FailedTestNcs||_tt|j|dS)N) _exceptionsuperr__init__)selfZ method_name exception) __class__'/usr/lib64/python3.6/unittest/loader.pyr sz_FailedTest.__init__cs*|jkrttj|Sfdd}|S)Ncs jdS)N)rr)r rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namer)r )r rrs  z_FailedTest.__getattr__)__name__ __module__ __qualname__rr r __classcell__rr)r rrs rcCs"d|tjf}t|t|||S)Nz#Failed to import test module: %s %s) traceback format_exc_make_failed_test ImportError)r suiteClassmessagerrr_make_failed_import_test&srcCsdtjf}t||||S)NzFailed to call load_tests: %s)rrr)rr rrrrr_make_failed_load_tests+srcCst||}||f|fS)N)r) methodnamer rrtestrrrr0s rcCs<tjt|dd}||i}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)r r rr"ZattrsZ TestClassrrr_make_skipped_test4sr'cCs*|jjdr|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r,rrr_jython_aware_splitext<s r.cseZdZdZeejZej Z dZ fddZ ddZ dddd Zd d d Zd!d d ZddZd"ddZddZddZddZddZd#ddZd$ddZZS)% TestLoaderr!Ncs tt|jg|_t|_dS)N)r r/r errorsset_loading_packages)r )r rrr LszTestLoader.__init__cCsHt|tjrtd|j|}| r4t|dr4dg}|jt||}|S)NzYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest) issubclassr TestSuite TypeErrorgetTestCaseNameshasattrrmap)r testCaseClassZ testCaseNamesZ loaded_suiterrrloadTestsFromTestCaseSs  z TestLoader.loadTestsFromTestCase)patternc Os2t|dksd|kr,tjdt|jddt|dkrRt|d}tdj|t|dkrxt|d}tdj|g}x@t|D]4}t ||}t |t rt |t jr|j|j|qWt |dd} |j|}| dk r.y | |||Stk r,} z$t|j| |j\} } |jj| | Sd} ~ XnX|S)NrZuse_load_testsz(use_load_tests is deprecated and ignoredrzCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}' load_tests)lenwarningswarnDeprecationWarningpopr5formatsorteddirgetattr isinstancer%r3rr&appendr:r Exceptionrrr0) r moduler;argsZkwsZ complainttestsrobjr<e error_case error_messagerrrloadTestsFromModuleas4           zTestLoader.loadTestsFromModulecCs>|jd}d\}}|dkr|dd}xb|rydj|}t|}PWq(tk r|j}t||j\}}|s|jj||SYq(Xq(W|dd}|} x|D]} y| t | | } } Wqt k r2} z\t | dddk r|dk r|jj||St | | |jdt j f\}}|jj||SWYdd} ~ XqXqWt| tjrP|j| St| trtt| tjrt|j| St| tjrt| trt| tjr|d}| |} tt | |tjs|j| gSnt| tjr| St| r.| }t|tjr|St|tjr|j|gStd| |fn td| dS) N.r__path__zFailed to access attribute: %sz"calling %s returned %s, not a testz$don't know how to make test from: %s)NN)splitjoin __import__rrArrr0rGrEAttributeErrorrrrrFtypes ModuleTyperPr%r3rr&r: FunctionTyperr4callabler5)r rrIpartsrNrOZ parts_copy module_nameZnext_attributerLpartparentrMZinstr!rrrloadTestsFromNamesl             zTestLoader.loadTestsFromNamecsfdd|D}j|S)Ncsg|]}j|qSr)r`).0r)rIr rr sz1TestLoader.loadTestsFromNames..)r)r namesrIZsuitesr)rIr rloadTestsFromNamesszTestLoader.loadTestsFromNamescCs@||jfdd}tt|t|}|jr<|jtj|jd|S)NcSs|j|ott||S)N) startswithr[rE)Zattrnamer9prefixrrr isTestMethods z1TestLoader.getTestCaseNames..isTestMethod)key)testMethodPrefixlistfilterrDsortTestMethodsUsingsort functools cmp_to_key)r r9rgZ testFnNamesrrrr6s zTestLoader.getTestCaseNamestest*.pyc CsRd}|dkr|jdk r|j}n|dkr.d}|}tjj|}|tjkrRtjjd|||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }nxy t |Wnt k rd}YnRXtj |}|j dd} ytjjtjj |j}Wntk ry |j} Wntk r8d} YnX| r| jdkr| jdk rd}x|jD]T} | r| j| rqd| j |jjdtjjd|_|j|j| |ddqdWn*|jtjkrtddntdj|dYnX|r |s|j| |_tjj|n tjj||r2t d ||sHt|j||}|j |S) NFTrz __init__.pyrQ) namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr+r,abspathsysinsertisdirisfilerUrVrmodulesrTdirname__file__rW__spec__loadersubmodule_search_locationsrRrerreplacesepextend _find_testsbuiltin_module_namesr5rB _get_directory_containing_moduleremoverjr) r start_dirr;Z top_level_dirZset_implicit_topZis_not_importable is_namespacerKZ the_moduleZtop_partspecr,rrrdiscoversv               zTestLoader.discovercCsRtj|}tjj|j}tjj|jjdrBtjj tjj |Stjj |SdS)Nz __init__.py) rtrxr+r,rsrzbasenamer)rery)r r]rI full_pathrrrrXs  z+TestLoader._get_directory_containing_modulecCsB||jkrdSttjj|}tjj||j}|jtjjd}|S)NrQ)rrr.r+r,normpathrelpathr~r)r r,Z_relpathrrrr_get_name_from_pathds  zTestLoader._get_name_from_pathcCst|tj|S)N)rVrtrx)r rrrr_get_module_from_namepsz TestLoader._get_module_from_namecCs t||S)N)r)r r,rr;rrr _match_pathtszTestLoader._match_pathFc cs|j|}|dkrD||jkrD|j|||\}}|dk r<|V|sDdSttj|}x||D]t}tjj||} |j| ||\}}|dk r|V|rX|j| }|jj|z|j | ||EdHWd|jj |XqXWdS)NrQ) rr2_find_test_pathrCr+listdirr,rUaddrdiscard) r rr;rqrrKZshould_recursepathsr,rrrrrxs*    zTestLoader._find_testscCsPtjj|}tjj|rFtj|s(dS|j|||s:d S|j|}y|j|}WnXt j k r}zt |||j dfSd}~Xnt ||j \}} |jj| |dfStjjt|d|} ttjj| } ttjj|} | j| jkr0tjj| } ttjj|}tjj|}d}t||| |f|j||ddfSntjj|rH| rztjjtjj|d rzd Sd}d}|j|}y|j|}WnZt j k r}zt |||j dfSd}~Xnzt ||j \}} |jj| |dfSt|dd}|jj|z(|j||d}|dk r0|dfS|dfS|jj|Xnd SdS) NFrzzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?)r;z __init__.pyr<T)NF)NF)NF)NF)r+r,rrwVALID_MODULE_NAMEmatchrrrrZSkipTestr'rrr0rGrsrEr.realpathr)ryrrPrvrUr2rr)r rr;rqrrrIrMrNrOZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr<rKpackagerrrrsl           zTestLoader._find_test_path)N)N)rpN)F)F)rrrri staticmethodr three_way_cmprlrr4rrrr r:rPr`rdr6rrrrrrrrrr)r rr/Bs"  ( N  n   "r/cCs t}||_||_|r||_|S)N)r/rlrir)rf sortUsingrr|rrr _makeLoaders rcCst||j|S)N)rr6)r9rfrrrrr6sr6r!cCst|||j|S)N)rr:)r9rfrrrrr makeSuites rcCst|||j|S)N)rrP)rIrfrrrrr findTestCasess r)N) r+rertrrXrnr>rrrrZ __unittestcompile IGNORECASErr&rrrrr'r.objectr/ZdefaultTestLoaderrrr6r4rrrrrrs6 ' PK!,6,6loader.cpython-36.pycnu[3 \V@sdZddlZddlZddlZddlZddlZddlZddlZddlmZddl m Z m Z m Z dZ ejdejZGdd d e jZd d Zd d ZddZddZddZGdddeZeZdddZe jfddZde je jfddZde je jfddZ dS) zLoading unittests.N)fnmatch)casesuiteutilTz[_a-z]\w*\.py$cs,eZdZdZfddZfddZZS) _FailedTestNcs||_tt|j|dS)N) _exceptionsuperr__init__)selfZ method_name exception) __class__'/usr/lib64/python3.6/unittest/loader.pyr sz_FailedTest.__init__cs*|jkrttj|Sfdd}|S)Ncs jdS)N)rr)r rr testFailure!sz,_FailedTest.__getattr__..testFailure)_testMethodNamer r __getattr__)r namer)r )r rrs  z_FailedTest.__getattr__)__name__ __module__ __qualname__rr r __classcell__rr)r rrs rcCs"d|tjf}t|t|||S)Nz#Failed to import test module: %s %s) traceback format_exc_make_failed_test ImportError)r suiteClassmessagerrr_make_failed_import_test&srcCsdtjf}t||||S)NzFailed to call load_tests: %s)rrr)rr rrrrr_make_failed_load_tests+srcCst||}||f|fS)N)r) methodnamer rrtestrrrr0s rcCs<tjt|dd}||i}tdtjf|}|||fS)NcSsdS)Nr)r rrr testSkipped5sz'_make_skipped_test..testSkippedZ ModuleSkipped)rskipstrtypeTestCase)r r rr"ZattrsZ TestClassrrr_make_skipped_test4sr'cCs*|jjdr|ddStjj|dS)Nz $py.class ri)lowerendswithospathsplitext)r,rrr_jython_aware_splitext<s r.cseZdZdZdZeejZe j Z dZ fddZ ddZddd d Zd!d d Zd"d dZddZd#ddZddZddZddZddZd$ddZd%dd ZZS)& TestLoaderz This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite r!Ncs tt|jg|_t|_dS)N)r r/r errorsset_loading_packages)r )r rrr LszTestLoader.__init__cCsHt|tjrtd|j|}| r4t|dr4dg}|jt||}|S)z;Return a suite of all test cases contained in testCaseClasszYTest cases should not be derived from TestSuite. Maybe you meant to derive from TestCase?ZrunTest) issubclassr TestSuite TypeErrorgetTestCaseNameshasattrrmap)r testCaseClassZ testCaseNamesZ loaded_suiterrrloadTestsFromTestCaseSs  z TestLoader.loadTestsFromTestCase)patternc Os2t|dksd|kr,tjdt|jddt|dkrRt|d}tdj|t|dkrxt|d}tdj|g}x@t|D]4}t ||}t |t rt |t jr|j|j|qWt |dd} |j|}| dk r.y | |||Stk r,} z$t|j| |j\} } |jj| | Sd} ~ XnX|S) z>Return a suite of all test cases contained in the given modulerZuse_load_testsz(use_load_tests is deprecated and ignoredNrzCloadTestsFromModule() takes 1 positional argument but {} were givenz=loadTestsFromModule() got an unexpected keyword argument '{}' load_tests)lenwarningswarnDeprecationWarningpopr5formatsorteddirgetattr isinstancer%r3rr&appendr:r Exceptionrrr0) r moduler;argsZkwsZ complainttestsrobjr<e error_case error_messagerrrloadTestsFromModuleas4           zTestLoader.loadTestsFromModulecCs>|jd}d\}}|dkr|dd}xb|rydj|}t|}PWq(tk r|j}t||j\}}|s|jj||SYq(Xq(W|dd}|} x|D]} y| t | | } } Wqt k r2} z\t | dddk r|dk r|jj||St | | |jdt j f\}}|jj||SWYdd} ~ XqXqWt| tjrP|j| St| trtt| tjrt|j| St| tjrt| trt| tjr|d }| |} tt | |tjs|j| gSnt| tjr| St| r.| }t|tjr|St|tjr|j|gStd| |fn td| dS) aSReturn a suite of all test cases given a string specifier. The name may resolve either to a module, a test case class, a test method within a test case class, or a callable object which returns a TestCase or TestSuite instance. The method optionally resolves the names relative to a given module. .Nr__path__zFailed to access attribute: %sz"calling %s returned %s, not a testz$don't know how to make test from: %s)NN)splitjoin __import__rrArrr0rGrEAttributeErrorrrrrFtypes ModuleTyperPr%r3rr&r: FunctionTyperr4callabler5)r rrIpartsrNrOZ parts_copy module_nameZnext_attributerLpartparentrMZinstr!rrrloadTestsFromNamesl             zTestLoader.loadTestsFromNamecsfdd|D}j|S)zReturn a suite of all test cases found using the given sequence of string specifiers. See 'loadTestsFromName()'. csg|]}j|qSr)r`).0r)rIr rr sz1TestLoader.loadTestsFromNames..)r)r namesrIZsuitesr)rIr rloadTestsFromNamesszTestLoader.loadTestsFromNamescCs@||jfdd}tt|t|}|jr<|jtj|jd|S)zLReturn a sorted sequence of method names found within testCaseClass cSs|j|ott||S)N) startswithr[rE)Zattrnamer9prefixrrr isTestMethods z1TestLoader.getTestCaseNames..isTestMethod)key)testMethodPrefixlistfilterrDsortTestMethodsUsingsort functools cmp_to_key)r r9rgZ testFnNamesrrrr6s zTestLoader.getTestCaseNamestest*.pyc CsRd}|dkr|jdk r|j}n|dkr.d}|}tjj|}|tjkrRtjjd|||_d}d}g}tjjtjj|rtjj|}||krtjjtjj|d }nxy t |Wnt k rd}YnRXtj |}|j dd} ytjjtjj |j}Wntk ry |j} Wntk r8d} YnX| r| jdkr| jdk rd}x|jD]T} | r| j| rqd| j |jjdtjjd|_|j|j| |ddqdWn*|jtjkrtddntd j|dYnX|r |s|j| |_tjj|n tjj||r2t d ||sHt|j||}|j |S) a%Find and return all test modules from the specified start directory, recursing into subdirectories to find them and return all tests found within them. Only test files that match the pattern will be loaded. (Using shell style pattern matching.) All test modules must be importable from the top level of the project. If the start directory is not the top level directory then the top level directory must be specified separately. If a test package name (directory with '__init__.py') matches the pattern then the package will be checked for a 'load_tests' function. If this exists then it will be called with (loader, tests, pattern) unless the package has already had load_tests called from the same discovery invocation, in which case the package module object is not scanned for tests - this ensures that when a package uses discover to further discover child tests that infinite recursion does not happen. If load_tests exists then discovery does *not* recurse into the package, load_tests is responsible for loading all tests in the package. The pattern is deliberately not stored as a loader attribute so that packages can continue discovery themselves. top_level_dir is stored so load_tests does not need to pass this argument in to loader.discover(). Paths are sorted before being imported to ensure reproducible execution order even on filesystems with non-alphabetical ordering like ext3/4. FNTrz __init__.pyrQ) namespacez2Can not use builtin modules as dotted module namesz$don't know how to discover from {!r}z%Start directory is not importable: %r)!_top_level_dirr+r,abspathsysinsertisdirisfilerUrVrmodulesrTdirname__file__rW__spec__loadersubmodule_search_locationsrRrerreplacesepextend _find_testsbuiltin_module_namesr5rB _get_directory_containing_moduleremoverjr) r start_dirr;Z top_level_dirZset_implicit_topZis_not_importable is_namespacerKZ the_moduleZtop_partspecr,rrrdiscoversv               zTestLoader.discovercCsRtj|}tjj|j}tjj|jjdrBtjj tjj |Stjj |SdS)Nz __init__.py) rtrxr+r,rsrzbasenamer)rery)r r]rI full_pathrrrrXs  z+TestLoader._get_directory_containing_modulecCsl||jkrdSttjj|}tjj||j}tjj| sDtd|jd sXtd|j tjj d}|S)NrQzPath must be within the projectz..) rrr.r+r,normpathrelpathisabsAssertionErrorrer~r)r r,Z_relpathrrrr_get_name_from_pathds zTestLoader._get_name_from_pathcCst|tj|S)N)rVrtrx)r rrrr_get_module_from_namepsz TestLoader._get_module_from_namecCs t||S)N)r)r r,rr;rrr _match_pathtszTestLoader._match_pathFc cs|j|}|dkrD||jkrD|j|||\}}|dk r<|V|sDdSttj|}x||D]t}tjj||} |j| ||\}}|dk r|V|rX|j| }|jj|z|j | ||EdHWd|jj |XqXWdS)z/Used by discovery. Yields test suites it loads.rQN) rr2_find_test_pathrCr+listdirr,rUaddrdiscard) r rr;rqrrKZshould_recursepathsr,rrrrrxs*    zTestLoader._find_testscCsPtjj|}tjj|rFtj|s(d S|j|||s:d S|j|}y|j|}WnXt j k r}zt |||j dfSd}~Xnt ||j \}} |jj| |dfStjjt|d|} ttjj| } ttjj|} | j| jkr0tjj| } ttjj|}tjj|}d}t||| |f|j||ddfSntjj|rH| rztjjtjj|d rzd Sd}d}|j|}y|j|}WnZt j k r}zt |||j dfSd}~Xnzt ||j \}} |jj| |dfSt|dd}|jj|z(|j||d}|dk r0|dfS|dfS|jj|Xnd SdS) zUsed by discovery. Loads tests from a single file, or a directories' __init__.py when passed the directory. Returns a tuple (None_or_tests_from_file, should_recurse). NFrzzW%r module incorrectly imported from %r. Expected %r. Is this module globally installed?)r;z __init__.pyr<T)NF)NF)NF)NF)r+r,rrwVALID_MODULE_NAMEmatchrrrrZSkipTestr'rrr0rGrsrEr.realpathr)ryrrPrvrUr2rr)r rr;rqrrrIrMrNrOZmod_filerZfullpath_noextZ module_dirZmod_nameZ expected_dirmsgr<rKpackagerrrrsl           zTestLoader._find_test_path)N)N)rpN)F)F)rrr__doc__ri staticmethodr three_way_cmprlrr4rrrr r:rPr`rdr6rrrrrrrrrr)r rr/Bs$  ( N  n   "r/cCs t}||_||_|r||_|S)N)r/rlrir)rf sortUsingrr|rrr _makeLoaders rcCst||j|S)N)rr6)r9rfrrrrr6sr6r!cCst|||j|S)N)rr:)r9rfrrrrr makeSuites rcCst|||j|S)N)rrP)rIrfrrrrr findTestCasess r)N)!rr+rertrrXrnr>rrrrZ __unittestcompile IGNORECASErr&rrrrr'r.objectr/ZdefaultTestLoaderrrr6r4rrrrrrs8 ' PK!vffmain.cpython-36.opt-1.pycnu[3 \8)@sldZddlZddlZddlZddlmZmZddlmZdZ dZ dZ d d Z d d Z Gd ddeZeZdS)zUnittest main programN)loaderrunner)installHandlerTaExamples: %(prog)s test_module - run tests from test_module %(prog)s module.TestClass - run tests from module.TestClass %(prog)s module.Class.test_method - run specified test method %(prog)s path/to/test_file.py - run tests from test_file.py aFExamples: %(prog)s - run default set of tests %(prog)s MyTestSuite - run suite 'MyTestSuite' %(prog)s MyTestCase.testSomething - run MyTestCase.testSomething %(prog)s MyTestCase - run all 'test*' test methods in MyTestCase cCsxtjj|rt|jjdrttjj|rXtjj|tj}tjj|sP|jtj rT|S|}|ddj ddj ddS|S)Nz.py\./) ospathisfilelowerendswithisabsrelpathgetcwd startswithpardirreplace)nameZrel_pathr%/usr/lib64/python3.6/unittest/main.py _convert_names rcCsdd|DS)NcSsg|] }t|qSr)r).0rrrr .sz"_convert_names..r)namesrrr_convert_names-src @seZdZdZdZdZdZZZZ Z dZ dddde j ddddddf dddd Zdd d Zd d ZddZddZddZddZddZddZdddZddZdS) TestProgramzA command-line program that runs a set of tests; this is primarily for making test modules conveniently executable. Nr__main__TF) tb_localsc Cst|tr@t||_x0|jdddD]} t|j| |_q(Wn||_|dkrTtj}||_||_ | |_ ||_ | |_ | |_ | dkrtj rd|_n| |_||_||_||_tjj|d|_|j||jdS)Nrrdefaultr) isinstancestr __import__modulesplitgetattrsysargvexitfailfast catchbreak verbositybufferr warnoptionswarnings defaultTest testRunner testLoaderr r basenameprogName parseArgsrunTests)selfr%r1r)r2r3r*r-r+r,r.r0r partrrr__init__;s,   zTestProgram.__init__cCs4|r t||jdkr|j|jtjddS)N)print_discovery_parser_initArgParsers _print_helpr(r*)r8msgrrr usageExitas  zTestProgram.usageExitcOsZ|jdkr6t|jjttd|ji|jjn t|jjttd|jidS)Nprog) r%r< _main_parserZ format_help MAIN_EXAMPLESr5r= print_helpMODULE_EXAMPLES)r8argskwargsrrrr?is   zTestProgram._print_helpcCs|j|jdkrpt|dkrD|djdkrD|j|dddS|jj|dd||js|jgdSn|jj|dd||jrt|j|_ t dkrd|_n6|j dkrd|_ n$t |j t r|j f|_ n t|j |_ |jdS)Nrdiscoverr;r)r>r%lenr _do_discoveryrC parse_argstestsr testNames__name__r1r"r#list createTests)r8r)rrrr6rs(       zTestProgram.parseArgscCs4|jdkr|jj|j|_n|jj|j|j|_dS)N)rNr3ZloadTestsFromModuler%testZloadTestsFromNames)r8rrrrQs  zTestProgram.createTestscCs$|j}|j||_|j||_dS)N)_getParentArgParser_getMainArgParserrC_getDiscoveryArgParserr=)r8Z parent_parserrrrr>s zTestProgram._initArgParserscCstjdd}|jddddddd |jd d ddd d d |jddddd|jdkrn|jddddddd|_|jdkr|jddddddd|_|jdkr|jddddddd|_|S)NF)Zadd_helpz-vz --verboser-Z store_constr;zVerbose output)destactionZconsthelpz-qz--quietrz Quiet outputz--localsr store_truez"Show local variables in tracebacks)rVrWrXz-fz --failfastr+zStop on first fail or errorz-cz--catchr,z'Catch Ctrl-C and display results so farz-bz--bufferr.z%Buffer stdout and stderr during tests)argparseArgumentParser add_argumentr+r,r.)r8parserrrrrSs4         zTestProgram._getParentArgParsercCs2tj|gd}|j|_|j|_|jdddd|S)N)parentsrM*z?a list of any number of test modules, classes and test methods.)nargsrX)rZr[r5rBr?rEr\)r8parentr]rrrrTs zTestProgram._getMainArgParsercCs~tj|gd}d|j|_d|_|jddddd|jd d d d d|jd ddddx"dD]}|j|dtjtjdq\W|S)N)r^z %s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directorystartz*Directory to start discovery ('.' default))rVrXz-pz --patternpatternz+Pattern to match tests ('test*.py' default)z-tz--top-level-directorytopzrLr3rIrR)r8r)LoaderrrrrrKs zTestProgram._do_discoverycCs|jr t|jdkrtj|_t|jtryVy"|j|j|j|j |j |j d}Wn.t k r||j|j|j|j |j d}YnXWqt k r|j}YqXn|j}|j |j|_|jrtj|jj dS)N)r-r+r.r0r )r-r+r.r0)r,rr2rZTextTestRunnerr"typer-r+r.r0r TypeErrorZrunrRresultr*r(Z wasSuccessful)r8r2rrrr7s.  zTestProgram.runTests)N)N)rO __module__ __qualname____doc__r%r-r+r,r.r5r0r=rZdefaultTestLoaderr:rAr?r6rQr>rSrTrUrKr7rrrrr1s&#    r)rmr(rZr rrZsignalsrZ __unittestrDrFrrobjectrmainrrrrs  TPK!egmain.cpython-36.opt-2.pycnu[3 \8)@shddlZddlZddlZddlmZmZddlmZdZdZ dZ dd Z d d Z Gd d d e ZeZdS)N)loaderrunner)installHandlerTaExamples: %(prog)s test_module - run tests from test_module %(prog)s module.TestClass - run tests from module.TestClass %(prog)s module.Class.test_method - run specified test method %(prog)s path/to/test_file.py - run tests from test_file.py aFExamples: %(prog)s - run default set of tests %(prog)s MyTestSuite - run suite 'MyTestSuite' %(prog)s MyTestCase.testSomething - run MyTestCase.testSomething %(prog)s MyTestCase - run all 'test*' test methods in MyTestCase cCsxtjj|rt|jjdrttjj|rXtjj|tj}tjj|sP|jtj rT|S|}|ddj ddj ddS|S)Nz.py\./) ospathisfilelowerendswithisabsrelpathgetcwd startswithpardirreplace)nameZrel_pathr%/usr/lib64/python3.6/unittest/main.py _convert_names rcCsdd|DS)NcSsg|] }t|qSr)r).0rrrr .sz"_convert_names..r)namesrrr_convert_names-src @seZdZdZdZdZZZZZ dZ dddde j ddddddf ddddZ dd d Zd d Zd dZddZddZddZddZddZdddZddZdS) TestProgramNr__main__TF) tb_localsc Cst|tr@t||_x0|jdddD]} t|j| |_q(Wn||_|dkrTtj}||_||_ | |_ ||_ | |_ | |_ | dkrtj rd|_n| |_||_||_||_tjj|d|_|j||jdS)Nrrdefaultr) isinstancestr __import__modulesplitgetattrsysargvexitfailfast catchbreak verbositybufferr warnoptionswarnings defaultTest testRunner testLoaderr r basenameprogName parseArgsrunTests)selfr%r1r)r2r3r*r-r+r,r.r0r partrrr__init__;s,   zTestProgram.__init__cCs4|r t||jdkr|j|jtjddS)N)print_discovery_parser_initArgParsers _print_helpr(r*)r8msgrrr usageExitas  zTestProgram.usageExitcOsZ|jdkr6t|jjttd|ji|jjn t|jjttd|jidS)Nprog) r%r< _main_parserZ format_help MAIN_EXAMPLESr5r= print_helpMODULE_EXAMPLES)r8argskwargsrrrr?is   zTestProgram._print_helpcCs|j|jdkrpt|dkrD|djdkrD|j|dddS|jj|dd||js|jgdSn|jj|dd||jrt|j|_ t dkrd|_n6|j dkrd|_ n$t |j t r|j f|_ n t|j |_ |jdS)Nrdiscoverr;r)r>r%lenr _do_discoveryrC parse_argstestsr testNames__name__r1r"r#list createTests)r8r)rrrr6rs(       zTestProgram.parseArgscCs4|jdkr|jj|j|_n|jj|j|j|_dS)N)rNr3ZloadTestsFromModuler%testZloadTestsFromNames)r8rrrrQs  zTestProgram.createTestscCs$|j}|j||_|j||_dS)N)_getParentArgParser_getMainArgParserrC_getDiscoveryArgParserr=)r8Z parent_parserrrrr>s zTestProgram._initArgParserscCstjdd}|jddddddd |jd d ddd d d |jddddd|jdkrn|jddddddd|_|jdkr|jddddddd|_|jdkr|jddddddd|_|S)NF)Zadd_helpz-vz --verboser-Z store_constr;zVerbose output)destactionZconsthelpz-qz--quietrz Quiet outputz--localsr store_truez"Show local variables in tracebacks)rVrWrXz-fz --failfastr+zStop on first fail or errorz-cz--catchr,z'Catch Ctrl-C and display results so farz-bz--bufferr.z%Buffer stdout and stderr during tests)argparseArgumentParser add_argumentr+r,r.)r8parserrrrrSs4         zTestProgram._getParentArgParsercCs2tj|gd}|j|_|j|_|jdddd|S)N)parentsrM*z?a list of any number of test modules, classes and test methods.)nargsrX)rZr[r5rBr?rEr\)r8parentr]rrrrTs zTestProgram._getMainArgParsercCs~tj|gd}d|j|_d|_|jddddd|jd d d d d|jd ddddx"dD]}|j|dtjtjdq\W|S)N)r^z %s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directorystartz*Directory to start discovery ('.' default))rVrXz-pz --patternpatternz+Pattern to match tests ('test*.py' default)z-tz--top-level-directorytopzrLr3rIrR)r8r)LoaderrrrrrKs zTestProgram._do_discoverycCs|jr t|jdkrtj|_t|jtryVy"|j|j|j|j |j |j d}Wn.t k r||j|j|j|j |j d}YnXWqt k r|j}YqXn|j}|j |j|_|jrtj|jj dS)N)r-r+r.r0r )r-r+r.r0)r,rr2rZTextTestRunnerr"typer-r+r.r0r TypeErrorZrunrRresultr*r(Z wasSuccessful)r8r2rrrr7s.  zTestProgram.runTests)N)N)rO __module__ __qualname__r%r-r+r,r.r5r0r=rZdefaultTestLoaderr:rAr?r6rQr>rSrTrUrKr7rrrrr1s$#    r)r(rZr rrZsignalsrZ __unittestrDrFrrobjectrmainrrrrs  TPK!vffmain.cpython-36.pycnu[3 \8)@sldZddlZddlZddlZddlmZmZddlmZdZ dZ dZ d d Z d d Z Gd ddeZeZdS)zUnittest main programN)loaderrunner)installHandlerTaExamples: %(prog)s test_module - run tests from test_module %(prog)s module.TestClass - run tests from module.TestClass %(prog)s module.Class.test_method - run specified test method %(prog)s path/to/test_file.py - run tests from test_file.py aFExamples: %(prog)s - run default set of tests %(prog)s MyTestSuite - run suite 'MyTestSuite' %(prog)s MyTestCase.testSomething - run MyTestCase.testSomething %(prog)s MyTestCase - run all 'test*' test methods in MyTestCase cCsxtjj|rt|jjdrttjj|rXtjj|tj}tjj|sP|jtj rT|S|}|ddj ddj ddS|S)Nz.py\./) ospathisfilelowerendswithisabsrelpathgetcwd startswithpardirreplace)nameZrel_pathr%/usr/lib64/python3.6/unittest/main.py _convert_names rcCsdd|DS)NcSsg|] }t|qSr)r).0rrrr .sz"_convert_names..r)namesrrr_convert_names-src @seZdZdZdZdZdZZZZ Z dZ dddde j ddddddf dddd Zdd d Zd d ZddZddZddZddZddZddZdddZddZdS) TestProgramzA command-line program that runs a set of tests; this is primarily for making test modules conveniently executable. Nr__main__TF) tb_localsc Cst|tr@t||_x0|jdddD]} t|j| |_q(Wn||_|dkrTtj}||_||_ | |_ ||_ | |_ | |_ | dkrtj rd|_n| |_||_||_||_tjj|d|_|j||jdS)Nrrdefaultr) isinstancestr __import__modulesplitgetattrsysargvexitfailfast catchbreak verbositybufferr warnoptionswarnings defaultTest testRunner testLoaderr r basenameprogName parseArgsrunTests)selfr%r1r)r2r3r*r-r+r,r.r0r partrrr__init__;s,   zTestProgram.__init__cCs4|r t||jdkr|j|jtjddS)N)print_discovery_parser_initArgParsers _print_helpr(r*)r8msgrrr usageExitas  zTestProgram.usageExitcOsZ|jdkr6t|jjttd|ji|jjn t|jjttd|jidS)Nprog) r%r< _main_parserZ format_help MAIN_EXAMPLESr5r= print_helpMODULE_EXAMPLES)r8argskwargsrrrr?is   zTestProgram._print_helpcCs|j|jdkrpt|dkrD|djdkrD|j|dddS|jj|dd||js|jgdSn|jj|dd||jrt|j|_ t dkrd|_n6|j dkrd|_ n$t |j t r|j f|_ n t|j |_ |jdS)Nrdiscoverr;r)r>r%lenr _do_discoveryrC parse_argstestsr testNames__name__r1r"r#list createTests)r8r)rrrr6rs(       zTestProgram.parseArgscCs4|jdkr|jj|j|_n|jj|j|j|_dS)N)rNr3ZloadTestsFromModuler%testZloadTestsFromNames)r8rrrrQs  zTestProgram.createTestscCs$|j}|j||_|j||_dS)N)_getParentArgParser_getMainArgParserrC_getDiscoveryArgParserr=)r8Z parent_parserrrrr>s zTestProgram._initArgParserscCstjdd}|jddddddd |jd d ddd d d |jddddd|jdkrn|jddddddd|_|jdkr|jddddddd|_|jdkr|jddddddd|_|S)NF)Zadd_helpz-vz --verboser-Z store_constr;zVerbose output)destactionZconsthelpz-qz--quietrz Quiet outputz--localsr store_truez"Show local variables in tracebacks)rVrWrXz-fz --failfastr+zStop on first fail or errorz-cz--catchr,z'Catch Ctrl-C and display results so farz-bz--bufferr.z%Buffer stdout and stderr during tests)argparseArgumentParser add_argumentr+r,r.)r8parserrrrrSs4         zTestProgram._getParentArgParsercCs2tj|gd}|j|_|j|_|jdddd|S)N)parentsrM*z?a list of any number of test modules, classes and test methods.)nargsrX)rZr[r5rBr?rEr\)r8parentr]rrrrTs zTestProgram._getMainArgParsercCs~tj|gd}d|j|_d|_|jddddd|jd d d d d|jd ddddx"dD]}|j|dtjtjdq\W|S)N)r^z %s discoverzcFor test discovery all test modules must be importable from the top level directory of the project.z-sz--start-directorystartz*Directory to start discovery ('.' default))rVrXz-pz --patternpatternz+Pattern to match tests ('test*.py' default)z-tz--top-level-directorytopzrLr3rIrR)r8r)LoaderrrrrrKs zTestProgram._do_discoverycCs|jr t|jdkrtj|_t|jtryVy"|j|j|j|j |j |j d}Wn.t k r||j|j|j|j |j d}YnXWqt k r|j}YqXn|j}|j |j|_|jrtj|jj dS)N)r-r+r.r0r )r-r+r.r0)r,rr2rZTextTestRunnerr"typer-r+r.r0r TypeErrorZrunrRresultr*r(Z wasSuccessful)r8r2rrrr7s.  zTestProgram.runTests)N)N)rO __module__ __qualname____doc__r%r-r+r,r.r5r0r=rZdefaultTestLoaderr:rAr?r6rQr>rSrTrUrKr7rrrrr1s&#    r)rmr(rZr rrZsignalsrZ __unittestrDrFrrobjectrmainrrrrs  TPK!g"\\mock.cpython-36.opt-1.pycnu[3 \7@sFdZd ZddlZddlZddlZddlZddlmZddlm Z m Z dde eDZ e fZdejkrzddlZe ejjfZdZeZddZddZddZdddZdd Zd!d"Zd#d$Zd%d&Zdd'd(Zd)d*Zd+d,Z Gd-d.d.e!Z"Gd/d0d0e!Z#e#Z$e$j%Z%e$j&Z'e$j(Z)d1d2Z*d3d4d5d6d7d8d9d:hZ+d;d<Z,Gd=d>d>e-Z.d?d@Z/GdAdBdBe!Z0GdCdDdDe!Z1GdEd d e1Z2dFdGZ3GdHdIdIe1Z4GdJdde4e2Z5dKdLZ6dMdNZ7dOdPZ8GdQdRdRe!Z9dSdTZ:e%dddddfdUdVZ;ddWdXZd\d]Z?d^d_Z@e;e=_!e>e=_Ae#srjavaTcCstt|tS)N) issubclasstyper )objrrr_is_instance_mock2srcCst|tpt|tot|tS)N) isinstanceBaseExceptionsrr)rrrr _is_exception8s r cCst|tr6| r6y |j}Wntk r.dSXd}n*t|ts`y |j}Wntk r^dSX|rpt|d}n|}y|tj|fSt k rdSXdS)z Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None. NT) rr__init__AttributeError FunctionTypes__call__rinspectZ signature ValueError)funcZ as_instanceZeat_selfZsig_funcrrr_get_signature_object?s$    r(FcsDt|||dkrdS\}fdd}t|||t|_dS)Ncsj||dS)N)bind) _mock_selfargskwargs)sigrrchecksigdsz"_check_signature..checksig)r(_copy_func_detailsr_mock_check_sig)r'mock skipfirstinstancer.r)r-r_check_signature_s   r4c#Cs|j|_|j|_y |j|_Wntk r0YnXy |j|_Wntk rRYnXy |j|_Wntk rtYnXy |j|_Wntk rYnXdS)N)__name____doc____text_signature__r" __module__ __defaults____kwdefaults__)r'funcopyrrrr/js$    r/cCs&t|trdSt|dddk r"dSdS)NTr$F)rrgetattr)rrrr _callables  r=cCst|ttfkS)N)rlisttuple)rrrr_is_listsr@cCsHt|tst|dddk Sx(|f|jD]}|jjddk r(dSq(WdS)ztGiven an object, return True if the object is callable. For classes, return True if instances would be callable.r$NTF)rrr<__mro____dict__get)rbaserrr_instance_callables  rEc st|s dSt|t}t|||}|dkr.|S|\}fdd}t|||j}|js^d}||d}d|} t| |||} t| || S)Ncsj||dS)N)r))r+r,)r-rrr.sz _set_signature..checksigr;)Z _checksig_r1zYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)) r=rrr(r/r5 isidentifierexec _setup_func) r1originalr3r2resultr'r.rcontextsrcr;r)r-r_set_signatures$       rMc s_tsdSfdd}fdd}fdd}fdd}fd d }fd d }fd d}fdd} d_d_d_t_t_t_j _ j _ j _ |_ |_ |_|_| _|_|_|__dS)Ncs j||S)N)assert_called_with)r+r,)r1rrrNsz'_setup_func..assert_called_withcs j||S)N) assert_called)r+r,)r1rrrOsz"_setup_func..assert_calledcs j||S)N)assert_not_called)r+r,)r1rrrPsz&_setup_func..assert_not_calledcs j||S)N)assert_called_once)r+r,)r1rrrQsz'_setup_func..assert_called_oncecs j||S)N)assert_called_once_with)r+r,)r1rrrRsz,_setup_func..assert_called_once_withcs j||S)N)assert_has_calls)r+r,)r1rrrSsz%_setup_func..assert_has_callscs j||S)N)assert_any_call)r+r,)r1rrrTsz$_setup_func..assert_any_callcs:t_t_jj}t|r6|k r6|jdS)N) _CallList method_calls mock_calls reset_mock return_valuer)ret)r;r1rrrXs z_setup_func..reset_mockFr)r1rcalled call_count call_argsrUcall_args_listrVrWrY side_effect_mock_childrenrNrRrSrTrXrOrPrQ_mock_delegate) r;r1rNrOrPrQrRrSrTrXr)r;r1rrHs:       rHcCsd|dd|kS)Nz__%s__r)rrrr _is_magicsrdc@s eZdZdZddZddZdS)_SentinelObjectz!A unique, named, sentinel object.cCs ||_dS)N)r)selfrrrrr!sz_SentinelObject.__init__cCs d|jS)Nz sentinel.%s)r)rfrrr__repr__sz_SentinelObject.__repr__N)r5r8 __qualname__r6r!rgrrrrresrec@s eZdZdZddZddZdS) _SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs i|_dS)N) _sentinels)rfrrrr!sz_Sentinel.__init__cCs|dkr t|jj|t|S)N __bases__)r"rj setdefaultre)rfrrrr __getattr__sz_Sentinel.__getattr__N)r5r8rhr6r!rmrrrrrisricCs$t|ttttfkr t||S|S)N)rdictr>r?set)valuerrr_copys rqrY_mock_return_valuer__mock_side_effect _mock_parent_mock_new_parent _mock_name_mock_new_namecCs8tj|d|}||fdd}||fdd}t||S)NZ_mock_cSs"|j}|dkrt||St||S)N)rar<)rfr _the_namer-rrr_gets z"_delegating_property.._getcSs*|j}|dkr||j|<n t|||dS)N)rarBsetattr)rfrprrxr-rrr_set$s z"_delegating_property.._set)_allowed_namesaddproperty)rrxryr{rrr_delegating_propertys  rc@seZdZddZddZdS)rUcCsnt|tstj||St|}t|}||kr2dSx6td||dD] }||||}||krFdSqFWdS)NFrT)rr> __contains__lenrange)rfrpZ len_valueZlen_selfiZsub_listrrrr1s  z_CallList.__contains__cCstjt|S)N)pprintZpformatr>)rfrrrrg?sz_CallList.__repr__N)r5r8rhrrgrrrrrU/srUcCsxt|s dS|js,|js,|jdk s,|jdk r0dS|}x|dk rR||krJdS|j}q6W|rd||_||_|rt||_||_dS)NFT)rrvrwrtru)parentrprnew_name_parentrrr_check_and_set_parentCs$     rc@s$eZdZddZddZddZdS) _MockItercCst||_dS)N)iterr)rfrrrrr!]sz_MockIter.__init__cCs|S)Nr)rfrrr__iter___sz_MockIter.__iter__cCs t|jS)N)nextr)rfrrr__next__asz_MockIter.__next__N)r5r8rhr!rrrrrrr\src@seZdZeZdZddZdS)BaseNcOsdS)Nr)rfr+r,rrrr!gsz Base.__init__)r5r8rhrrrrsr!rrrrrdsrc @sHeZdZdZddZdDddZd d ZdEd d ZdFd dZddZ ddZ dZ e e e e Z e ddZedZedZedZedZedZddZddZe eeZdGdddd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Z d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%dd?Z'd@dAZ(dBdCZ)dS)Ir z A non-callable version of `Mock`cOs$t|j|fd|ji}tj|}|S)Nr6)rr5r6object__new__)clsr+kwnewr3rrrros zNonCallableMock.__new__NFc Ks|dkr |}|j} || d<|| d<|| d<|| d<|dk rB|}d}| dkrR|dk } |j||| | i| d<|| d<d| d<d | d <d| d <d | d <t| d<t| d<t| d<| | d<| r|jf| tt|j||||||dS)NrtrvrwruTr` _mock_wrapsraFZ _mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrV _mock_unsafe)rB_mock_add_specrUconfigure_mock _safe_superr r!)rfspecrrspec_setr _spec_state _new_name _new_parent_spec_as_instance _eat_selfZunsafer,rBrrrr!xs8      zNonCallableMock.__init__cCs(d|_d|_d|_d|_t|||dS)z Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the `method_calls` and `mock_calls` attributes of this one.Nr)rtrurvrwrz)rfr1 attributerrr attach_mocks zNonCallableMock.attach_mockcCs|j||dS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)r)rfrrrrr mock_add_specszNonCallableMock.mock_add_specc Cs|d}d}|dk rRt| rRt|tr*|}nt|}t|||}|oH|d}t|}|j}||d<||d<||d<||d<dS)Nr _spec_class _spec_set_spec_signature _mock_methods)r@rr _get_classr(dirrB) rfrrrrrrresrBrrrrs  zNonCallableMock._mock_add_speccCs8|j}|jdk r|jj}|tkr4|j|dd}||_|S)Nz())rr)rrrarYr_get_child_mock)rfrZrrrZ__get_return_values  z"NonCallableMock.__get_return_valuecCs,|jdk r||j_n||_t||dddS)Nz())rarYrrr)rfrprrrZ__set_return_values  z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdkrt|S|jS)N)rr)rfrrr __class__s zNonCallableMock.__class__r[r\r]r^rWcCsT|j}|dkr|jS|j}|dk rPt| rPt|t rPt| rPt|}||_|S)N)rarsr_callablerrr )rf delegatedZsfrrrZ__get_side_effectsz!NonCallableMock.__get_side_effectcCs(t|}|j}|dkr||_n||_dS)N) _try_iterrarsr_)rfrprrrrZ__set_side_effects z!NonCallableMock.__set_side_effect)rYr_cCs|dkr g}t||krdS|jt|d|_d|_d|_t|_t|_t|_|r^t |_ |rhd|_ x0|j j D]"}t|tst|tkrqt|j|qtW|j }t|r||k r|j|dS)z-Restore the mock object to its initial state.NFr)idappendr[r]r\rUrWr^rVrrrrsr`valuesr _SpecState_deletedrXr)rfZvisitedrYr_ZchildrZrrrrX s, zNonCallableMock.reset_mockcKs`xZt|jdddD]B\}}|jd}|j}|}x|D]}t||}q:Wt|||qWdS)aZSet attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs)cSs|djdS)Nr.)count)entryrrr8sz0NonCallableMock.configure_mock..)keyrN)sorteditemssplitpopr<rz)rfr,argvalr+finalrrrrrr+s   zNonCallableMock.configure_mockcCs|dkrt|n:|jdk r<||jks.|tkrLtd|nt|rLt||jsd|jdrdt||jj|}|tkrt|np|dkrd}|j dk rt |j |}|j |||||d}||j|<n.t |t rt|j|j|j|j|j}||j|<|S) NrrzMock object has no attribute %rassertassret)rrrrr>rr)rr)r"r _all_magicsrdrrr`rCrrr<rrrrrrr3rr)rfrrJrrrrrmAs6            zNonCallableMock.__getattr__c Cs"|jg}|j}|}d}|dgkr$d}t}xT|dk r~|}|j|j|d}|jdkrZd}|j}t||krnP|jt|q,Wtt|}|jpd}t |dkr|dd kr|d7}||d<dj |}d}|dkrd |}d} |j dk rd } |j rd } | |j j } d t|j || t|fS)Nr()rr1r().rmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr)r1r)rwrurorrr}r>reversedrvrjoinrrr5r) rfZ _name_listrZlastdotseenZ_firstrZ name_stringZ spec_stringrrrrggsL           zNonCallableMock.__repr__cCshtstj|S|jpg}tt|}t|j}dd|D}dd|D}tt |||t|j S)z8Filter the output of `dir(mock)` to only useful members.cSsg|]}|jds|qS)r)r)rerrr sz+NonCallableMock.__dir__..cSs$g|]}|jd st|r|qS)r)rrd)rrrrrrs) r r__dir__rrrr>rBrror`)rfZextrasZ from_typeZ from_dictrrrrs    zNonCallableMock.__dir__cs"|tkrtj||SjrHjdk rH|jkrH|jkrHtd|n|tkrbd|}t|n|tkrjdk r|jkrtd|t |st t |t |||fdd}n(t |d|t t |||j|<n.|dkr|_dSt |||r|j|<tj||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.csf||S)Nr)r+r)rIrfrrrsz-NonCallableMock.__setattr__..r)r|r __setattr__rrrBr"_unsupported_magicsrrrzr _get_methodrr`r)rfrrpmsgr)rIrfrrs2       zNonCallableMock.__setattr__cCs|tkr2|t|jkr2tt||||jkr2dS||jkrHtj|||jj|t}|t krft ||tk rv|j|=t |j|<dS)N) rrrBdelattrr __delattr__r`rC_missingrr")rfrrrrrrs   zNonCallableMock.__delattr__cCs|jpd}t|||S)Nr1)rv_format_call_signature)rfr+r,rrrr_format_mock_call_signatures z+NonCallableMock._format_mock_call_signaturecCsDd}|j||}|j}t|dkr.|dd}|j|}|||fS)Nz!Expected call: %s Actual call: %sr)rr]r)rfr+r,messageexpected_stringr]Z actual_stringrrr_format_mock_failure_messages    z,NonCallableMock._format_mock_failure_messagecCst|j}|dk rlt|dkr(d}|\}}n |\}}}y||j||fStk rh}z |jdSd}~XqpXn|SdS)a Given a call (or simply an (args, kwargs) tuple), return a comparison key suitable for matching with other calls. This is a best effort method which relies on the spec's signature, if available, or falls back on the arguments themselves. Nrbr)rrr) TypeErrorwith_traceback)rf_callr-rr+r,rrrr _call_matchers   zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|dS)z/assert that the mock was never called. rz7Expected '%s' to not have been called. Called %s times.r1N)r\rvAssertionError)r*rfrrrrrPs  z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|dS)z6assert that the mock was called at least once rz"Expected '%s' to have been called.r1N)r\rvr)r*rfrrrrrO s   zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|dS)z3assert that the mock was called only once. rz8Expected '%s' to have been called once. Called %s times.r1N)r\rvr)r*rfrrrrrQs  z"NonCallableMock.assert_called_oncecs||jdkr(j}td|ffdd}jf}jj}||krxt|trh|nd}t||dS)zassert that the mock was called with the specified arguments. Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.NzExpected call: %s Not calledcsj}|S)N)r)r)r+r,rfrr_error_message's z:NonCallableMock.assert_called_with.._error_message)r]rrrr Exception)r*r+r,expectedractualcauser)r+r,rfrrNs   z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t||j||S)ziassert that the mock was called exactly once and that that call was with the specified arguments.rz1Expected '%s' to be called once. Called %s times.r1)r\rvrrN)r*r+r,rfrrrrrR1s  z'NonCallableMock.assert_called_once_withc sfdd|D}t|tr |nd}tfddjD}|sd||kr`tdt|jf|dSt|}g}x:|D]2}y|j|Wqvtk r|j|YqvXqvW|rtdt |f|dS)aassert the mock has been called with the specified calls. The `mock_calls` list is checked for the calls. If `any_order` is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls. If `any_order` is True then the calls can be in any order, but they must all appear in `mock_calls`.csg|]}j|qSr)r)rc)rfrrrFsz4NonCallableMock.assert_has_calls..Nc3s|]}j|VqdS)N)r)rr)rfrr Hsz3NonCallableMock.assert_has_calls..z(Calls not found. Expected: %r Actual: %rz%r not all found in call list) rrrUrWrr>remover&rr?)rfZcallsZ any_orderrrZ all_callsZ not_foundZkallr)rfrrS<s*  z NonCallableMock.assert_has_callscsZj||f}fddjD}||krVt|tr8|nd}j||}td||dS)zassert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike `assert_called_with` and `assert_called_once_with` that only pass if the call is the most recent one.csg|]}j|qSr)r)rr)rfrrrfsz3NonCallableMock.assert_any_call..Nz%s call not found)rr^rrrr)rfr+r,rrrrr)rfrrT_s zNonCallableMock.assert_any_callcKsFt|}t|ts2t|tr"t}q.) rrrrrrrrrr,attribute_namer)rfrrrrrisz _patch.copycCst|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rfr'rrrr$vs  z_patch.__call__cCsRxLt|D]@}|jtjsq t||}t|ds2q |j}t||||q W|S)Nr$)rrr TEST_PREFIXr<rrrz)rfrattr attr_valuerrrrr|s   z_patch.decorate_classcs<tdrjj|Stfdd|g_S)N patchingscsg}g}t}zybxJjD]@}|j}|j||jdk rF|j|q|jtkr|j|qW|t|7}||S||krt|r|j|t j }YnXWdxt |D]}|j |qWXdS)N) r?r __enter__rrupdaterrrsysexc_infor__exit__)r+Zkeywargs extra_argsZentered_patchersr patchingr)r'patchedrrrs*         z)_patch.decorate_callable..patched)rrrr)rfr'r)r'rrrs   z_patch.decorate_callablec Cs|j}|j}t}d}y|j|}Wn$ttfk rHt||t}YnXd}|tkrft|t rfd|_ |j r|tkrtd||f||fS)NFTz!%s does not have the attribute %r) rrrrBr"KeyErrorr< _builtinsrrr)rfrrrIlocalrrr get_originalsz_patch.get_originalcCs>|j|j|j}}}|j|j}}|j}|j|_|dkr@d}|dkrLd}|dkrXd}|dk rp|dk rptd|dk s|dk r|dkrtd|j \}}|t ko|dkrTd} |dkr|}|dkr|}d}n&|dk r|dkr|}d}n |dkr|}|dk s |dk r,|t krtdt |t r,d} t } i} |dk rD|} nN|dk sX|dk r|} |dk rj|} t| r~d| k} n t|  } | rt} |dk r|| d<|dk r|| d <t | t rt| tr|jr|j| d <| j|| f| }| rt|r|} |dk r|} t|  r2t|  r2t} | jd | f|d d | |_nl|dk r|t k rptd |t krtdt|}|dkr|}t|f||jd|}n|rtd|}||_||_t|j|j||jdk r:i}|jt kr|||j<x.|jD]$}|j }|jt kr|j|qW|S|S)zPerform the patch.FNzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer$rrrz())rrzBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r_namez.Can't pass kwargs to a mock we aren't creating)TN)!rrrrr,rrrrrrrrrr@rr rr rr rrErrYboolr temp_originalrrzrrr )rfrrrrr,rrIrZinheritKlass_kwargsZ this_specZ not_callableZnew_attrrrrrrrr s                              z_patch.__enter__cGst|std|jr4|jtk r4t|j|j|jnBt|j|j|j rvt |j|j sd|jdkrvt|j|j|j|`|`|`x$t |j D]}t|r|j |qWdS) zUndo the patch.z stop called on unstarted patcherr6r8r9__annotations__r:N)r6r8r9rr:)r RuntimeErrorrrrrzrrrrrrrr )rfr rrrrr Hs z_patch.__exit__cCs|j}|jj||S)z-Activate a patch, returning any created mock.)r _active_patchesr)rfrJrrrstart`s z _patch.startc Cs.y|jj|Wntk r$YnX|jS)zStop an active patch.)rrr&r )rfrrrstopgs z _patch.stop)r5r8rhrrr!rr$rrrr r rrrrrrrIs (~rc sPyjdd\}Wn&ttfk r:tdfYnXfdd}||fS)Nrrz.Need a valid target to patch. You supplied: %rcstS)N)rr)rrrrysz_get_target..)rsplitrr&)rrrr)rr _get_targetss r c s$fdd} t| |||||||| S)a patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. Like `patch`, `patch.object` takes arbitrary keyword arguments for configuring the mock object it creates. When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` for choosing which methods to wrap. csS)Nrr)rrrrsz_patch_object..)r) rrrrrrrrr,rr)rr _patch_object}s  r!c sttkrfdd}n fdd}|s2tdt|j}|d\} } t|| | |||||i } | | _xB|ddD]2\} } t|| | |||||i } | | _| jj| qvW| S)aPerform multiple patches in a single call. It takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use `DEFAULT` as the value if you want `patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when `patch.multiple` is used as a context manager. `patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments `spec`, `spec_set`, `create`, `autospec` and `new_callable` have the same meaning as for `patch`. These arguments will be applied to *all* patches done by `patch.multiple`. When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX` for choosing which methods to wrap. cstS)N)rr)rrrrsz!_patch_multiple..csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerrN) rstrr&r>rrrrr) rrrrrrr,rrrrrZ this_patcherr)rr_patch_multiples&        r#c Ks$t|\}} t|| ||||||| S)a `patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the `target` is patched with a `new` object. When the function/with statement exits the patch is undone. If `new` is omitted, then the target is replaced with a `MagicMock`. If `patch` is used as a decorator and `new` is omitted, the created mock is passed in as an extra argument to the decorated function. If `patch` is used as a context manager the created mock is returned by the context manager. `target` should be a string in the form `'package.module.ClassName'`. The `target` is imported and the specified object replaced with the `new` object, so the `target` must be importable from the environment you are calling `patch` from. The target is imported when the decorated function is executed, not at decoration time. The `spec` and `spec_set` keyword arguments are passed to the `MagicMock` if patch is creating one for you. In addition you can pass `spec=True` or `spec_set=True`, which causes patch to pass in the object being mocked as the spec/spec_set object. `new_callable` allows you to specify a different class, or callable object, that will be called to create the `new` object. By default `MagicMock` is used. A more powerful form of `spec` is `autospec`. If you set `autospec=True` then the mock will be created with a spec from the object being replaced. All attributes of the mock will also have the spec of the corresponding attribute of the object being replaced. Methods and functions being mocked will have their arguments checked and will raise a `TypeError` if they are called with the wrong signature. For mocks replacing a class, their return value (the 'instance') will have the same spec as the class. Instead of `autospec=True` you can pass `autospec=some_object` to use an arbitrary object as the spec instead of the one being replaced. By default `patch` will fail to replace attributes that don't exist. If you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against attributes that your production code creates at runtime. It is off by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! Patch can be used as a `TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods share a common patchings set. `patch` finds tests by looking for method names that start with `patch.TEST_PREFIX`. By default this is `test`, which matches the way `unittest` finds tests. You can specify an alternative prefix by setting `patch.TEST_PREFIX`. Patch can be used as a context manager, with the with statement. Here the patching applies to the indented block after the with statement. If you use "as" then the patched object will be bound to the name after the "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to the `Mock` (or `new_callable`) on construction. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. )r r) rrrrrrrr,rrrrrrsE  c@sVeZdZdZfdfddZddZddZd d Zd d Zd dZ ddZ eZ e Z dS) _patch_dicta# Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test. `in_dict` can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys. `in_dict` can also be a string specifying the name of the dictionary, which will then be fetched by importing it. `values` can be a dictionary of values to set in the dictionary. `values` can also be an iterable of `(key, value)` pairs. If `clear` is True then the dictionary will be cleared before the new values are set. `patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary:: with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()): ... `patch.dict` can be used as a context manager, decorator or class decorator. When used as a class decorator `patch.dict` honours `patch.TEST_PREFIX` for choosing which methods to wrap. FcKs>t|trt|}||_t||_|jj|||_d|_dS)N) rr"rin_dictrnrr clear _original)rfr%rr&r,rrrr!0s   z_patch_dict.__init__cs.ttrjStfdd}|S)Nc s"jz ||SjXdS)N)r$ _unpatch_dict)r+r)frfrr_inner>s z$_patch_dict.__call__.._inner)rrrr)rfr)r*r)r)rfrr$;s  z_patch_dict.__call__cCs\xVt|D]J}t||}|jtjr t|dr t|j|j|j }||}t |||q W|S)Nr$) rr<rrrrr$r%rr&rz)rfrrrZ decoratorZ decoratedrrrrIs   z_patch_dict.decorate_classcCs |jdS)zPatch the dict.N)r$)rfrrrr Tsz_patch_dict.__enter__cCs|j}|j}|j}y |j}Wn2tk rPi}x|D]}||||<q8WYnX||_|rdt|y|j|Wn.tk rx|D]}||||<qWYnXdS)N)rr%r&rr"r' _clear_dictr )rfrr%r&rIrrrrr$Ys"   z_patch_dict._patch_dictc CsV|j}|j}t|y|j|Wn.tk rPx|D]}||||<q8WYnXdS)N)r%r'r+r r")rfr%rIrrrrr(ss z_patch_dict._unpatch_dictcGs |jdS)zUnpatch the dict.F)r()rfr+rrrr sz_patch_dict.__exit__N) r5r8rhr6r!r$rr r$r(r rrrrrrr$s   r$c CsBy |jWn0tk r<t|}x|D] }||=q*WYnXdS)N)r&r"r>)r%keysrrrrr+s   r+cCs xttjD] }|jq WdS)z7Stop all active patches. LIFO to unroll nested patches.N)rrrr)rrrr_patch_stopallsr-Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv ccs|]}d|VqdS)zi%sNr)rnrrrrsrccs|]}d|VqdS)zr%sNr)rr/rrrrs__get____set__ __delete__ __reversed__ __missing__ __reduce__ __reduce_ex__Z__getinitargs____getnewargs__ __getstate__ __setstate__ __getformat__ __setformat__rgr__subclasses__ __format____getnewargs_ex__csfdd}||_|S)z:Turns a callable object (like a mock) into a real functioncs|f||S)Nr)rfr+r)r'rrmethodsz_get_method..method)r5)rr'r?r)r'rrs rcCsh|] }d|qS)z__%s__r)rr?rrrrsrmrr!r __prepare____instancecheck____subclasscheck____del__cCs tj|S)N)r__hash__)rfrrrrsrcCs tj|S)N)r__str__)rfrrrrscCs tj|S)N)r __sizeof__)rfrrrrs)rDrErFry?g?) __lt____gt____le____ge____int__r__len__r  __complex__ __float____bool__ __index__csfdd}|S)Ncs$jj}|tk r|S|kr dStS)NT)__eq__rrrNotImplemented)otherret_val)rfrrrQs z_get_eq..__eq__r)rfrQr)rfr_get_eqs rUcsfdd}|S)Ncs jjtk rtS|krdStS)NF)__ne__rrrrR)rS)rfrrrVs  z_get_ne..__ne__r)rfrVr)rfr_get_nes rWcsfdd}|S)Ncs jj}|tkrtgSt|S)N)rrrrr)rT)rfrrrsz_get_iter..__iter__r)rfrr)rfr _get_iters rX)rQrVrc Cstj|t}|tk r||_dStj|}|dk rdy ||}Wntk rXt|}YnX||_dStj|}|dk r|||_dS)N)_return_valuesrCrrY_calculate_return_valuer"_side_effect_methodsr_)r1r?rZfixedZreturn_calulatorrYZ side_effectorrrr_set_return_values    r\c@seZdZddZddZdS) MagicMixincOs&|jtt|j|||jdS)N)_mock_set_magicsrr]r!)rfr+rrrrr!(szMagicMixin.__init__cCst}t|dddk rTtj|j}t}t|}x$|D]}|t|jkr4t||q4W|tt|j}t|}x|D]}t||t ||qtWdS)Nr) _magicsr< intersectionrrorrBrrz MagicProxy)rfZ these_magicsZ remove_magicsrrrrrr^.s   zMagicMixin._mock_set_magicsN)r5r8rhr!r^rrrrr]'sr]c@seZdZdZdddZdS)r z-A version of `MagicMock` that isn't callable.FcCs|j|||jdS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)rr^)rfrrrrrrGs z"NonCallableMagicMock.mock_add_specN)F)r5r8rhr6rrrrrr Esc@seZdZdZdddZdS)ra MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. If you use the `spec` or `spec_set` arguments then *only* magic methods that exist in the spec will be created. Attributes and the return value of a `MagicMock` will also be `MagicMocks`. FcCs|j|||jdS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)rr^)rfrrrrrr]s zMagicMock.mock_add_specN)F)r5r8rhr6rrrrrrRs c@s.eZdZddZddZddZd dd ZdS) racCs||_||_dS)N)rr)rfrrrrrr!iszMagicProxy.__init__cOs|j}|||S)N) create_mock)rfr+r,mrrrr$mszMagicProxy.__call__cCs8|j}|j}|j|||d}t|||t||||S)N)rrr)rrrrzr\)rfrrrcrrrrbqs  zMagicProxy.create_mockNcCs|jS)N)rb)rfrrrrrr0zszMagicProxy.__get__)N)r5r8rhr!r$rbr0rrrrrahs rac@s(eZdZdZddZddZddZdS) _ANYz2A helper object that compares equal to everything.cCsdS)NTr)rfrSrrrrQsz _ANY.__eq__cCsdS)NFr)rfrSrrrrVsz _ANY.__ne__cCsdS)Nzr)rfrrrrgsz _ANY.__repr__N)r5r8rhr6rQrVrgrrrrrdsrdcCsdd|}d}djdd|D}djddt|jD}|rD|}|r\|rT|d7}||7}||S)Nz%s(%%s)rz, cSsg|] }t|qSr)repr)rrrrrrsz*_format_call_signature..cSsg|]\}}d||fqS)z%s=%rr)rrrprrrrs)rrr)rr+r,rZformatted_argsZ args_stringZ kwargs_stringrrrrsrc@sveZdZdZfddddfddZfddddfdd Zd d ZejZd d Z ddZ ddZ ddZ ddZ ddZdS)ra A tuple for holding the results of a call to a mock, either in the form `(args, kwargs)` or `(name, args, kwargs)`. If args or kwargs are empty then a call tuple will compare equal to a tuple without those values. This makes comparisons less verbose:: _Call(('name', (), {})) == ('name',) _Call(('name', (1,), {})) == ('name', (1,)) _Call(((), {'a': 'b'})) == ({'a': 'b'},) The `_Call` object provides a useful shortcut for comparing with call:: _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) If the _Call has no name then it will match any name. rNFTc Csf}i}t|}|dkr$|\}}}nr|dkrd|\} } t| trX| }t| trR| }qb| }q| | }}n2|dkr|\}t|tr|}nt|tr|}n|}|rtj|||fStj||||fS)Nrrbr)rrr"r?r) rrprrr from_kallr+r,_lenfirstsecondrrrrs.      z _Call.__new__cCs||_||_||_dS)N)rvrt_mock_from_kall)rfrprrrrfrrrr!sz_Call.__init__c Csf|tkr dSy t|}Wntk r,dSXd}t|dkrH|\}}n |\}}}t|ddrzt|ddrz|j|jkrzdSd}|dkrfi}}n|dkr|\}}}n|dkr|\} t| tr| }i}n"t| tr| }fi}}nf}| }nV|dkr>|\} } t| tr2| }t| tr&| i}}n f| }}n | | }}ndS|rV||krVdS||f||fkS) NTFrrbrtrrr)rrrr<rtrr?r") rfrSZ len_otherZ self_nameZ self_argsZ self_kwargsZ other_nameZ other_argsZ other_kwargsrprhrirrrrQsP                z _Call.__eq__cOs<|jdkrtd||fddS|jd}t|j||f||dS)Nrz())r)rr)rvr)rfr+r,rrrrr$s  z_Call.__call__cCs2|jdkrt|ddSd|j|f}t||ddS)NF)rrfz%s.%s)rrrf)rvr)rfrrrrrrms  z_Call.__getattr__cOs|jd||S)Nr)rm)rfr+r,rrrr$sz _Call.countcOs|jd||S)Nindex)rm)rfr+r,rrrrk'sz _Call.indexcCs||js&|jpd}|jdr"d|}|St|dkr@d}|\}}n0|\}}}|sTd}n|jdshd|}nd|}t|||S)Nrz()zcall%srbzcall.%s)rjrvrrr)rfrr+r,rrrrg*s       z_Call.__repr__cCs8g}|}x"|dk r*|jr"|j||j}q Wtt|S)zFor a call object that represents multiple calls, `call_list` returns a list of all the intermediate calls as well as the final call.N)rjrrtrUr)rfvalsrrrr call_list?s   z_Call.call_list)r5r8rhr6rr!rQrrVr$rmrrkrgrmrrrrrs  7r)rfcKs,t|rt|}t|t}d|i}|r0d|i}n |dkr.rrxrxrxrx)rbytesr) read_dataZ data_as_listliner)rwr_iterate_read_data s  r|rcsfdd}fdd}fddtdkr`ddl}ttt|jjtt|ja|dkrttd t d }ttd j _ t dgdj _ dj_ dj_ dj_ |j_d <d j_|j_fd d}||_|_ |S)a A helper function to create a mock to replace the use of `open`. It works for `open` called directly or used as a context manager. The `mock` argument is the mock object to configure. If `None` (the default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. `read_data` is a string for the `read` methoddline`, and `readlines` of the file handle to return. This is an empty string by default. cs jjdk rjjStdS)Nr) readlinesrYr>)r+r,)_statehandlerr_readlines_side_effect( s z)mock_open.._readlines_side_effectcs(jjdk rjjStjdS)Nr)readrYrr)r+r,)r~rrzrr_read_side_effect- s z$mock_open.._read_side_effectc3sJjjdk rxjjVqWxdD] }|Vq&WxtVq6WdS)Nr)readlinerYr)r{)r~rrzrr_readline_side_effect2 s  z(mock_open.._readline_side_effectNropen)rr)rrcs6td<jjdkr2d<dj_tS)Nrr)r|rr_r)r+r,)rr~rrzrr reset_dataS s    zmock_open..reset_data) file_spec_ior>ror TextIOWrapperunionBytesIOrrr rYr|writerrr}r_)r1rzrrrrr)rr~rrzrr  s.  "     c@s(eZdZdZddZddZddZdS) r aW A mock intended to be used as a property, or other descriptor, on a class. `PropertyMock` provides `__get__` and `__set__` methods so you can specify a return value when it is fetched. Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. cKs tf|S)N)r)rfr,rrrri szPropertyMock._get_child_mockcCs|S)Nr)rfrZobj_typerrrr0l szPropertyMock.__get__cCs ||dS)Nr)rfrrrrrr1n szPropertyMock.__set__N)r5r8rhr6rr0r1rrrrr ` s) rrrrrrrrr r r r r )F)F)NFNNN)FFNN)Nr)o__all__ __version__r%rr builtinstypesr functoolsrrrr BaseExceptionrplatformrZlangZ Throwabler superrrr r(r4r/r=r@rErMrHrdrrerirrZMISSINGrZDELETEDrrqr|rr>rUrrrr rrrrrrrr r!r#rr$r+r-rnZmultipleZstopallrZ magic_methodsZnumericsrrZinplacerightZ _non_defaultsrr_rrrZrRrYrUrWrXr[r\r]r rrardrrr?rrrrnrrrrQr#r0rrrr|r r rrrrs     4  i5 ,   1Jv        ,  w  DPK!+eQddmock.cpython-36.opt-2.pycnu[3 \7@sFdZd ZddlZddlZddlZddlZddlmZddlm Z m Z dde eDZ e fZdejkrzddlZe ejjfZdZeZddZddZddZdddZdd Zd!d"Zd#d$Zd%d&Zdd'd(Zd)d*Zd+d,Z Gd-d.d.e!Z"Gd/d0d0e!Z#e#Z$e$j%Z%e$j&Z'e$j(Z)d1d2Z*d3d4d5d6d7d8d9d:hZ+d;d<Z,Gd=d>d>e-Z.d?d@Z/GdAdBdBe!Z0GdCdDdDe!Z1GdEd d e1Z2dFdGZ3GdHdIdIe1Z4GdJdde4e2Z5dKdLZ6dMdNZ7dOdPZ8GdQdRdRe!Z9dSdTZ:e%dddddfdUdVZ;ddWdXZd\d]Z?d^d_Z@e;e=_!e>e=_Ae#srjavaTcCstt|tS)N) issubclasstyper )objrrr_is_instance_mock2srcCst|tpt|tot|tS)N) isinstanceBaseExceptionsrr)rrrr _is_exception8s r cCst|tr6| r6y |j}Wntk r.dSXd}n*t|ts`y |j}Wntk r^dSX|rpt|d}n|}y|tj|fSt k rdSXdS)NT) rr__init__AttributeError FunctionTypes__call__rinspectZ signature ValueError)funcZ as_instanceZeat_selfZsig_funcrrr_get_signature_object?s$    r(FcsDt|||dkrdS\}fdd}t|||t|_dS)Ncsj||dS)N)bind) _mock_selfargskwargs)sigrrchecksigdsz"_check_signature..checksig)r(_copy_func_detailsr_mock_check_sig)r'mock skipfirstinstancer.r)r-r_check_signature_s   r4c#Cs|j|_|j|_y |j|_Wntk r0YnXy |j|_Wntk rRYnXy |j|_Wntk rtYnXy |j|_Wntk rYnXdS)N)__name____doc____text_signature__r" __module__ __defaults____kwdefaults__)r'funcopyrrrr/js$    r/cCs&t|trdSt|dddk r"dSdS)NTr$F)rrgetattr)rrrr _callables  r=cCst|ttfkS)N)rlisttuple)rrrr_is_listsr@cCsHt|tst|dddk Sx(|f|jD]}|jjddk r(dSq(WdS)Nr$TF)rrr<__mro____dict__get)rbaserrr_instance_callables  rEc st|s dSt|t}t|||}|dkr.|S|\}fdd}t|||j}|js^d}||d}d|} t| |||} t| || S)Ncsj||dS)N)r))r+r,)r-rrr.sz _set_signature..checksigr;)Z _checksig_r1zYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)) r=rrr(r/r5 isidentifierexec _setup_func) r1originalr3r2resultr'r.rcontextsrcr;r)r-r_set_signatures$       rMc s_tsdSfdd}fdd}fdd}fdd}fd d }fd d }fd d}fdd} d_d_d_t_t_t_j _ j _ j _ |_ |_ |_|_| _|_|_|__dS)Ncs j||S)N)assert_called_with)r+r,)r1rrrNsz'_setup_func..assert_called_withcs j||S)N) assert_called)r+r,)r1rrrOsz"_setup_func..assert_calledcs j||S)N)assert_not_called)r+r,)r1rrrPsz&_setup_func..assert_not_calledcs j||S)N)assert_called_once)r+r,)r1rrrQsz'_setup_func..assert_called_oncecs j||S)N)assert_called_once_with)r+r,)r1rrrRsz,_setup_func..assert_called_once_withcs j||S)N)assert_has_calls)r+r,)r1rrrSsz%_setup_func..assert_has_callscs j||S)N)assert_any_call)r+r,)r1rrrTsz$_setup_func..assert_any_callcs:t_t_jj}t|r6|k r6|jdS)N) _CallList method_calls mock_calls reset_mock return_valuer)ret)r;r1rrrXs z_setup_func..reset_mockFr)r1rcalled call_count call_argsrUcall_args_listrVrWrY side_effect_mock_childrenrNrRrSrTrXrOrPrQ_mock_delegate) r;r1rNrOrPrQrRrSrTrXr)r;r1rrHs:       rHcCsd|dd|kS)Nz__%s__r)rrrr _is_magicsrdc@seZdZddZddZdS)_SentinelObjectcCs ||_dS)N)r)selfrrrrr!sz_SentinelObject.__init__cCs d|jS)Nz sentinel.%s)r)rfrrr__repr__sz_SentinelObject.__repr__N)r5r8 __qualname__r!rgrrrrresrec@seZdZddZddZdS) _SentinelcCs i|_dS)N) _sentinels)rfrrrr!sz_Sentinel.__init__cCs|dkr t|jj|t|S)N __bases__)r"rj setdefaultre)rfrrrr __getattr__sz_Sentinel.__getattr__N)r5r8rhr!rmrrrrrisricCs$t|ttttfkr t||S|S)N)rdictr>r?set)valuerrr_copys rqrY_mock_return_valuer__mock_side_effect _mock_parent_mock_new_parent _mock_name_mock_new_namecCs8tj|d|}||fdd}||fdd}t||S)NZ_mock_cSs"|j}|dkrt||St||S)N)rar<)rfr _the_namer-rrr_gets z"_delegating_property.._getcSs*|j}|dkr||j|<n t|||dS)N)rarBsetattr)rfrprrxr-rrr_set$s z"_delegating_property.._set)_allowed_namesaddproperty)rrxryr{rrr_delegating_propertys  rc@seZdZddZddZdS)rUcCsnt|tstj||St|}t|}||kr2dSx6td||dD] }||||}||krFdSqFWdS)NFrT)rr> __contains__lenrange)rfrpZ len_valueZlen_selfiZsub_listrrrr1s  z_CallList.__contains__cCstjt|S)N)pprintZpformatr>)rfrrrrg?sz_CallList.__repr__N)r5r8rhrrgrrrrrU/srUcCsxt|s dS|js,|js,|jdk s,|jdk r0dS|}x|dk rR||krJdS|j}q6W|rd||_||_|rt||_||_dS)NFT)rrvrwrtru)parentrprnew_name_parentrrr_check_and_set_parentCs$     rc@s$eZdZddZddZddZdS) _MockItercCst||_dS)N)iterr)rfrrrrr!]sz_MockIter.__init__cCs|S)Nr)rfrrr__iter___sz_MockIter.__iter__cCs t|jS)N)nextr)rfrrr__next__asz_MockIter.__next__N)r5r8rhr!rrrrrrr\src@seZdZeZdZddZdS)BaseNcOsdS)Nr)rfr+r,rrrr!gsz Base.__init__)r5r8rhrrrrsr!rrrrrdsrc @sDeZdZddZdCddZdd ZdDd d ZdEd d ZddZddZ dZ e ee e Z e ddZ edZedZedZedZedZddZddZe eeZdFddddd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd1d2Z d3d4Z!d5d6Z"d7d8Z#d9d:Z$d;d<Z%dGd=d>Z&d?d@Z'dAdBZ(dS)Hr cOs$t|j|fd|ji}tj|}|S)Nr6)rr5r6object__new__)clsr+kwnewr3rrrros zNonCallableMock.__new__NFc Ks|dkr |}|j} || d<|| d<|| d<|| d<|dk rB|}d}| dkrR|dk } |j||| | i| d<|| d<d| d<d | d <d| d <d | d <t| d<t| d<t| d<| | d<| r|jf| tt|j||||||dS)NrtrvrwruTr` _mock_wrapsraFZ _mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrV _mock_unsafe)rB_mock_add_specrUconfigure_mock _safe_superr r!)rfspecrrspec_setr _spec_state _new_name _new_parent_spec_as_instance _eat_selfZunsafer,rBrrrr!xs8      zNonCallableMock.__init__cCs(d|_d|_d|_d|_t|||dS)Nr)rtrurvrwrz)rfr1 attributerrr attach_mocks zNonCallableMock.attach_mockcCs|j||dS)N)r)rfrrrrr mock_add_specszNonCallableMock.mock_add_specc Cs|d}d}|dk rRt| rRt|tr*|}nt|}t|||}|oH|d}t|}|j}||d<||d<||d<||d<dS)Nr _spec_class _spec_set_spec_signature _mock_methods)r@rr _get_classr(dirrB) rfrrrrrrresrBrrrrs  zNonCallableMock._mock_add_speccCs8|j}|jdk r|jj}|tkr4|j|dd}||_|S)Nz())rr)rrrarYr_get_child_mock)rfrZrrrZ__get_return_values  z"NonCallableMock.__get_return_valuecCs,|jdk r||j_n||_t||dddS)Nz())rarYrrr)rfrprrrZ__set_return_values  z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdkrt|S|jS)N)rr)rfrrr __class__s zNonCallableMock.__class__r[r\r]r^rWcCsT|j}|dkr|jS|j}|dk rPt| rPt|t rPt| rPt|}||_|S)N)rarsr_callablerrr )rf delegatedZsfrrrZ__get_side_effectsz!NonCallableMock.__get_side_effectcCs(t|}|j}|dkr||_n||_dS)N) _try_iterrarsr_)rfrprrrrZ__set_side_effects z!NonCallableMock.__set_side_effect)rYr_cCs|dkr g}t||krdS|jt|d|_d|_d|_t|_t|_t|_|r^t |_ |rhd|_ x0|j j D]"}t|tst|tkrqt|j|qtW|j }t|r||k r|j|dS)NFr)idappendr[r]r\rUrWr^rVrrrrsr`valuesr _SpecState_deletedrXr)rfZvisitedrYr_ZchildrZrrrrX s, zNonCallableMock.reset_mockcKs`xZt|jdddD]B\}}|jd}|j}|}x|D]}t||}q:Wt|||qWdS)NcSs|djdS)Nr.)count)entryrrr8sz0NonCallableMock.configure_mock..)keyr)sorteditemssplitpopr<rz)rfr,argvalr+finalrrrrrr+s   zNonCallableMock.configure_mockcCs|dkrt|n:|jdk r<||jks.|tkrLtd|nt|rLt||jsd|jdrdt||jj|}|tkrt|np|dkrd}|j dk rt |j |}|j |||||d}||j|<n.t |t rt|j|j|j|j|j}||j|<|S) NrrzMock object has no attribute %rassertassret)rrrrr>rr)rr)r"r _all_magicsrdrrr`rCrrr<rrrrrrr3rr)rfrrJrrrrrmAs6            zNonCallableMock.__getattr__c Cs"|jg}|j}|}d}|dgkr$d}t}xT|dk r~|}|j|j|d}|jdkrZd}|j}t||krnP|jt|q,Wtt|}|jpd}t |dkr|dd kr|d7}||d<dj |}d}|dkrd |}d} |j dk rd } |j rd } | |j j } d t|j || t|fS)Nr()rr1r().rmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr)r1r)rwrurorrr}r>reversedrvrjoinrrr5r) rfZ _name_listrZlastdotseenZ_firstrZ name_stringZ spec_stringrrrrggsL           zNonCallableMock.__repr__cCshtstj|S|jpg}tt|}t|j}dd|D}dd|D}tt |||t|j S)NcSsg|]}|jds|qS)r)r)rerrr sz+NonCallableMock.__dir__..cSs$g|]}|jd st|r|qS)r)rrd)rrrrrrs) r r__dir__rrrr>rBrror`)rfZextrasZ from_typeZ from_dictrrrrs    zNonCallableMock.__dir__cs"|tkrtj||SjrHjdk rH|jkrH|jkrHtd|n|tkrbd|}t|n|tkrjdk r|jkrtd|t |st t |t |||fdd}n(t |d|t t |||j|<n.|dkr|_dSt |||r|j|<tj||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.csf||S)Nr)r+r)rIrfrrrsz-NonCallableMock.__setattr__..r)r|r __setattr__rrrBr"_unsupported_magicsrrrzr _get_methodrr`r)rfrrpmsgr)rIrfrrs2       zNonCallableMock.__setattr__cCs|tkr2|t|jkr2tt||||jkr2dS||jkrHtj|||jj|t}|t krft ||tk rv|j|=t |j|<dS)N) rrrBdelattrr __delattr__r`rC_missingrr")rfrrrrrrs   zNonCallableMock.__delattr__cCs|jpd}t|||S)Nr1)rv_format_call_signature)rfr+r,rrrr_format_mock_call_signatures z+NonCallableMock._format_mock_call_signaturecCsDd}|j||}|j}t|dkr.|dd}|j|}|||fS)Nz!Expected call: %s Actual call: %sr)rr]r)rfr+r,messageexpected_stringr]Z actual_stringrrr_format_mock_failure_messages    z,NonCallableMock._format_mock_failure_messagecCst|j}|dk rlt|dkr(d}|\}}n |\}}}y||j||fStk rh}z |jdSd}~XqpXn|SdS)Nrbr)rrr) TypeErrorwith_traceback)rf_callr-rr+r,rrrr _call_matchers   zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|dS)Nrz7Expected '%s' to not have been called. Called %s times.r1)r\rvAssertionError)r*rfrrrrrPs  z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|dS)Nrz"Expected '%s' to have been called.r1)r\rvr)r*rfrrrrrO s   zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|dS)Nrz8Expected '%s' to have been called once. Called %s times.r1)r\rvr)r*rfrrrrrQs  z"NonCallableMock.assert_called_oncecs||jdkr(j}td|ffdd}jf}jj}||krxt|trh|nd}t||dS)NzExpected call: %s Not calledcsj}|S)N)r)r)r+r,rfrr_error_message's z:NonCallableMock.assert_called_with.._error_message)r]rrrr Exception)r*r+r,expectedractualcauser)r+r,rfrrNs   z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t||j||S)Nrz1Expected '%s' to be called once. Called %s times.r1)r\rvrrN)r*r+r,rfrrrrrR1s  z'NonCallableMock.assert_called_once_withc sfdd|D}t|tr |nd}tfddjD}|sd||kr`tdt|jf|dSt|}g}x:|D]2}y|j|Wqvtk r|j|YqvXqvW|rtdt |f|dS)Ncsg|]}j|qSr)r)rc)rfrrrFsz4NonCallableMock.assert_has_calls..c3s|]}j|VqdS)N)r)rr)rfrr Hsz3NonCallableMock.assert_has_calls..z(Calls not found. Expected: %r Actual: %rz%r not all found in call list) rrrUrWrr>remover&rr?)rfZcallsZ any_orderrrZ all_callsZ not_foundZkallr)rfrrS<s*  z NonCallableMock.assert_has_callscsZj||f}fddjD}||krVt|tr8|nd}j||}td||dS)Ncsg|]}j|qSr)r)rr)rfrrrfsz3NonCallableMock.assert_any_call..z%s call not found)rr^rrrr)rfr+r,rrrrr)rfrrT_s zNonCallableMock.assert_any_callcKsFt|}t|ts2t|tr"t}q.) rrrrrrrrrr,attribute_namer)rfrrrrrisz _patch.copycCst|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rfr'rrrr$vs  z_patch.__call__cCsRxLt|D]@}|jtjsq t||}t|ds2q |j}t||||q W|S)Nr$)rrr TEST_PREFIXr<rrrz)rfrattr attr_valuerrrrr|s   z_patch.decorate_classcs<tdrjj|Stfdd|g_S)N patchingscsg}g}t}zybxJjD]@}|j}|j||jdk rF|j|q|jtkr|j|qW|t|7}||S||krt|r|j|t j }YnXWdxt |D]}|j |qWXdS)N) r?r __enter__rrupdaterrrsysexc_infor__exit__)r+Zkeywargs extra_argsZentered_patchersr patchingr)r'patchedrrrs*         z)_patch.decorate_callable..patched)rrrr)rfr'r)r'rrrs   z_patch.decorate_callablec Cs|j}|j}t}d}y|j|}Wn$ttfk rHt||t}YnXd}|tkrft|t rfd|_ |j r|tkrtd||f||fS)NFTz!%s does not have the attribute %r) rrrrBr"KeyErrorr< _builtinsrrr)rfrrrIlocalrrr get_originalsz_patch.get_originalcCs>|j|j|j}}}|j|j}}|j}|j|_|dkr@d}|dkrLd}|dkrXd}|dk rp|dk rptd|dk s|dk r|dkrtd|j \}}|t ko|dkrTd} |dkr|}|dkr|}d}n&|dk r|dkr|}d}n |dkr|}|dk s |dk r,|t krtdt |t r,d} t } i} |dk rD|} nN|dk sX|dk r|} |dk rj|} t| r~d| k} n t|  } | rt} |dk r|| d<|dk r|| d<t | t rt| tr|jr|j| d <| j|| f| }| rt|r|} |dk r|} t|  r2t|  r2t} | jd | f|d d | |_nl|dk r|t k rptd |t krtd t|}|dkr|}t|f||jd|}n|rtd|}||_||_t|j|j||jdk r:i}|jt kr|||j<x.|jD]$}|j }|jt kr|j|qW|S|S)NFzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer$rrrz())rrzBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r_namez.Can't pass kwargs to a mock we aren't creating)TN)!rrrrr,rrrrrrrrrr@rr rr rr rrErrYboolr temp_originalrrzrrr )rfrrrrr,rrIrZinheritKlass_kwargsZ this_specZ not_callableZnew_attrrrrrrrr s                              z_patch.__enter__cGst|std|jr4|jtk r4t|j|j|jnBt|j|j|j rvt |j|j sd|jdkrvt|j|j|j|`|`|`x$t |j D]}t|r|j |qWdS)Nz stop called on unstarted patcherr6r8r9__annotations__r:)r6r8r9rr:)r RuntimeErrorrrrrzrrrrrrrr )rfr rrrrr Hs z_patch.__exit__cCs|j}|jj||S)N)r _active_patchesr)rfrJrrrstart`s z _patch.startc Cs.y|jj|Wntk r$YnX|jS)N)rrr&r )rfrrrstopgs z _patch.stop)r5r8rhrrr!rr$rrrr r rrrrrrrIs (~rc sPyjdd\}Wn&ttfk r:tdfYnXfdd}||fS)Nrrz.Need a valid target to patch. You supplied: %rcstS)N)rr)rrrrysz_get_target..)rsplitrr&)rrrr)rr _get_targetss r c s$fdd} t| |||||||| S)NcsS)Nrr)rrrrsz_patch_object..)r) rrrrrrrrr,rr)rr _patch_object}s  r!c sttkrfdd}n fdd}|s2tdt|j}|d\} } t|| | |||||i } | | _xB|ddD]2\} } t|| | |||||i } | | _| jj| qvW| S)NcstS)N)rr)rrrrsz!_patch_multiple..csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerr) rstrr&r>rrrrr) rrrrrrr,rrrrrZ this_patcherr)rr_patch_multiples&        r#c Ks$t|\}} t|| ||||||| S)N)r r) rrrrrrrr,rrrrrrsE  c@sReZdZfdfddZddZddZdd Zd d Zd d ZddZ eZ e Z dS) _patch_dictFcKs>t|trt|}||_t||_|jj|||_d|_dS)N) rr"rin_dictrnrr clear _original)rfr%rr&r,rrrr!0s   z_patch_dict.__init__cs.ttrjStfdd}|S)Nc s"jz ||SjXdS)N)r$ _unpatch_dict)r+r)frfrr_inner>s z$_patch_dict.__call__.._inner)rrrr)rfr)r*r)r)rfrr$;s  z_patch_dict.__call__cCs\xVt|D]J}t||}|jtjr t|dr t|j|j|j }||}t |||q W|S)Nr$) rr<rrrrr$r%rr&rz)rfrrrZ decoratorZ decoratedrrrrIs   z_patch_dict.decorate_classcCs |jdS)N)r$)rfrrrr Tsz_patch_dict.__enter__cCs|j}|j}|j}y |j}Wn2tk rPi}x|D]}||||<q8WYnX||_|rdt|y|j|Wn.tk rx|D]}||||<qWYnXdS)N)rr%r&rr"r' _clear_dictr )rfrr%r&rIrrrrr$Ys"   z_patch_dict._patch_dictc CsV|j}|j}t|y|j|Wn.tk rPx|D]}||||<q8WYnXdS)N)r%r'r+r r")rfr%rIrrrrr(ss z_patch_dict._unpatch_dictcGs |jdS)NF)r()rfr+rrrr sz_patch_dict.__exit__N) r5r8rhr!r$rr r$r(r rrrrrrr$s   r$c CsBy |jWn0tk r<t|}x|D] }||=q*WYnXdS)N)r&r"r>)r%keysrrrrr+s   r+cCs xttjD] }|jq WdS)N)rrrr)rrrr_patch_stopallsr-Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv ccs|]}d|VqdS)zi%sNr)rnrrrrsrccs|]}d|VqdS)zr%sNr)rr/rrrrs__get____set__ __delete__ __reversed__ __missing__ __reduce__ __reduce_ex__Z__getinitargs____getnewargs__ __getstate__ __setstate__ __getformat__ __setformat__rgr__subclasses__ __format____getnewargs_ex__csfdd}||_|S)Ncs|f||S)Nr)rfr+r)r'rrmethodsz_get_method..method)r5)rr'r?r)r'rrs rcCsh|] }d|qS)z__%s__r)rr?rrrrsrmrr!r __prepare____instancecheck____subclasscheck____del__cCs tj|S)N)r__hash__)rfrrrrsrcCs tj|S)N)r__str__)rfrrrrscCs tj|S)N)r __sizeof__)rfrrrrs)rDrErFry?g?) __lt____gt____le____ge____int__r__len__r  __complex__ __float____bool__ __index__csfdd}|S)Ncs$jj}|tk r|S|kr dStS)NT)__eq__rrrNotImplemented)otherret_val)rfrrrQs z_get_eq..__eq__r)rfrQr)rfr_get_eqs rUcsfdd}|S)Ncs jjtk rtS|krdStS)NF)__ne__rrrrR)rS)rfrrrVs  z_get_ne..__ne__r)rfrVr)rfr_get_nes rWcsfdd}|S)Ncs jj}|tkrtgSt|S)N)rrrrr)rT)rfrrrsz_get_iter..__iter__r)rfrr)rfr _get_iters rX)rQrVrc Cstj|t}|tk r||_dStj|}|dk rdy ||}Wntk rXt|}YnX||_dStj|}|dk r|||_dS)N)_return_valuesrCrrY_calculate_return_valuer"_side_effect_methodsr_)r1r?rZfixedZreturn_calulatorrYZ side_effectorrrr_set_return_values    r\c@seZdZddZddZdS) MagicMixincOs&|jtt|j|||jdS)N)_mock_set_magicsrr]r!)rfr+rrrrr!(szMagicMixin.__init__cCst}t|dddk rTtj|j}t}t|}x$|D]}|t|jkr4t||q4W|tt|j}t|}x|D]}t||t ||qtWdS)Nr) _magicsr< intersectionrrorrBrrz MagicProxy)rfZ these_magicsZ remove_magicsrrrrrr^.s   zMagicMixin._mock_set_magicsN)r5r8rhr!r^rrrrr]'sr]c@seZdZdddZdS)r FcCs|j|||jdS)N)rr^)rfrrrrrrGs z"NonCallableMagicMock.mock_add_specN)F)r5r8rhrrrrrr Esc@seZdZdddZdS)rFcCs|j|||jdS)N)rr^)rfrrrrrr]s zMagicMock.mock_add_specN)F)r5r8rhrrrrrrRs c@s.eZdZddZddZddZd dd ZdS) racCs||_||_dS)N)rr)rfrrrrrr!iszMagicProxy.__init__cOs|j}|||S)N) create_mock)rfr+r,mrrrr$mszMagicProxy.__call__cCs8|j}|j}|j|||d}t|||t||||S)N)rrr)rrrrzr\)rfrrrcrrrrbqs  zMagicProxy.create_mockNcCs|jS)N)rb)rfrrrrrr0zszMagicProxy.__get__)N)r5r8rhr!r$rbr0rrrrrahs rac@s$eZdZddZddZddZdS)_ANYcCsdS)NTr)rfrSrrrrQsz _ANY.__eq__cCsdS)NFr)rfrSrrrrVsz _ANY.__ne__cCsdS)Nzr)rfrrrrgsz _ANY.__repr__N)r5r8rhrQrVrgrrrrrdsrdcCsdd|}d}djdd|D}djddt|jD}|rD|}|r\|rT|d7}||7}||S)Nz%s(%%s)rz, cSsg|] }t|qSr)repr)rrrrrrsz*_format_call_signature..cSsg|]\}}d||fqS)z%s=%rr)rrrprrrrs)rrr)rr+r,rZformatted_argsZ args_stringZ kwargs_stringrrrrsrc@sreZdZfddddfddZfddddfddZd d ZejZd d Zd dZ ddZ ddZ ddZ ddZ dS)rrNFTc Csf}i}t|}|dkr$|\}}}nr|dkrd|\} } t| trX| }t| trR| }qb| }q| | }}n2|dkr|\}t|tr|}nt|tr|}n|}|rtj|||fStj||||fS)Nrrbr)rrr"r?r) rrprrr from_kallr+r,_lenfirstsecondrrrrs.      z _Call.__new__cCs||_||_||_dS)N)rvrt_mock_from_kall)rfrprrrrfrrrr!sz_Call.__init__c Csf|tkr dSy t|}Wntk r,dSXd}t|dkrH|\}}n |\}}}t|ddrzt|ddrz|j|jkrzdSd}|dkrfi}}n|dkr|\}}}n|dkr|\} t| tr| }i}n"t| tr| }fi}}nf}| }nV|dkr>|\} } t| tr2| }t| tr&| i}}n f| }}n | | }}ndS|rV||krVdS||f||fkS) NTFrrbrtrrr)rrrr<rtrr?r") rfrSZ len_otherZ self_nameZ self_argsZ self_kwargsZ other_nameZ other_argsZ other_kwargsrprhrirrrrQsP                z _Call.__eq__cOs<|jdkrtd||fddS|jd}t|j||f||dS)Nrz())r)rr)rvr)rfr+r,rrrrr$s  z_Call.__call__cCs2|jdkrt|ddSd|j|f}t||ddS)NF)rrfz%s.%s)rrrf)rvr)rfrrrrrrms  z_Call.__getattr__cOs|jd||S)Nr)rm)rfr+r,rrrr$sz _Call.countcOs|jd||S)Nindex)rm)rfr+r,rrrrk'sz _Call.indexcCs||js&|jpd}|jdr"d|}|St|dkr@d}|\}}n0|\}}}|sTd}n|jdshd|}nd|}t|||S)Nrz()zcall%srbzcall.%s)rjrvrrr)rfrr+r,rrrrg*s       z_Call.__repr__cCs8g}|}x"|dk r*|jr"|j||j}q Wtt|S)N)rjrrtrUr)rfvalsrrrr call_list?s   z_Call.call_list)r5r8rhrr!rQrrVr$rmrrkrgrmrrrrrs  7r)rfcKs,t|rt|}t|t}d|i}|r0d|i}n |dkr.rrxrxrxrx)rbytesr) read_dataZ data_as_listliner)rwr_iterate_read_data s  r|rcsfdd}fdd}fddtdkr`ddl}ttt|jjtt|ja|dkrttdt d }ttd j _ t dgdj _ dj_ dj_ dj_ |j_d <d j_|j_fd d }||_|_ |S)Ncs jjdk rjjStdS)Nr) readlinesrYr>)r+r,)_statehandlerr_readlines_side_effect( s z)mock_open.._readlines_side_effectcs(jjdk rjjStjdS)Nr)readrYrr)r+r,)r~rrzrr_read_side_effect- s z$mock_open.._read_side_effectc3sJjjdk rxjjVqWxdD] }|Vq&WxtVq6WdS)Nr)readlinerYr)r{)r~rrzrr_readline_side_effect2 s  z(mock_open.._readline_side_effectropen)rr)rrcs6td<jjdkr2d<dj_tS)Nrr)r|rr_r)r+r,)rr~rrzrr reset_dataS s    zmock_open..reset_data) file_spec_ior>ror TextIOWrapperunionBytesIOrrr rYr|writerrr}r_)r1rzrrrrr)rr~rrzrr  s.  "     c@s$eZdZddZddZddZdS)r cKs tf|S)N)r)rfr,rrrri szPropertyMock._get_child_mockcCs|S)Nr)rfrZobj_typerrrr0l szPropertyMock.__get__cCs ||dS)Nr)rfrrrrrr1n szPropertyMock.__set__N)r5r8rhrr0r1rrrrr ` s ) rrrrrrrrr r r r r )F)F)NFNNN)FFNN)Nr)o__all__ __version__r%rr builtinstypesr functoolsrrrr BaseExceptionrplatformrZlangZ Throwabler superrrr r(r4r/r=r@rErMrHrdrrerirrZMISSINGrZDELETEDrrqr|rr>rUrrrr rrrrrrrr r!r#rr$r+r-rnZmultipleZstopallrZ magic_methodsZnumericsrrZinplacerightZ _non_defaultsrr_rrrZrRrYrUrWrXr[r\r]r rrardrrr?rrrrnrrrrQr#r0rrrr|r r rrrrs     4  i5 ,   1Jv        ,  w  DPK!g"\\mock.cpython-36.pycnu[3 \7@sFdZd ZddlZddlZddlZddlZddlmZddlm Z m Z dde eDZ e fZdejkrzddlZe ejjfZdZeZddZddZddZdddZdd Zd!d"Zd#d$Zd%d&Zdd'd(Zd)d*Zd+d,Z Gd-d.d.e!Z"Gd/d0d0e!Z#e#Z$e$j%Z%e$j&Z'e$j(Z)d1d2Z*d3d4d5d6d7d8d9d:hZ+d;d<Z,Gd=d>d>e-Z.d?d@Z/GdAdBdBe!Z0GdCdDdDe!Z1GdEd d e1Z2dFdGZ3GdHdIdIe1Z4GdJdde4e2Z5dKdLZ6dMdNZ7dOdPZ8GdQdRdRe!Z9dSdTZ:e%dddddfdUdVZ;ddWdXZd\d]Z?d^d_Z@e;e=_!e>e=_Ae#srjavaTcCstt|tS)N) issubclasstyper )objrrr_is_instance_mock2srcCst|tpt|tot|tS)N) isinstanceBaseExceptionsrr)rrrr _is_exception8s r cCst|tr6| r6y |j}Wntk r.dSXd}n*t|ts`y |j}Wntk r^dSX|rpt|d}n|}y|tj|fSt k rdSXdS)z Given an arbitrary, possibly callable object, try to create a suitable signature object. Return a (reduced func, signature) tuple, or None. NT) rr__init__AttributeError FunctionTypes__call__rinspectZ signature ValueError)funcZ as_instanceZeat_selfZsig_funcrrr_get_signature_object?s$    r(FcsDt|||dkrdS\}fdd}t|||t|_dS)Ncsj||dS)N)bind) _mock_selfargskwargs)sigrrchecksigdsz"_check_signature..checksig)r(_copy_func_detailsr_mock_check_sig)r'mock skipfirstinstancer.r)r-r_check_signature_s   r4c#Cs|j|_|j|_y |j|_Wntk r0YnXy |j|_Wntk rRYnXy |j|_Wntk rtYnXy |j|_Wntk rYnXdS)N)__name____doc____text_signature__r" __module__ __defaults____kwdefaults__)r'funcopyrrrr/js$    r/cCs&t|trdSt|dddk r"dSdS)NTr$F)rrgetattr)rrrr _callables  r=cCst|ttfkS)N)rlisttuple)rrrr_is_listsr@cCsHt|tst|dddk Sx(|f|jD]}|jjddk r(dSq(WdS)ztGiven an object, return True if the object is callable. For classes, return True if instances would be callable.r$NTF)rrr<__mro____dict__get)rbaserrr_instance_callables  rEc st|s dSt|t}t|||}|dkr.|S|\}fdd}t|||j}|js^d}||d}d|} t| |||} t| || S)Ncsj||dS)N)r))r+r,)r-rrr.sz _set_signature..checksigr;)Z _checksig_r1zYdef %s(*args, **kwargs): _checksig_(*args, **kwargs) return mock(*args, **kwargs)) r=rrr(r/r5 isidentifierexec _setup_func) r1originalr3r2resultr'r.rcontextsrcr;r)r-r_set_signatures$       rMc s_tsdSfdd}fdd}fdd}fdd}fd d }fd d }fd d}fdd} d_d_d_t_t_t_j _ j _ j _ |_ |_ |_|_| _|_|_|__dS)Ncs j||S)N)assert_called_with)r+r,)r1rrrNsz'_setup_func..assert_called_withcs j||S)N) assert_called)r+r,)r1rrrOsz"_setup_func..assert_calledcs j||S)N)assert_not_called)r+r,)r1rrrPsz&_setup_func..assert_not_calledcs j||S)N)assert_called_once)r+r,)r1rrrQsz'_setup_func..assert_called_oncecs j||S)N)assert_called_once_with)r+r,)r1rrrRsz,_setup_func..assert_called_once_withcs j||S)N)assert_has_calls)r+r,)r1rrrSsz%_setup_func..assert_has_callscs j||S)N)assert_any_call)r+r,)r1rrrTsz$_setup_func..assert_any_callcs:t_t_jj}t|r6|k r6|jdS)N) _CallList method_calls mock_calls reset_mock return_valuer)ret)r;r1rrrXs z_setup_func..reset_mockFr)r1rcalled call_count call_argsrUcall_args_listrVrWrY side_effect_mock_childrenrNrRrSrTrXrOrPrQ_mock_delegate) r;r1rNrOrPrQrRrSrTrXr)r;r1rrHs:       rHcCsd|dd|kS)Nz__%s__r)rrrr _is_magicsrdc@s eZdZdZddZddZdS)_SentinelObjectz!A unique, named, sentinel object.cCs ||_dS)N)r)selfrrrrr!sz_SentinelObject.__init__cCs d|jS)Nz sentinel.%s)r)rfrrr__repr__sz_SentinelObject.__repr__N)r5r8 __qualname__r6r!rgrrrrresrec@s eZdZdZddZddZdS) _SentinelzAAccess attributes to return a named object, usable as a sentinel.cCs i|_dS)N) _sentinels)rfrrrr!sz_Sentinel.__init__cCs|dkr t|jj|t|S)N __bases__)r"rj setdefaultre)rfrrrr __getattr__sz_Sentinel.__getattr__N)r5r8rhr6r!rmrrrrrisricCs$t|ttttfkr t||S|S)N)rdictr>r?set)valuerrr_copys rqrY_mock_return_valuer__mock_side_effect _mock_parent_mock_new_parent _mock_name_mock_new_namecCs8tj|d|}||fdd}||fdd}t||S)NZ_mock_cSs"|j}|dkrt||St||S)N)rar<)rfr _the_namer-rrr_gets z"_delegating_property.._getcSs*|j}|dkr||j|<n t|||dS)N)rarBsetattr)rfrprrxr-rrr_set$s z"_delegating_property.._set)_allowed_namesaddproperty)rrxryr{rrr_delegating_propertys  rc@seZdZddZddZdS)rUcCsnt|tstj||St|}t|}||kr2dSx6td||dD] }||||}||krFdSqFWdS)NFrT)rr> __contains__lenrange)rfrpZ len_valueZlen_selfiZsub_listrrrr1s  z_CallList.__contains__cCstjt|S)N)pprintZpformatr>)rfrrrrg?sz_CallList.__repr__N)r5r8rhrrgrrrrrU/srUcCsxt|s dS|js,|js,|jdk s,|jdk r0dS|}x|dk rR||krJdS|j}q6W|rd||_||_|rt||_||_dS)NFT)rrvrwrtru)parentrprnew_name_parentrrr_check_and_set_parentCs$     rc@s$eZdZddZddZddZdS) _MockItercCst||_dS)N)iterr)rfrrrrr!]sz_MockIter.__init__cCs|S)Nr)rfrrr__iter___sz_MockIter.__iter__cCs t|jS)N)nextr)rfrrr__next__asz_MockIter.__next__N)r5r8rhr!rrrrrrr\src@seZdZeZdZddZdS)BaseNcOsdS)Nr)rfr+r,rrrr!gsz Base.__init__)r5r8rhrrrrsr!rrrrrdsrc @sHeZdZdZddZdDddZd d ZdEd d ZdFd dZddZ ddZ dZ e e e e Z e ddZedZedZedZedZedZddZddZe eeZdGdddd d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-Zd.d/Zd0d1Z d2d3Z!d4d5Z"d6d7Z#d8d9Z$d:d;Z%dd?Z'd@dAZ(dBdCZ)dS)Ir z A non-callable version of `Mock`cOs$t|j|fd|ji}tj|}|S)Nr6)rr5r6object__new__)clsr+kwnewr3rrrros zNonCallableMock.__new__NFc Ks|dkr |}|j} || d<|| d<|| d<|| d<|dk rB|}d}| dkrR|dk } |j||| | i| d<|| d<d| d<d | d <d| d <d | d <t| d<t| d<t| d<| | d<| r|jf| tt|j||||||dS)NrtrvrwruTr` _mock_wrapsraFZ _mock_calledZ_mock_call_argsrZ_mock_call_countZ_mock_call_args_listZ_mock_mock_callsrV _mock_unsafe)rB_mock_add_specrUconfigure_mock _safe_superr r!)rfspecrrspec_setr _spec_state _new_name _new_parent_spec_as_instance _eat_selfZunsafer,rBrrrr!xs8      zNonCallableMock.__init__cCs(d|_d|_d|_d|_t|||dS)z Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the `method_calls` and `mock_calls` attributes of this one.Nr)rtrurvrwrz)rfr1 attributerrr attach_mocks zNonCallableMock.attach_mockcCs|j||dS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)r)rfrrrrr mock_add_specszNonCallableMock.mock_add_specc Cs|d}d}|dk rRt| rRt|tr*|}nt|}t|||}|oH|d}t|}|j}||d<||d<||d<||d<dS)Nr _spec_class _spec_set_spec_signature _mock_methods)r@rr _get_classr(dirrB) rfrrrrrrresrBrrrrs  zNonCallableMock._mock_add_speccCs8|j}|jdk r|jj}|tkr4|j|dd}||_|S)Nz())rr)rrrarYr_get_child_mock)rfrZrrrZ__get_return_values  z"NonCallableMock.__get_return_valuecCs,|jdk r||j_n||_t||dddS)Nz())rarYrrr)rfrprrrZ__set_return_values  z"NonCallableMock.__set_return_valuez1The value to be returned when the mock is called.cCs|jdkrt|S|jS)N)rr)rfrrr __class__s zNonCallableMock.__class__r[r\r]r^rWcCsT|j}|dkr|jS|j}|dk rPt| rPt|t rPt| rPt|}||_|S)N)rarsr_callablerrr )rf delegatedZsfrrrZ__get_side_effectsz!NonCallableMock.__get_side_effectcCs(t|}|j}|dkr||_n||_dS)N) _try_iterrarsr_)rfrprrrrZ__set_side_effects z!NonCallableMock.__set_side_effect)rYr_cCs|dkr g}t||krdS|jt|d|_d|_d|_t|_t|_t|_|r^t |_ |rhd|_ x0|j j D]"}t|tst|tkrqt|j|qtW|j }t|r||k r|j|dS)z-Restore the mock object to its initial state.NFr)idappendr[r]r\rUrWr^rVrrrrsr`valuesr _SpecState_deletedrXr)rfZvisitedrYr_ZchildrZrrrrX s, zNonCallableMock.reset_mockcKs`xZt|jdddD]B\}}|jd}|j}|}x|D]}t||}q:Wt|||qWdS)aZSet attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs)cSs|djdS)Nr.)count)entryrrr8sz0NonCallableMock.configure_mock..)keyrN)sorteditemssplitpopr<rz)rfr,argvalr+finalrrrrrr+s   zNonCallableMock.configure_mockcCs|dkrt|n:|jdk r<||jks.|tkrLtd|nt|rLt||jsd|jdrdt||jj|}|tkrt|np|dkrd}|j dk rt |j |}|j |||||d}||j|<n.t |t rt|j|j|j|j|j}||j|<|S) NrrzMock object has no attribute %rassertassret)rrrrr>rr)rr)r"r _all_magicsrdrrr`rCrrr<rrrrrrr3rr)rfrrJrrrrrmAs6            zNonCallableMock.__getattr__c Cs"|jg}|j}|}d}|dgkr$d}t}xT|dk r~|}|j|j|d}|jdkrZd}|j}t||krnP|jt|q,Wtt|}|jpd}t |dkr|dd kr|d7}||d<dj |}d}|dkrd |}d} |j dk rd } |j rd } | |j j } d t|j || t|fS)Nr()rr1r().rmock.z name=%rz spec=%rz spec_set=%rz<%s%s%s id='%s'>)rr)r1r)rwrurorrr}r>reversedrvrjoinrrr5r) rfZ _name_listrZlastdotseenZ_firstrZ name_stringZ spec_stringrrrrggsL           zNonCallableMock.__repr__cCshtstj|S|jpg}tt|}t|j}dd|D}dd|D}tt |||t|j S)z8Filter the output of `dir(mock)` to only useful members.cSsg|]}|jds|qS)r)r)rerrr sz+NonCallableMock.__dir__..cSs$g|]}|jd st|r|qS)r)rrd)rrrrrrs) r r__dir__rrrr>rBrror`)rfZextrasZ from_typeZ from_dictrrrrs    zNonCallableMock.__dir__cs"|tkrtj||SjrHjdk rH|jkrH|jkrHtd|n|tkrbd|}t|n|tkrjdk r|jkrtd|t |st t |t |||fdd}n(t |d|t t |||j|<n.|dkr|_dSt |||r|j|<tj||S)Nz!Mock object has no attribute '%s'z.Attempting to set unsupported magic method %r.csf||S)Nr)r+r)rIrfrrrsz-NonCallableMock.__setattr__..r)r|r __setattr__rrrBr"_unsupported_magicsrrrzr _get_methodrr`r)rfrrpmsgr)rIrfrrs2       zNonCallableMock.__setattr__cCs|tkr2|t|jkr2tt||||jkr2dS||jkrHtj|||jj|t}|t krft ||tk rv|j|=t |j|<dS)N) rrrBdelattrr __delattr__r`rC_missingrr")rfrrrrrrs   zNonCallableMock.__delattr__cCs|jpd}t|||S)Nr1)rv_format_call_signature)rfr+r,rrrr_format_mock_call_signatures z+NonCallableMock._format_mock_call_signaturecCsDd}|j||}|j}t|dkr.|dd}|j|}|||fS)Nz!Expected call: %s Actual call: %sr)rr]r)rfr+r,messageexpected_stringr]Z actual_stringrrr_format_mock_failure_messages    z,NonCallableMock._format_mock_failure_messagecCst|j}|dk rlt|dkr(d}|\}}n |\}}}y||j||fStk rh}z |jdSd}~XqpXn|SdS)a Given a call (or simply an (args, kwargs) tuple), return a comparison key suitable for matching with other calls. This is a best effort method which relies on the spec's signature, if available, or falls back on the arguments themselves. Nrbr)rrr) TypeErrorwith_traceback)rf_callr-rr+r,rrrr _call_matchers   zNonCallableMock._call_matchercCs.|}|jdkr*d|jpd|jf}t|dS)z/assert that the mock was never called. rz7Expected '%s' to not have been called. Called %s times.r1N)r\rvAssertionError)r*rfrrrrrPs  z!NonCallableMock.assert_not_calledcCs(|}|jdkr$d|jpd}t|dS)z6assert that the mock was called at least once rz"Expected '%s' to have been called.r1N)r\rvr)r*rfrrrrrO s   zNonCallableMock.assert_calledcCs.|}|jdks*d|jpd|jf}t|dS)z3assert that the mock was called only once. rz8Expected '%s' to have been called once. Called %s times.r1N)r\rvr)r*rfrrrrrQs  z"NonCallableMock.assert_called_oncecs||jdkr(j}td|ffdd}jf}jj}||krxt|trh|nd}t||dS)zassert that the mock was called with the specified arguments. Raises an AssertionError if the args and keyword args passed in are different to the last call to the mock.NzExpected call: %s Not calledcsj}|S)N)r)r)r+r,rfrr_error_message's z:NonCallableMock.assert_called_with.._error_message)r]rrrr Exception)r*r+r,expectedractualcauser)r+r,rfrrNs   z"NonCallableMock.assert_called_withcOs6|}|jdks*d|jpd|jf}t||j||S)ziassert that the mock was called exactly once and that that call was with the specified arguments.rz1Expected '%s' to be called once. Called %s times.r1)r\rvrrN)r*r+r,rfrrrrrR1s  z'NonCallableMock.assert_called_once_withc sfdd|D}t|tr |nd}tfddjD}|sd||kr`tdt|jf|dSt|}g}x:|D]2}y|j|Wqvtk r|j|YqvXqvW|rtdt |f|dS)aassert the mock has been called with the specified calls. The `mock_calls` list is checked for the calls. If `any_order` is False (the default) then the calls must be sequential. There can be extra calls before or after the specified calls. If `any_order` is True then the calls can be in any order, but they must all appear in `mock_calls`.csg|]}j|qSr)r)rc)rfrrrFsz4NonCallableMock.assert_has_calls..Nc3s|]}j|VqdS)N)r)rr)rfrr Hsz3NonCallableMock.assert_has_calls..z(Calls not found. Expected: %r Actual: %rz%r not all found in call list) rrrUrWrr>remover&rr?)rfZcallsZ any_orderrrZ all_callsZ not_foundZkallr)rfrrS<s*  z NonCallableMock.assert_has_callscsZj||f}fddjD}||krVt|tr8|nd}j||}td||dS)zassert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike `assert_called_with` and `assert_called_once_with` that only pass if the call is the most recent one.csg|]}j|qSr)r)rr)rfrrrfsz3NonCallableMock.assert_any_call..Nz%s call not found)rr^rrrr)rfr+r,rrrrr)rfrrT_s zNonCallableMock.assert_any_callcKsFt|}t|ts2t|tr"t}q.) rrrrrrrrrr,attribute_namer)rfrrrrrisz _patch.copycCst|tr|j|S|j|S)N)rrdecorate_classdecorate_callable)rfr'rrrr$vs  z_patch.__call__cCsRxLt|D]@}|jtjsq t||}t|ds2q |j}t||||q W|S)Nr$)rrr TEST_PREFIXr<rrrz)rfrattr attr_valuerrrrr|s   z_patch.decorate_classcs<tdrjj|Stfdd|g_S)N patchingscsg}g}t}zybxJjD]@}|j}|j||jdk rF|j|q|jtkr|j|qW|t|7}||S||krt|r|j|t j }YnXWdxt |D]}|j |qWXdS)N) r?r __enter__rrupdaterrrsysexc_infor__exit__)r+Zkeywargs extra_argsZentered_patchersr patchingr)r'patchedrrrs*         z)_patch.decorate_callable..patched)rrrr)rfr'r)r'rrrs   z_patch.decorate_callablec Cs|j}|j}t}d}y|j|}Wn$ttfk rHt||t}YnXd}|tkrft|t rfd|_ |j r|tkrtd||f||fS)NFTz!%s does not have the attribute %r) rrrrBr"KeyErrorr< _builtinsrrr)rfrrrIlocalrrr get_originalsz_patch.get_originalcCs>|j|j|j}}}|j|j}}|j}|j|_|dkr@d}|dkrLd}|dkrXd}|dk rp|dk rptd|dk s|dk r|dkrtd|j \}}|t ko|dkrTd} |dkr|}|dkr|}d}n&|dk r|dkr|}d}n |dkr|}|dk s |dk r,|t krtdt |t r,d} t } i} |dk rD|} nN|dk sX|dk r|} |dk rj|} t| r~d| k} n t|  } | rt} |dk r|| d<|dk r|| d <t | t rt| tr|jr|j| d <| j|| f| }| rt|r|} |dk r|} t|  r2t|  r2t} | jd | f|d d | |_nl|dk r|t k rptd |t krtdt|}|dkr|}t|f||jd|}n|rtd|}||_||_t|j|j||jdk r:i}|jt kr|||j<x.|jD]$}|j }|jt kr|j|qW|S|S)zPerform the patch.FNzCan't specify spec and autospecTz6Can't provide explicit spec_set *and* spec or autospecz!Can't use 'spec' with create=Truer$rrrz())rrzBautospec creates the mock for you. Can't specify autospec and new.z%Can't use 'autospec' with create=True)r_namez.Can't pass kwargs to a mock we aren't creating)TN)!rrrrr,rrrrrrrrrr@rr rr rr rrErrYboolr temp_originalrrzrrr )rfrrrrr,rrIrZinheritKlass_kwargsZ this_specZ not_callableZnew_attrrrrrrrr s                              z_patch.__enter__cGst|std|jr4|jtk r4t|j|j|jnBt|j|j|j rvt |j|j sd|jdkrvt|j|j|j|`|`|`x$t |j D]}t|r|j |qWdS) zUndo the patch.z stop called on unstarted patcherr6r8r9__annotations__r:N)r6r8r9rr:)r RuntimeErrorrrrrzrrrrrrrr )rfr rrrrr Hs z_patch.__exit__cCs|j}|jj||S)z-Activate a patch, returning any created mock.)r _active_patchesr)rfrJrrrstart`s z _patch.startc Cs.y|jj|Wntk r$YnX|jS)zStop an active patch.)rrr&r )rfrrrstopgs z _patch.stop)r5r8rhrrr!rr$rrrr r rrrrrrrIs (~rc sPyjdd\}Wn&ttfk r:tdfYnXfdd}||fS)Nrrz.Need a valid target to patch. You supplied: %rcstS)N)rr)rrrrysz_get_target..)rsplitrr&)rrrr)rr _get_targetss r c s$fdd} t| |||||||| S)a patch the named member (`attribute`) on an object (`target`) with a mock object. `patch.object` can be used as a decorator, class decorator or a context manager. Arguments `new`, `spec`, `create`, `spec_set`, `autospec` and `new_callable` have the same meaning as for `patch`. Like `patch`, `patch.object` takes arbitrary keyword arguments for configuring the mock object it creates. When used as a class decorator `patch.object` honours `patch.TEST_PREFIX` for choosing which methods to wrap. csS)Nrr)rrrrsz_patch_object..)r) rrrrrrrrr,rr)rr _patch_object}s  r!c sttkrfdd}n fdd}|s2tdt|j}|d\} } t|| | |||||i } | | _xB|ddD]2\} } t|| | |||||i } | | _| jj| qvW| S)aPerform multiple patches in a single call. It takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use `DEFAULT` as the value if you want `patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when `patch.multiple` is used as a context manager. `patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments `spec`, `spec_set`, `create`, `autospec` and `new_callable` have the same meaning as for `patch`. These arguments will be applied to *all* patches done by `patch.multiple`. When used as a class decorator `patch.multiple` honours `patch.TEST_PREFIX` for choosing which methods to wrap. cstS)N)rr)rrrrsz!_patch_multiple..csS)Nrr)rrrrsz=Must supply at least one keyword argument with patch.multiplerrN) rstrr&r>rrrrr) rrrrrrr,rrrrrZ this_patcherr)rr_patch_multiples&        r#c Ks$t|\}} t|| ||||||| S)a `patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the `target` is patched with a `new` object. When the function/with statement exits the patch is undone. If `new` is omitted, then the target is replaced with a `MagicMock`. If `patch` is used as a decorator and `new` is omitted, the created mock is passed in as an extra argument to the decorated function. If `patch` is used as a context manager the created mock is returned by the context manager. `target` should be a string in the form `'package.module.ClassName'`. The `target` is imported and the specified object replaced with the `new` object, so the `target` must be importable from the environment you are calling `patch` from. The target is imported when the decorated function is executed, not at decoration time. The `spec` and `spec_set` keyword arguments are passed to the `MagicMock` if patch is creating one for you. In addition you can pass `spec=True` or `spec_set=True`, which causes patch to pass in the object being mocked as the spec/spec_set object. `new_callable` allows you to specify a different class, or callable object, that will be called to create the `new` object. By default `MagicMock` is used. A more powerful form of `spec` is `autospec`. If you set `autospec=True` then the mock will be created with a spec from the object being replaced. All attributes of the mock will also have the spec of the corresponding attribute of the object being replaced. Methods and functions being mocked will have their arguments checked and will raise a `TypeError` if they are called with the wrong signature. For mocks replacing a class, their return value (the 'instance') will have the same spec as the class. Instead of `autospec=True` you can pass `autospec=some_object` to use an arbitrary object as the spec instead of the one being replaced. By default `patch` will fail to replace attributes that don't exist. If you pass in `create=True`, and the attribute doesn't exist, patch will create the attribute for you when the patched function is called, and delete it again afterwards. This is useful for writing tests against attributes that your production code creates at runtime. It is off by default because it can be dangerous. With it switched on you can write passing tests against APIs that don't actually exist! Patch can be used as a `TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods share a common patchings set. `patch` finds tests by looking for method names that start with `patch.TEST_PREFIX`. By default this is `test`, which matches the way `unittest` finds tests. You can specify an alternative prefix by setting `patch.TEST_PREFIX`. Patch can be used as a context manager, with the with statement. Here the patching applies to the indented block after the with statement. If you use "as" then the patched object will be bound to the name after the "as"; very useful if `patch` is creating a mock object for you. `patch` takes arbitrary keyword arguments. These will be passed to the `Mock` (or `new_callable`) on construction. `patch.dict(...)`, `patch.multiple(...)` and `patch.object(...)` are available for alternate use-cases. )r r) rrrrrrrr,rrrrrrsE  c@sVeZdZdZfdfddZddZddZd d Zd d Zd dZ ddZ eZ e Z dS) _patch_dicta# Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test. `in_dict` can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys. `in_dict` can also be a string specifying the name of the dictionary, which will then be fetched by importing it. `values` can be a dictionary of values to set in the dictionary. `values` can also be an iterable of `(key, value)` pairs. If `clear` is True then the dictionary will be cleared before the new values are set. `patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary:: with patch.dict('sys.modules', mymodule=Mock(), other_module=Mock()): ... `patch.dict` can be used as a context manager, decorator or class decorator. When used as a class decorator `patch.dict` honours `patch.TEST_PREFIX` for choosing which methods to wrap. FcKs>t|trt|}||_t||_|jj|||_d|_dS)N) rr"rin_dictrnrr clear _original)rfr%rr&r,rrrr!0s   z_patch_dict.__init__cs.ttrjStfdd}|S)Nc s"jz ||SjXdS)N)r$ _unpatch_dict)r+r)frfrr_inner>s z$_patch_dict.__call__.._inner)rrrr)rfr)r*r)r)rfrr$;s  z_patch_dict.__call__cCs\xVt|D]J}t||}|jtjr t|dr t|j|j|j }||}t |||q W|S)Nr$) rr<rrrrr$r%rr&rz)rfrrrZ decoratorZ decoratedrrrrIs   z_patch_dict.decorate_classcCs |jdS)zPatch the dict.N)r$)rfrrrr Tsz_patch_dict.__enter__cCs|j}|j}|j}y |j}Wn2tk rPi}x|D]}||||<q8WYnX||_|rdt|y|j|Wn.tk rx|D]}||||<qWYnXdS)N)rr%r&rr"r' _clear_dictr )rfrr%r&rIrrrrr$Ys"   z_patch_dict._patch_dictc CsV|j}|j}t|y|j|Wn.tk rPx|D]}||||<q8WYnXdS)N)r%r'r+r r")rfr%rIrrrrr(ss z_patch_dict._unpatch_dictcGs |jdS)zUnpatch the dict.F)r()rfr+rrrr sz_patch_dict.__exit__N) r5r8rhr6r!r$rr r$r(r rrrrrrr$s   r$c CsBy |jWn0tk r<t|}x|D] }||=q*WYnXdS)N)r&r"r>)r%keysrrrrr+s   r+cCs xttjD] }|jq WdS)z7Stop all active patches. LIFO to unroll nested patches.N)rrrr)rrrr_patch_stopallsr-Ztestzlt le gt ge eq ne getitem setitem delitem len contains iter hash str sizeof enter exit divmod rdivmod neg pos abs invert complex int float index trunc floor ceil bool next zHadd sub mul matmul div floordiv mod lshift rshift and xor or pow truediv ccs|]}d|VqdS)zi%sNr)rnrrrrsrccs|]}d|VqdS)zr%sNr)rr/rrrrs__get____set__ __delete__ __reversed__ __missing__ __reduce__ __reduce_ex__Z__getinitargs____getnewargs__ __getstate__ __setstate__ __getformat__ __setformat__rgr__subclasses__ __format____getnewargs_ex__csfdd}||_|S)z:Turns a callable object (like a mock) into a real functioncs|f||S)Nr)rfr+r)r'rrmethodsz_get_method..method)r5)rr'r?r)r'rrs rcCsh|] }d|qS)z__%s__r)rr?rrrrsrmrr!r __prepare____instancecheck____subclasscheck____del__cCs tj|S)N)r__hash__)rfrrrrsrcCs tj|S)N)r__str__)rfrrrrscCs tj|S)N)r __sizeof__)rfrrrrs)rDrErFry?g?) __lt____gt____le____ge____int__r__len__r  __complex__ __float____bool__ __index__csfdd}|S)Ncs$jj}|tk r|S|kr dStS)NT)__eq__rrrNotImplemented)otherret_val)rfrrrQs z_get_eq..__eq__r)rfrQr)rfr_get_eqs rUcsfdd}|S)Ncs jjtk rtS|krdStS)NF)__ne__rrrrR)rS)rfrrrVs  z_get_ne..__ne__r)rfrVr)rfr_get_nes rWcsfdd}|S)Ncs jj}|tkrtgSt|S)N)rrrrr)rT)rfrrrsz_get_iter..__iter__r)rfrr)rfr _get_iters rX)rQrVrc Cstj|t}|tk r||_dStj|}|dk rdy ||}Wntk rXt|}YnX||_dStj|}|dk r|||_dS)N)_return_valuesrCrrY_calculate_return_valuer"_side_effect_methodsr_)r1r?rZfixedZreturn_calulatorrYZ side_effectorrrr_set_return_values    r\c@seZdZddZddZdS) MagicMixincOs&|jtt|j|||jdS)N)_mock_set_magicsrr]r!)rfr+rrrrr!(szMagicMixin.__init__cCst}t|dddk rTtj|j}t}t|}x$|D]}|t|jkr4t||q4W|tt|j}t|}x|D]}t||t ||qtWdS)Nr) _magicsr< intersectionrrorrBrrz MagicProxy)rfZ these_magicsZ remove_magicsrrrrrr^.s   zMagicMixin._mock_set_magicsN)r5r8rhr!r^rrrrr]'sr]c@seZdZdZdddZdS)r z-A version of `MagicMock` that isn't callable.FcCs|j|||jdS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)rr^)rfrrrrrrGs z"NonCallableMagicMock.mock_add_specN)F)r5r8rhr6rrrrrr Esc@seZdZdZdddZdS)ra MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. If you use the `spec` or `spec_set` arguments then *only* magic methods that exist in the spec will be created. Attributes and the return value of a `MagicMock` will also be `MagicMocks`. FcCs|j|||jdS)zAdd a spec to a mock. `spec` can either be an object or a list of strings. Only attributes on the `spec` can be fetched as attributes from the mock. If `spec_set` is True then only attributes on the spec can be set.N)rr^)rfrrrrrr]s zMagicMock.mock_add_specN)F)r5r8rhr6rrrrrrRs c@s.eZdZddZddZddZd dd ZdS) racCs||_||_dS)N)rr)rfrrrrrr!iszMagicProxy.__init__cOs|j}|||S)N) create_mock)rfr+r,mrrrr$mszMagicProxy.__call__cCs8|j}|j}|j|||d}t|||t||||S)N)rrr)rrrrzr\)rfrrrcrrrrbqs  zMagicProxy.create_mockNcCs|jS)N)rb)rfrrrrrr0zszMagicProxy.__get__)N)r5r8rhr!r$rbr0rrrrrahs rac@s(eZdZdZddZddZddZdS) _ANYz2A helper object that compares equal to everything.cCsdS)NTr)rfrSrrrrQsz _ANY.__eq__cCsdS)NFr)rfrSrrrrVsz _ANY.__ne__cCsdS)Nzr)rfrrrrgsz _ANY.__repr__N)r5r8rhr6rQrVrgrrrrrdsrdcCsdd|}d}djdd|D}djddt|jD}|rD|}|r\|rT|d7}||7}||S)Nz%s(%%s)rz, cSsg|] }t|qSr)repr)rrrrrrsz*_format_call_signature..cSsg|]\}}d||fqS)z%s=%rr)rrrprrrrs)rrr)rr+r,rZformatted_argsZ args_stringZ kwargs_stringrrrrsrc@sveZdZdZfddddfddZfddddfdd Zd d ZejZd d Z ddZ ddZ ddZ ddZ ddZdS)ra A tuple for holding the results of a call to a mock, either in the form `(args, kwargs)` or `(name, args, kwargs)`. If args or kwargs are empty then a call tuple will compare equal to a tuple without those values. This makes comparisons less verbose:: _Call(('name', (), {})) == ('name',) _Call(('name', (1,), {})) == ('name', (1,)) _Call(((), {'a': 'b'})) == ({'a': 'b'},) The `_Call` object provides a useful shortcut for comparing with call:: _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) If the _Call has no name then it will match any name. rNFTc Csf}i}t|}|dkr$|\}}}nr|dkrd|\} } t| trX| }t| trR| }qb| }q| | }}n2|dkr|\}t|tr|}nt|tr|}n|}|rtj|||fStj||||fS)Nrrbr)rrr"r?r) rrprrr from_kallr+r,_lenfirstsecondrrrrs.      z _Call.__new__cCs||_||_||_dS)N)rvrt_mock_from_kall)rfrprrrrfrrrr!sz_Call.__init__c Csf|tkr dSy t|}Wntk r,dSXd}t|dkrH|\}}n |\}}}t|ddrzt|ddrz|j|jkrzdSd}|dkrfi}}n|dkr|\}}}n|dkr|\} t| tr| }i}n"t| tr| }fi}}nf}| }nV|dkr>|\} } t| tr2| }t| tr&| i}}n f| }}n | | }}ndS|rV||krVdS||f||fkS) NTFrrbrtrrr)rrrr<rtrr?r") rfrSZ len_otherZ self_nameZ self_argsZ self_kwargsZ other_nameZ other_argsZ other_kwargsrprhrirrrrQsP                z _Call.__eq__cOs<|jdkrtd||fddS|jd}t|j||f||dS)Nrz())r)rr)rvr)rfr+r,rrrrr$s  z_Call.__call__cCs2|jdkrt|ddSd|j|f}t||ddS)NF)rrfz%s.%s)rrrf)rvr)rfrrrrrrms  z_Call.__getattr__cOs|jd||S)Nr)rm)rfr+r,rrrr$sz _Call.countcOs|jd||S)Nindex)rm)rfr+r,rrrrk'sz _Call.indexcCs||js&|jpd}|jdr"d|}|St|dkr@d}|\}}n0|\}}}|sTd}n|jdshd|}nd|}t|||S)Nrz()zcall%srbzcall.%s)rjrvrrr)rfrr+r,rrrrg*s       z_Call.__repr__cCs8g}|}x"|dk r*|jr"|j||j}q Wtt|S)zFor a call object that represents multiple calls, `call_list` returns a list of all the intermediate calls as well as the final call.N)rjrrtrUr)rfvalsrrrr call_list?s   z_Call.call_list)r5r8rhr6rr!rQrrVr$rmrrkrgrmrrrrrs  7r)rfcKs,t|rt|}t|t}d|i}|r0d|i}n |dkr.rrxrxrxrx)rbytesr) read_dataZ data_as_listliner)rwr_iterate_read_data s  r|rcsfdd}fdd}fddtdkr`ddl}ttt|jjtt|ja|dkrttd t d }ttd j _ t dgdj _ dj_ dj_ dj_ |j_d <d j_|j_fd d}||_|_ |S)a A helper function to create a mock to replace the use of `open`. It works for `open` called directly or used as a context manager. The `mock` argument is the mock object to configure. If `None` (the default) then a `MagicMock` will be created for you, with the API limited to methods or attributes available on standard file handles. `read_data` is a string for the `read` methoddline`, and `readlines` of the file handle to return. This is an empty string by default. cs jjdk rjjStdS)Nr) readlinesrYr>)r+r,)_statehandlerr_readlines_side_effect( s z)mock_open.._readlines_side_effectcs(jjdk rjjStjdS)Nr)readrYrr)r+r,)r~rrzrr_read_side_effect- s z$mock_open.._read_side_effectc3sJjjdk rxjjVqWxdD] }|Vq&WxtVq6WdS)Nr)readlinerYr)r{)r~rrzrr_readline_side_effect2 s  z(mock_open.._readline_side_effectNropen)rr)rrcs6td<jjdkr2d<dj_tS)Nrr)r|rr_r)r+r,)rr~rrzrr reset_dataS s    zmock_open..reset_data) file_spec_ior>ror TextIOWrapperunionBytesIOrrr rYr|writerrr}r_)r1rzrrrrr)rr~rrzrr  s.  "     c@s(eZdZdZddZddZddZdS) r aW A mock intended to be used as a property, or other descriptor, on a class. `PropertyMock` provides `__get__` and `__set__` methods so you can specify a return value when it is fetched. Fetching a `PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock with the value being set. cKs tf|S)N)r)rfr,rrrri szPropertyMock._get_child_mockcCs|S)Nr)rfrZobj_typerrrr0l szPropertyMock.__get__cCs ||dS)Nr)rfrrrrrr1n szPropertyMock.__set__N)r5r8rhr6rr0r1rrrrr ` s) rrrrrrrrr r r r r )F)F)NFNNN)FFNN)Nr)o__all__ __version__r%rr builtinstypesr functoolsrrrr BaseExceptionrplatformrZlangZ Throwabler superrrr r(r4r/r=r@rErMrHrdrrerirrZMISSINGrZDELETEDrrqr|rr>rUrrrr rrrrrrrr r!r#rr$r+r-rnZmultipleZstopallrZ magic_methodsZnumericsrrZinplacerightZ _non_defaultsrr_rrrZrRrYrUrWrXr[r\r]r rrardrrr?rrrrnrrrrQr#r0rrrr|r r rrrrs     4  i5 ,   1Jv        ,  w  DPK!nԀ<<result.cpython-36.opt-1.pycnu[3 \@s\dZddlZddlZddlZddlmZddlmZdZddZ d Z d Z Gd d d e Z dS) zTest result objectN)util)wrapsTcstfdd}|S)Ncs$t|ddr|j|f||S)NfailfastF)getattrstop)selfargskw)method'/usr/lib64/python3.6/unittest/result.pyinner s zfailfast..inner)r)r rr )r r r srz Stdout: %sz Stderr: %sc@seZdZdZdZdZdZd.ddZddZdd Z d d Z d d Z ddZ ddZ ddZeddZeddZddZddZddZddZed d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)/ TestResultaHolder for test result information. Test results are automatically managed by the TestCase and TestSuite classes, and do not need to be explicitly manipulated by writers of tests. Each instance holds the total number of tests run, and collections of failures and errors that occurred among those test runs. The collections contain tuples of (testcase, exceptioninfo), where exceptioninfo is the formatted traceback of the error that occurred. NFcCsbd|_g|_g|_d|_g|_g|_g|_d|_d|_d|_ d|_ d|_ t j |_t j|_d|_dS)NFr)rfailureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses shouldStopbuffer tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr _mirrorOutput)rstreamZ descriptions verbosityr r r __init__&szTestResult.__init__cCsdS)z#Called by TestRunner after test runNr )rr r r printErrors7szTestResult.printErrorscCs |jd7_d|_|jdS)z-Called when the given test is about to be runrFN)rr _setupStdout)rtestr r r startTest:szTestResult.startTestcCs8|jr4|jdkr$tj|_tj|_|jt_|jt_dS)N)rrioStringIOrrrr)rr r r r%@s    zTestResult._setupStdoutcCsdS)zpCalled once before any tests are executed. See startTest for a method called before each test. Nr )rr r r startTestRunHszTestResult.startTestRuncCs|jd|_dS)z'Called when the given test has been runFN)_restoreStdoutr )rr&r r r stopTestNszTestResult.stopTestcCs|jr|jrltjj}tjj}|rF|jds6|d7}|jjt ||rl|jds\|d7}|j jt ||jt_|j t_|j j d|j j|jj d|jjdS)N r)rr rrgetvaluerendswithrwrite STDOUT_LINEr STDERR_LINErseektruncater)routputerrorr r r r+Ss$       zTestResult._restoreStdoutcCsdS)zmCalled once after all tests are executed. See stopTest for a method called after each test. Nr )rr r r stopTestRunhszTestResult.stopTestRuncCs"|jj||j||fd|_dS)zmCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info(). TN)rappend_exc_info_to_stringr )rr&errr r r addErrornszTestResult.addErrorcCs"|jj||j||fd|_dS)zdCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().TN)rr8r9r )rr&r:r r r addFailurevszTestResult.addFailurecCsZ|dk rVt|ddr|jt|d|jr4|j}n|j}|j||j||fd|_dS)zCalled at the end of a subtest. 'err' is None if the subtest ended successfully, otherwise it's a tuple of values as returned by sys.exc_info(). NrFrT) rr issubclassfailureExceptionrrr8r9r )rr&Zsubtestr:rr r r addSubTest}s zTestResult.addSubTestcCsdS)z-Called when a test has completed successfullyNr )rr&r r r addSuccessszTestResult.addSuccesscCs|jj||fdS)zCalled when a test is skipped.N)rr8)rr&reasonr r r addSkipszTestResult.addSkipcCs|jj||j||fdS)z/Called when an expected failure/error occurred.N)rr8r9)rr&r:r r r addExpectedFailureszTestResult.addExpectedFailurecCs|jj|dS)z5Called when a test was expected to fail, but succeed.N)rr8)rr&r r r addUnexpectedSuccessszTestResult.addUnexpectedSuccesscCs>t|jt|jkodknoConverts a sys.exc_info()-style tuple of values into a string.N)limitcapture_localsr-)_is_relevant_tb_leveltb_nextr>_count_relevant_tb_levels tracebackTracebackExceptionrlistformatrrrr.rr/r8r1r2join) rr:r&exctypevaluetblengthZtb_eZmsgLinesr5r6r r r r9s*         zTestResult._exc_info_to_stringcCs d|jjkS)N __unittest)tb_frame f_globals)rrUr r r rKsz TestResult._is_relevant_tb_levelcCs,d}x"|r&|j| r&|d7}|j}qW|S)Nrr)rKrL)rrUrVr r r rMs  z$TestResult._count_relevant_tb_levelscCs&dtj|j|jt|jt|jfS)Nz!<%s run=%i errors=%i failures=%i>)rZstrclass __class__rrErr)rr r r __repr__szTestResult.__repr__)NNN)__name__ __module__ __qualname____doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr#r$r'r%r*r,r+r7rr;r<r?r@rBrCrDrGrr9rKrMr[r r r r rs2      r)r_r(rrNrJr functoolsrrWrr1r2objectrr r r r s  PK!p4result.cpython-36.opt-2.pycnu[3 \@sXddlZddlZddlZddlmZddlmZdZddZdZ d Z Gd d d e Z dS) N)util)wrapsTcstfdd}|S)Ncs$t|ddr|j|f||S)NfailfastF)getattrstop)selfargskw)method'/usr/lib64/python3.6/unittest/result.pyinner s zfailfast..inner)r)r rr )r r r srz Stdout: %sz Stderr: %sc@seZdZdZdZdZd-ddZddZddZd d Z d d Z d dZ ddZ ddZ eddZeddZddZddZddZddZedd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,ZdS). TestResultNFcCsbd|_g|_g|_d|_g|_g|_g|_d|_d|_d|_ d|_ d|_ t j |_t j|_d|_dS)NFr)rfailureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses shouldStopbuffer tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr _mirrorOutput)rstreamZ descriptions verbosityr r r __init__&szTestResult.__init__cCsdS)Nr )rr r r printErrors7szTestResult.printErrorscCs |jd7_d|_|jdS)NrF)rr _setupStdout)rtestr r r startTest:szTestResult.startTestcCs8|jr4|jdkr$tj|_tj|_|jt_|jt_dS)N)rrioStringIOrrrr)rr r r r%@s    zTestResult._setupStdoutcCsdS)Nr )rr r r startTestRunHszTestResult.startTestRuncCs|jd|_dS)NF)_restoreStdoutr )rr&r r r stopTestNszTestResult.stopTestcCs|jr|jrltjj}tjj}|rF|jds6|d7}|jjt ||rl|jds\|d7}|j jt ||jt_|j t_|j j d|j j|jj d|jjdS)N r)rr rrgetvaluerendswithrwrite STDOUT_LINEr STDERR_LINErseektruncater)routputerrorr r r r+Ss$       zTestResult._restoreStdoutcCsdS)Nr )rr r r stopTestRunhszTestResult.stopTestRuncCs"|jj||j||fd|_dS)NT)rappend_exc_info_to_stringr )rr&errr r r addErrornszTestResult.addErrorcCs"|jj||j||fd|_dS)NT)rr8r9r )rr&r:r r r addFailurevszTestResult.addFailurecCsZ|dk rVt|ddr|jt|d|jr4|j}n|j}|j||j||fd|_dS)NrFrT) rr issubclassfailureExceptionrrr8r9r )rr&Zsubtestr:rr r r addSubTest}s zTestResult.addSubTestcCsdS)Nr )rr&r r r addSuccessszTestResult.addSuccesscCs|jj||fdS)N)rr8)rr&reasonr r r addSkipszTestResult.addSkipcCs|jj||j||fdS)N)rr8r9)rr&r:r r r addExpectedFailureszTestResult.addExpectedFailurecCs|jj|dS)N)rr8)rr&r r r addUnexpectedSuccessszTestResult.addUnexpectedSuccesscCs>t|jt|jkodkno_count_relevant_tb_levels tracebackTracebackExceptionrlistformatrrrr.rr/r8r1r2join) rr:r&exctypevaluetblengthZtb_eZmsgLinesr5r6r r r r9s*         zTestResult._exc_info_to_stringcCs d|jjkS)N __unittest)tb_frame f_globals)rrUr r r rKsz TestResult._is_relevant_tb_levelcCs,d}x"|r&|j| r&|d7}|j}qW|S)Nrr)rKrL)rrUrVr r r rMs  z$TestResult._count_relevant_tb_levelscCs&dtj|j|jt|jt|jfS)Nz!<%s run=%i errors=%i failures=%i>)rZstrclass __class__rrErr)rr r r __repr__szTestResult.__repr__)NNN)__name__ __module__ __qualname__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr#r$r'r%r*r,r+r7rr;r<r?r@rBrCrDrGrr9rKrMr[r r r r rs0      r) r(rrNrJr functoolsrrWrr1r2objectrr r r r s  PK!nԀ<<result.cpython-36.pycnu[3 \@s\dZddlZddlZddlZddlmZddlmZdZddZ d Z d Z Gd d d e Z dS) zTest result objectN)util)wrapsTcstfdd}|S)Ncs$t|ddr|j|f||S)NfailfastF)getattrstop)selfargskw)method'/usr/lib64/python3.6/unittest/result.pyinner s zfailfast..inner)r)r rr )r r r srz Stdout: %sz Stderr: %sc@seZdZdZdZdZdZd.ddZddZdd Z d d Z d d Z ddZ ddZ ddZeddZeddZddZddZddZddZed d!Zd"d#Zd$d%Zd&d'Zd(d)Zd*d+Zd,d-ZdS)/ TestResultaHolder for test result information. Test results are automatically managed by the TestCase and TestSuite classes, and do not need to be explicitly manipulated by writers of tests. Each instance holds the total number of tests run, and collections of failures and errors that occurred among those test runs. The collections contain tuples of (testcase, exceptioninfo), where exceptioninfo is the formatted traceback of the error that occurred. NFcCsbd|_g|_g|_d|_g|_g|_g|_d|_d|_d|_ d|_ d|_ t j |_t j|_d|_dS)NFr)rfailureserrorstestsRunskippedexpectedFailuresunexpectedSuccesses shouldStopbuffer tb_locals_stdout_buffer_stderr_buffersysstdout_original_stdoutstderr_original_stderr _mirrorOutput)rstreamZ descriptions verbosityr r r __init__&szTestResult.__init__cCsdS)z#Called by TestRunner after test runNr )rr r r printErrors7szTestResult.printErrorscCs |jd7_d|_|jdS)z-Called when the given test is about to be runrFN)rr _setupStdout)rtestr r r startTest:szTestResult.startTestcCs8|jr4|jdkr$tj|_tj|_|jt_|jt_dS)N)rrioStringIOrrrr)rr r r r%@s    zTestResult._setupStdoutcCsdS)zpCalled once before any tests are executed. See startTest for a method called before each test. Nr )rr r r startTestRunHszTestResult.startTestRuncCs|jd|_dS)z'Called when the given test has been runFN)_restoreStdoutr )rr&r r r stopTestNszTestResult.stopTestcCs|jr|jrltjj}tjj}|rF|jds6|d7}|jjt ||rl|jds\|d7}|j jt ||jt_|j t_|j j d|j j|jj d|jjdS)N r)rr rrgetvaluerendswithrwrite STDOUT_LINEr STDERR_LINErseektruncater)routputerrorr r r r+Ss$       zTestResult._restoreStdoutcCsdS)zmCalled once after all tests are executed. See stopTest for a method called after each test. Nr )rr r r stopTestRunhszTestResult.stopTestRuncCs"|jj||j||fd|_dS)zmCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info(). TN)rappend_exc_info_to_stringr )rr&errr r r addErrornszTestResult.addErrorcCs"|jj||j||fd|_dS)zdCalled when an error has occurred. 'err' is a tuple of values as returned by sys.exc_info().TN)rr8r9r )rr&r:r r r addFailurevszTestResult.addFailurecCsZ|dk rVt|ddr|jt|d|jr4|j}n|j}|j||j||fd|_dS)zCalled at the end of a subtest. 'err' is None if the subtest ended successfully, otherwise it's a tuple of values as returned by sys.exc_info(). NrFrT) rr issubclassfailureExceptionrrr8r9r )rr&Zsubtestr:rr r r addSubTest}s zTestResult.addSubTestcCsdS)z-Called when a test has completed successfullyNr )rr&r r r addSuccessszTestResult.addSuccesscCs|jj||fdS)zCalled when a test is skipped.N)rr8)rr&reasonr r r addSkipszTestResult.addSkipcCs|jj||j||fdS)z/Called when an expected failure/error occurred.N)rr8r9)rr&r:r r r addExpectedFailureszTestResult.addExpectedFailurecCs|jj|dS)z5Called when a test was expected to fail, but succeed.N)rr8)rr&r r r addUnexpectedSuccessszTestResult.addUnexpectedSuccesscCs>t|jt|jkodknoConverts a sys.exc_info()-style tuple of values into a string.N)limitcapture_localsr-)_is_relevant_tb_leveltb_nextr>_count_relevant_tb_levels tracebackTracebackExceptionrlistformatrrrr.rr/r8r1r2join) rr:r&exctypevaluetblengthZtb_eZmsgLinesr5r6r r r r9s*         zTestResult._exc_info_to_stringcCs d|jjkS)N __unittest)tb_frame f_globals)rrUr r r rKsz TestResult._is_relevant_tb_levelcCs,d}x"|r&|j| r&|d7}|j}qW|S)Nrr)rKrL)rrUrVr r r rMs  z$TestResult._count_relevant_tb_levelscCs&dtj|j|jt|jt|jfS)Nz!<%s run=%i errors=%i failures=%i>)rZstrclass __class__rrErr)rr r r __repr__szTestResult.__repr__)NNN)__name__ __module__ __qualname____doc__Z_previousTestClassZ_testRunEnteredZ_moduleSetUpFailedr#r$r'r%r*r,r+r7rr;r<r?r@rBrCrDrGrr9rKrMr[r r r r rs2      r)r_r(rrNrJr functoolsrrWrr1r2objectrr r r r s  PK!kHrunner.cpython-36.opt-1.pycnu[3 \G@sndZddlZddlZddlZddlmZddlmZdZGddde Z Gd d d ej Z Gd d d e Z dS) z Running testsN)result)registerResultTc@s*eZdZdZddZddZd ddZdS) _WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodcCs ||_dS)N)stream)selfrr'/usr/lib64/python3.6/unittest/runner.py__init__sz_WritelnDecorator.__init__cCs|dkrt|t|j|S)Nr __getstate__)rr )AttributeErrorgetattrr)rattrrrr __getattr__sz_WritelnDecorator.__getattr__NcCs|r|j||jddS)N )write)rargrrr writelns z_WritelnDecorator.writeln)N)__name__ __module__ __qualname____doc__r rrrrrr r srcseZdZdZddZddZfddZddZfd d Zfd d Z fd dZ fddZ fddZ fddZ fddZddZddZZS)TextTestResultzhA test result class that can print formatted text results to a stream. Used by TextTestRunner. =F-cs8tt|j|||||_|dk|_|dk|_||_dS)Nr)superrr rshowAlldots descriptions)rrr verbosity) __class__rr r %s   zTextTestResult.__init__cCs0|j}|jr$|r$djt||fSt|SdS)Nr)ZshortDescriptionrjoinstr)rtestZdoc_first_linerrr getDescription,s zTextTestResult.getDescriptioncsBtt|j||jr>|jj|j||jjd|jjdS)Nz ... )rr startTestrrrr%flush)rr$)r!rr r&3s  zTextTestResult.startTestcsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nok.) rr addSuccessrrrrrr')rr$)r!rr r*:s  zTextTestResult.addSuccesscsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NERRORE) rraddErrorrrrrrr')rr$err)r!rr r-Bs  zTextTestResult.addErrorcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NFAILF) rr addFailurerrrrrr')rr$r.)r!rr r1Js  zTextTestResult.addFailurecsLtt|j|||jr,|jjdj|n|jrH|jjd|jj dS)Nz skipped {0!r}s) rraddSkiprrrformatrrr')rr$reason)r!rr r3Rs  zTextTestResult.addSkipcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)Nzexpected failurex) rraddExpectedFailurerrrrrr')rr$r.)r!rr r7Zs  z!TextTestResult.addExpectedFailurecsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nzunexpected successu) rraddUnexpectedSuccessrrrrrr')rr$)r!rr r9bs  z#TextTestResult.addUnexpectedSuccesscCs6|js |jr|jj|jd|j|jd|jdS)Nr+r/)rrrrprintErrorListerrorsfailures)rrrr printErrorsjs  zTextTestResult.printErrorscCs\xV|D]N\}}|jj|j|jjd||j|f|jj|j|jjd|qWdS)Nz%s: %sz%s)rr separator1r% separator2)rZflavourr;r$r.rrr r:ps zTextTestResult.printErrorList)rrrrr>r?r r%r&r*r-r1r3r7r9r=r: __classcell__rr)r!r rs        rc@s4eZdZdZeZd ddddZd d Zd d ZdS)TextTestRunnerzA test runner class that displays results in textual form. It prints out the names of tests as they are run, errors as they occur, and a summary of the results at the end of the test run. NTrF) tb_localsc CsN|dkrtj}t||_||_||_||_||_||_||_ |dk rJ||_ dS)zConstruct a TextTestRunner. Subclasses should accept **kwargs to ensure compatibility as the interface changes. N) sysstderrrrrr failfastbufferrBwarnings resultclass) rrrr rErFrHrGrBrrr r s zTextTestRunner.__init__cCs|j|j|j|jS)N)rHrrr )rrrr _makeResultszTextTestRunner._makeResultcCs4|j}t||j|_|j|_|j|_tj|jr^tj|j|jdkr^tjdt ddt j }t |dd}|dk r|z ||Wdt |dd}|dk r|Xt j }WdQRX||}|j t |d r|jj|j|j}|jjd ||d krd pd |f|jjd} } } ytt|j|j|jf} Wntk rVYn X| \} } } g} |js|jjdt|jt|j}}|r| jd||r| jd|n |jjd| r| jd| | r| jd| | r| jd| | r$|jjddj| fn |jjd|S)z&Run the given test case or test suite.defaultalwaysmodulezPlease use assert\w+ instead.)categorymessage startTestRunN stopTestRunr?zRan %d test%s in %.3fsrr2rZFAILEDz failures=%dz errors=%dZOKz skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r)rJrK)rIrrErFrBrGcatch_warnings simplefilterfilterwarningsDeprecationWarningtimer r=hasattrrrr?ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr Z wasSuccessfulrr<r;appendr")rr$rZ startTimerOrPZstopTimeZ timeTakenrunZ expectedFailsrZr[ZresultsZinfosZfailedZerroredrrr r]sr              zTextTestRunner.run)NTrFFNN) rrrrrrHr rIr]rrrr rAxsrA)rrCrVrGrQrZsignalsrZ __unittestobjectrZ TestResultrrArrrr s  [PK!T`aarunner.cpython-36.opt-2.pycnu[3 \G@sjddlZddlZddlZddlmZddlmZdZGdddeZ Gdd d ej Z Gd d d eZ dS) N)result)registerResultTc@s&eZdZddZddZdddZdS) _WritelnDecoratorcCs ||_dS)N)stream)selfrr'/usr/lib64/python3.6/unittest/runner.py__init__sz_WritelnDecorator.__init__cCs|dkrt|t|j|S)Nr __getstate__)rr )AttributeErrorgetattrr)rattrrrr __getattr__sz_WritelnDecorator.__getattr__NcCs|r|j||jddS)N )write)rargrrr writelns z_WritelnDecorator.writeln)N)__name__ __module__ __qualname__r rrrrrr r srcseZdZddZddZfddZddZfdd Zfd d Zfd d Z fddZ fddZ fddZ fddZ ddZddZZS)TextTestResult=F-cs8tt|j|||||_|dk|_|dk|_||_dS)Nr)superrr rshowAlldots descriptions)rrr verbosity) __class__rr r %s   zTextTestResult.__init__cCs0|j}|jr$|r$djt||fSt|SdS)Nr)ZshortDescriptionrjoinstr)rtestZdoc_first_linerrr getDescription,s zTextTestResult.getDescriptioncsBtt|j||jr>|jj|j||jjd|jjdS)Nz ... )rr startTestrrrr$flush)rr#)r rr r%3s  zTextTestResult.startTestcsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nok.) rr addSuccessrrrrrr&)rr#)r rr r):s  zTextTestResult.addSuccesscsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NERRORE) rraddErrorrrrrrr&)rr#err)r rr r,Bs  zTextTestResult.addErrorcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NFAILF) rr addFailurerrrrrr&)rr#r-)r rr r0Js  zTextTestResult.addFailurecsLtt|j|||jr,|jjdj|n|jrH|jjd|jj dS)Nz skipped {0!r}s) rraddSkiprrrformatrrr&)rr#reason)r rr r2Rs  zTextTestResult.addSkipcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)Nzexpected failurex) rraddExpectedFailurerrrrrr&)rr#r-)r rr r6Zs  z!TextTestResult.addExpectedFailurecsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nzunexpected successu) rraddUnexpectedSuccessrrrrrr&)rr#)r rr r8bs  z#TextTestResult.addUnexpectedSuccesscCs6|js |jr|jj|jd|j|jd|jdS)Nr*r.)rrrrprintErrorListerrorsfailures)rrrr printErrorsjs  zTextTestResult.printErrorscCs\xV|D]N\}}|jj|j|jjd||j|f|jj|j|jjd|qWdS)Nz%s: %sz%s)rr separator1r$ separator2)rZflavourr:r#r-rrr r9ps zTextTestResult.printErrorList)rrrr=r>r r$r%r)r,r0r2r6r8r<r9 __classcell__rr)r r rs        rc@s0eZdZeZd ddddZdd Zd d ZdS) TextTestRunnerNTrF) tb_localsc CsN|dkrtj}t||_||_||_||_||_||_||_ |dk rJ||_ dS)N) sysstderrrrrrfailfastbufferrAwarnings resultclass) rrrrrDrErGrFrArrr r s zTextTestRunner.__init__cCs|j|j|j|jS)N)rGrrr)rrrr _makeResultszTextTestRunner._makeResultcCs4|j}t||j|_|j|_|j|_tj|jr^tj|j|jdkr^tjdt ddt j }t |dd}|dk r|z ||Wdt |dd}|dk r|Xt j }WdQRX||}|j t |dr|jj|j|j}|jjd ||d krd pd |f|jjd } } } ytt|j|j|jf} Wntk rVYn X| \} } } g} |js|jjdt|jt|j}}|r| jd||r| jd|n |jjd| r| jd| | r| jd| | r| jd| | r$|jjddj| fn |jjd|S)NdefaultalwaysmodulezPlease use assert\w+ instead.)categorymessage startTestRun stopTestRunr>zRan %d test%s in %.3fsrr1rZFAILEDz failures=%dz errors=%dZOKz skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r)rIrJ)rHrrDrErArFcatch_warnings simplefilterfilterwarningsDeprecationWarningtimer r<hasattrrrr>ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr Z wasSuccessfulrr;r:appendr!)rr#rZ startTimerNrOZstopTimeZ timeTakenrunZ expectedFailsrYrZZresultsZinfosZfailedZerroredrrr r\sr              zTextTestRunner.run)NTrFFNN)rrrrrGr rHr\rrrr r@xs r@) rBrUrFrPrZsignalsrZ __unittestobjectrZ TestResultrr@rrrr s  [PK!kHrunner.cpython-36.pycnu[3 \G@sndZddlZddlZddlZddlmZddlmZdZGddde Z Gd d d ej Z Gd d d e Z dS) z Running testsN)result)registerResultTc@s*eZdZdZddZddZd ddZdS) _WritelnDecoratorz@Used to decorate file-like objects with a handy 'writeln' methodcCs ||_dS)N)stream)selfrr'/usr/lib64/python3.6/unittest/runner.py__init__sz_WritelnDecorator.__init__cCs|dkrt|t|j|S)Nr __getstate__)rr )AttributeErrorgetattrr)rattrrrr __getattr__sz_WritelnDecorator.__getattr__NcCs|r|j||jddS)N )write)rargrrr writelns z_WritelnDecorator.writeln)N)__name__ __module__ __qualname____doc__r rrrrrr r srcseZdZdZddZddZfddZddZfd d Zfd d Z fd dZ fddZ fddZ fddZ fddZddZddZZS)TextTestResultzhA test result class that can print formatted text results to a stream. Used by TextTestRunner. =F-cs8tt|j|||||_|dk|_|dk|_||_dS)Nr)superrr rshowAlldots descriptions)rrr verbosity) __class__rr r %s   zTextTestResult.__init__cCs0|j}|jr$|r$djt||fSt|SdS)Nr)ZshortDescriptionrjoinstr)rtestZdoc_first_linerrr getDescription,s zTextTestResult.getDescriptioncsBtt|j||jr>|jj|j||jjd|jjdS)Nz ... )rr startTestrrrr%flush)rr$)r!rr r&3s  zTextTestResult.startTestcsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nok.) rr addSuccessrrrrrr')rr$)r!rr r*:s  zTextTestResult.addSuccesscsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NERRORE) rraddErrorrrrrrr')rr$err)r!rr r-Bs  zTextTestResult.addErrorcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)NFAILF) rr addFailurerrrrrr')rr$r.)r!rr r1Js  zTextTestResult.addFailurecsLtt|j|||jr,|jjdj|n|jrH|jjd|jj dS)Nz skipped {0!r}s) rraddSkiprrrformatrrr')rr$reason)r!rr r3Rs  zTextTestResult.addSkipcsFtt|j|||jr&|jjdn|jrB|jjd|jjdS)Nzexpected failurex) rraddExpectedFailurerrrrrr')rr$r.)r!rr r7Zs  z!TextTestResult.addExpectedFailurecsDtt|j||jr$|jjdn|jr@|jjd|jjdS)Nzunexpected successu) rraddUnexpectedSuccessrrrrrr')rr$)r!rr r9bs  z#TextTestResult.addUnexpectedSuccesscCs6|js |jr|jj|jd|j|jd|jdS)Nr+r/)rrrrprintErrorListerrorsfailures)rrrr printErrorsjs  zTextTestResult.printErrorscCs\xV|D]N\}}|jj|j|jjd||j|f|jj|j|jjd|qWdS)Nz%s: %sz%s)rr separator1r% separator2)rZflavourr;r$r.rrr r:ps zTextTestResult.printErrorList)rrrrr>r?r r%r&r*r-r1r3r7r9r=r: __classcell__rr)r!r rs        rc@s4eZdZdZeZd ddddZd d Zd d ZdS)TextTestRunnerzA test runner class that displays results in textual form. It prints out the names of tests as they are run, errors as they occur, and a summary of the results at the end of the test run. NTrF) tb_localsc CsN|dkrtj}t||_||_||_||_||_||_||_ |dk rJ||_ dS)zConstruct a TextTestRunner. Subclasses should accept **kwargs to ensure compatibility as the interface changes. N) sysstderrrrrr failfastbufferrBwarnings resultclass) rrrr rErFrHrGrBrrr r s zTextTestRunner.__init__cCs|j|j|j|jS)N)rHrrr )rrrr _makeResultszTextTestRunner._makeResultcCs4|j}t||j|_|j|_|j|_tj|jr^tj|j|jdkr^tjdt ddt j }t |dd}|dk r|z ||Wdt |dd}|dk r|Xt j }WdQRX||}|j t |d r|jj|j|j}|jjd ||d krd pd |f|jjd} } } ytt|j|j|jf} Wntk rVYn X| \} } } g} |js|jjdt|jt|j}}|r| jd||r| jd|n |jjd| r| jd| | r| jd| | r| jd| | r$|jjddj| fn |jjd|S)z&Run the given test case or test suite.defaultalwaysmodulezPlease use assert\w+ instead.)categorymessage startTestRunN stopTestRunr?zRan %d test%s in %.3fsrr2rZFAILEDz failures=%dz errors=%dZOKz skipped=%dzexpected failures=%dzunexpected successes=%dz (%s)z, r)rJrK)rIrrErFrBrGcatch_warnings simplefilterfilterwarningsDeprecationWarningtimer r=hasattrrrr?ZtestsRunmaplenZexpectedFailuresunexpectedSuccessesskippedr Z wasSuccessfulrr<r;appendr")rr$rZ startTimerOrPZstopTimeZ timeTakenrunZ expectedFailsrZr[ZresultsZinfosZfailedZerroredrrr r]sr              zTextTestRunner.run)NTrFFNN) rrrrrrHr rIr]rrrr rAxsrA)rrCrVrGrQrZsignalsrZ __unittestobjectrZ TestResultrrArrrr s  [PK!~~signals.cpython-36.opt-1.pycnu[3 \c @sbddlZddlZddlmZdZGdddeZejZddZ dd Z da d d Z dd d Z dS)N)wrapsTc@seZdZddZddZdS)_InterruptHandlercCsNd|_||_t|trD|tjkr(tj}n|tjkr.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object) calledoriginal_handler isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN TypeErrorr)selfrrrr__init__ s    z_InterruptHandler.__init__cCsVtjtj}||k r |j|||jr2|j||d|_xtjD] }|jqBWdS)NT)r getsignalSIGINTrr_resultskeysstop)rZsignumframeZinstalled_handlerresultrrr__call__s   z_InterruptHandler.__call__N)__name__ __module__ __qualname__rrrrrrr srcCs dt|<dS)N)r)rrrrregisterResult*srcCsttj|dS)N)boolrpop)rrrr removeResult-sr!cCs.tdkr*tjtj}t|atjtjtdS)N)_interrupt_handlerr rrr)rrrrinstallHandler1s r#cs<dk r tfdd}|Stdk r8tjtjtjdS)Nc s2tjtj}tz ||Stjtj|XdS)N)r rr removeHandler)argskwargsinitial)methodrrinner;s   zremoveHandler..inner)rr"r rr)r(r)r)r(rr$9s r$)N)r weakref functoolsrZ __unittestobjectrWeakKeyDictionaryrrr!r"r#r$rrrrs  PK!~~signals.cpython-36.opt-2.pycnu[3 \c @sbddlZddlZddlmZdZGdddeZejZddZ dd Z da d d Z dd d Z dS)N)wrapsTc@seZdZddZddZdS)_InterruptHandlercCsNd|_||_t|trD|tjkr(tj}n|tjkr.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object) calledoriginal_handler isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN TypeErrorr)selfrrrr__init__ s    z_InterruptHandler.__init__cCsVtjtj}||k r |j|||jr2|j||d|_xtjD] }|jqBWdS)NT)r getsignalSIGINTrr_resultskeysstop)rZsignumframeZinstalled_handlerresultrrr__call__s   z_InterruptHandler.__call__N)__name__ __module__ __qualname__rrrrrrr srcCs dt|<dS)N)r)rrrrregisterResult*srcCsttj|dS)N)boolrpop)rrrr removeResult-sr!cCs.tdkr*tjtj}t|atjtjtdS)N)_interrupt_handlerr rrr)rrrrinstallHandler1s r#cs<dk r tfdd}|Stdk r8tjtjtjdS)Nc s2tjtj}tz ||Stjtj|XdS)N)r rr removeHandler)argskwargsinitial)methodrrinner;s   zremoveHandler..inner)rr"r rr)r(r)r)r(rr$9s r$)N)r weakref functoolsrZ __unittestobjectrWeakKeyDictionaryrrr!r"r#r$rrrrs  PK!~~signals.cpython-36.pycnu[3 \c @sbddlZddlZddlmZdZGdddeZejZddZ dd Z da d d Z dd d Z dS)N)wrapsTc@seZdZddZddZdS)_InterruptHandlercCsNd|_||_t|trD|tjkr(tj}n|tjkr.default_handlerzYexpected SIGINT signal handler to be signal.SIG_IGN, signal.SIG_DFL, or a callable object) calledoriginal_handler isinstanceintsignalSIG_DFLdefault_int_handlerSIG_IGN TypeErrorr)selfrrrr__init__ s    z_InterruptHandler.__init__cCsVtjtj}||k r |j|||jr2|j||d|_xtjD] }|jqBWdS)NT)r getsignalSIGINTrr_resultskeysstop)rZsignumframeZinstalled_handlerresultrrr__call__s   z_InterruptHandler.__call__N)__name__ __module__ __qualname__rrrrrrr srcCs dt|<dS)N)r)rrrrregisterResult*srcCsttj|dS)N)boolrpop)rrrr removeResult-sr!cCs.tdkr*tjtj}t|atjtjtdS)N)_interrupt_handlerr rrr)rrrrinstallHandler1s r#cs<dk r tfdd}|Stdk r8tjtjtjdS)Nc s2tjtj}tz ||Stjtj|XdS)N)r rr removeHandler)argskwargsinitial)methodrrinner;s   zremoveHandler..inner)rr"r rr)r(r)r)r(rr$9s r$)N)r weakref functoolsrZ __unittestobjectrWeakKeyDictionaryrrr!r"r#r$rrrrs  PK!ZZ##suite.cpython-36.opt-1.pycnu[3 \(@s|dZddlZddlmZddlmZdZddZGd d d eZGd ddeZ Gd d d eZ ddZ GdddeZ dS) TestSuiteN)case)utilTcCst||dd}|dS)NcSsdS)Nrrr&/usr/lib64/python3.6/unittest/suite.py sz!_call_if_exists..)getattr)parentattrfuncrrr_call_if_exists sr c@speZdZdZdZffddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZdS) BaseTestSuitezNA simple test suite that doesn't provide class or module shared fixtures. TcCsg|_d|_|j|dS)Nr)_tests_removed_testsaddTests)selftestsrrr__init__szBaseTestSuite.__init__cCsdtj|jt|fS)Nz <%s tests=%s>)rstrclass __class__list)rrrr__repr__szBaseTestSuite.__repr__cCs t||jstSt|t|kS)N) isinstancerNotImplementedr)rotherrrr__eq__s zBaseTestSuite.__eq__cCs t|jS)N)iterr)rrrr__iter__"szBaseTestSuite.__iter__cCs(|j}x|D]}|r ||j7}q W|S)N)rcountTestCases)rZcasestestrrrr%s  zBaseTestSuite.countTestCasescCsLt|stdjt|t|trdSt|ddrNdSt|dd}|dk rt|dz^y |WnNtk r}z2t|trtj|}d|}|j|||WYdd}~XnXWdt|d XdS) NrAr;Fr<rD tearDownClassrFztearDownClass (%s)rG) r rr rHrrCrrrI) rr r.rJrKr[rLrMrNrrrr>s,         $z TestSuite._tearDownPreviousClassN)F) r6r7r8r9r0r5r@rPr?rIrBr>rrrrr\s ! c@sTeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ dS)rWz Placeholder for a TestCase inside a result. As far as a TestResult is concerned, this looks exactly like a unit test. Used to insert arbitrary errors into a test suite run. NcCs ||_dS)N) description)rr\rrrrsz_ErrorHolder.__init__cCs|jS)N)r\)rrrridsz_ErrorHolder.idcCsdS)Nr)rrrrshortDescription sz_ErrorHolder.shortDescriptioncCs d|jfS)Nz)r\)rrrrr#sz_ErrorHolder.__repr__cCs|jS)N)r])rrrr__str__&sz_ErrorHolder.__str__cCsdS)Nr)rr.rrrr0)sz_ErrorHolder.runcCs |j|S)N)r0)rr.rrrr4.sz_ErrorHolder.__call__cCsdS)Nrr)rrrrr1sz_ErrorHolder.countTestCases) r6r7r8r9ZfailureExceptionrr]r^rr_r0r4rrrrrrWsrWc Cs&y t|Wntk r dSXdS)z?A crude way to tell apart testcases and suites with duck-typingTF)rr")r rrrr=4s  r=c@seZdZdZdZdZdZdS)rCzCUsed by the TestSuite to hold previous class when running in debug.NF)r6r7r8r9rAr<r+rrrrrC=srC) r9rRrrZ __unittestr objectrrrWr=rCrrrrs  L3& PK!چsuite.cpython-36.opt-2.pycnu[3 \(@sxddlZddlmZddlmZdZddZGdd d eZGd d d eZGd d d eZ ddZ GdddeZ dS)N)case)utilTcCst||dd}|dS)NcSsdS)Nrrr&/usr/lib64/python3.6/unittest/suite.py sz!_call_if_exists..)getattr)parentattrfuncrrr_call_if_exists sr c@sleZdZdZffddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS) BaseTestSuiteTcCsg|_d|_|j|dS)Nr)_tests_removed_testsaddTests)selftestsrrr__init__szBaseTestSuite.__init__cCsdtj|jt|fS)Nz <%s tests=%s>)rstrclass __class__list)rrrr__repr__szBaseTestSuite.__repr__cCs t||jstSt|t|kS)N) isinstancerNotImplementedr)rotherrrr__eq__s zBaseTestSuite.__eq__cCs t|jS)N)iterr)rrrr__iter__"szBaseTestSuite.__iter__cCs(|j}x|D]}|r ||j7}q W|S)N)rcountTestCases)rZcasestestrrrr%s  zBaseTestSuite.countTestCasescCsLt|stdjt|t|trs,      $zTestSuite._handleModuleFixturecCsLt|}t|dd}|dk r8t|tjr8||t|n|j|tjdS)NaddSkip) _ErrorHolderrrrZSkipTestr)ZaddErrorrQexc_info)rr.Z exceptionrMerrorrUrrrrHs  z)TestSuite._addClassOrModuleLevelExceptionc Cs|j|}|dkrdS|jr dSytj|}Wntk rBdSXt|dd}|dk rt|dzTy |WnDtk r}z(t|t rd|}|j |||WYdd}~XnXWdt|dXdS)NtearDownModulerEztearDownModule (%s)rF) rOr;rQrRrSrr rGrrBrH)rr.rNrTrYrKrMrrrrAs(     $zTestSuite._handleModuleTearDownc Cst|dd}|j}||krdSt|ddr.dSt|ddr>dSt|ddrNdSt|dd}|dk rt|dz^y |WnNtk r}z2t|trtj|}d|}|j|||WYdd}~XnXWdt|d XdS) Nr@r:Fr;rC tearDownClassrEztearDownClass (%s)rF) rrr rGrrBrrrH) rrr.rIrJrZrKrLrMrrrr=s,         $z TestSuite._tearDownPreviousClassN)F) r6r7r8r0r5r?rOr>rHrAr=rrrrr&\s ! r&c@sPeZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dS)rVNcCs ||_dS)N) description)rr[rrrrsz_ErrorHolder.__init__cCs|jS)N)r[)rrrridsz_ErrorHolder.idcCsdS)Nr)rrrrshortDescription sz_ErrorHolder.shortDescriptioncCs d|jfS)Nz)r[)rrrrr#sz_ErrorHolder.__repr__cCs|jS)N)r\)rrrr__str__&sz_ErrorHolder.__str__cCsdS)Nr)rr.rrrr0)sz_ErrorHolder.runcCs |j|S)N)r0)rr.rrrr4.sz_ErrorHolder.__call__cCsdS)Nrr)rrrrr1sz_ErrorHolder.countTestCases) r6r7r8ZfailureExceptionrr\r]rr^r0r4rrrrrrVs rVc Cs&y t|Wntk r dSXdS)NTF)rr!)rrrrr<4s  r<c@seZdZdZdZdZdS)rBNF)r6r7r8r@r;r+rrrrrB=srB) rQrrZ __unittestr objectr r&rVr<rBrrrrs  L3& PK!ZZ##suite.cpython-36.pycnu[3 \(@s|dZddlZddlmZddlmZdZddZGd d d eZGd ddeZ Gd d d eZ ddZ GdddeZ dS) TestSuiteN)case)utilTcCst||dd}|dS)NcSsdS)Nrrr&/usr/lib64/python3.6/unittest/suite.py sz!_call_if_exists..)getattr)parentattrfuncrrr_call_if_exists sr c@speZdZdZdZffddZddZddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZdS) BaseTestSuitezNA simple test suite that doesn't provide class or module shared fixtures. TcCsg|_d|_|j|dS)Nr)_tests_removed_testsaddTests)selftestsrrr__init__szBaseTestSuite.__init__cCsdtj|jt|fS)Nz <%s tests=%s>)rstrclass __class__list)rrrr__repr__szBaseTestSuite.__repr__cCs t||jstSt|t|kS)N) isinstancerNotImplementedr)rotherrrr__eq__s zBaseTestSuite.__eq__cCs t|jS)N)iterr)rrrr__iter__"szBaseTestSuite.__iter__cCs(|j}x|D]}|r ||j7}q W|S)N)rcountTestCases)rZcasestestrrrr%s  zBaseTestSuite.countTestCasescCsLt|stdjt|t|trdSt|ddrNdSt|dd}|dk rt|dz^y |WnNtk r}z2t|trtj|}d|}|j|||WYdd}~XnXWdt|d XdS) NrAr;Fr<rD tearDownClassrFztearDownClass (%s)rG) r rr rHrrCrrrI) rr r.rJrKr[rLrMrNrrrr>s,         $z TestSuite._tearDownPreviousClassN)F) r6r7r8r9r0r5r@rPr?rIrBr>rrrrr\s ! c@sTeZdZdZdZddZddZddZd d Zd d Z d dZ ddZ ddZ dS)rWz Placeholder for a TestCase inside a result. As far as a TestResult is concerned, this looks exactly like a unit test. Used to insert arbitrary errors into a test suite run. NcCs ||_dS)N) description)rr\rrrrsz_ErrorHolder.__init__cCs|jS)N)r\)rrrridsz_ErrorHolder.idcCsdS)Nr)rrrrshortDescription sz_ErrorHolder.shortDescriptioncCs d|jfS)Nz)r\)rrrrr#sz_ErrorHolder.__repr__cCs|jS)N)r])rrrr__str__&sz_ErrorHolder.__str__cCsdS)Nr)rr.rrrr0)sz_ErrorHolder.runcCs |j|S)N)r0)rr.rrrr4.sz_ErrorHolder.__call__cCsdS)Nrr)rrrrr1sz_ErrorHolder.countTestCases) r6r7r8r9ZfailureExceptionrr]r^rr_r0r4rrrrrrWsrWc Cs&y t|Wntk r dSXdS)z?A crude way to tell apart testcases and suites with duck-typingTF)rr")r rrrr=4s  r=c@seZdZdZdZdZdZdS)rCzCUsed by the TestSuite to hold previous class when running in debug.NF)r6r7r8r9rAr<r+rrrrrC=srC) r9rRrrZ __unittestr objectrrrWr=rCrrrrs  L3& PK!ZSPPutil.cpython-36.opt-1.pycnu[3 \9@sdZddlmZmZddlmZdZdZdZdZ dZ dZ ee ee ee Z dd Z d d Zd d dZddZddZddZddZeddZddZddZddZdS)!zVarious utility functions.) namedtuple OrderedDict) commonprefixTP cCsBt|||}|tkr>d|d|||t||df}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlenZ suffixlenskipr %/usr/lib64/python3.6/unittest/util.py_shortens&rcsttt|}ttt|}|tkr(|St|tt|tt}|t krxt t|tfdd|DSt tt tfdd|DS)Nc3s|]}|dVqdS)Nr ).0r )prefixr r r 'sz'_common_shorten_repr..c3s&|]}t|dttVqdS)N)r _MIN_DIFF_LEN _MIN_END_LEN)rr )rr r rr*s) tuplemap safe_reprmaxr _MAX_LENGTHr_MIN_BEGIN_LENr _MIN_COMMON_LENr)argsmaxlenZ common_lenr )rr r_common_shorten_reprs  rFc CsRy t|}Wntk r*tj|}YnX| s>t|tkrB|S|dtdS)Nz [truncated]...)repr Exceptionobject__repr__rr)objZshortresultr r rr-s rcCsd|j|jfS)Nz%s.%s) __module__ __qualname__)clsr r rstrclass6sr(cCs*d}}g}g}xy||}||}||kr\|j||d7}x|||krX|d7}qBWn||kr|j||d7}xf|||kr|d7}qxWnL|d7}zx|||kr|d7}qWWd|d7}x|||kr|d7}qWXWqtk r|j||d|j||dPYqXqW||fS)arFinds elements in only one or the other of two, sorted input lists. Returns a two-element tuple of lists. The first list contains those elements in the "expected" list but not in the "actual" list, and the second contains those elements in the "actual" list but not in the "expected" list. Duplicate elements in either input list are ignored. rN)append IndexErrorextend)expectedactualijmissingZ unexpectedear r rsorted_list_difference9s:   r4c CsLg}x>|rB|j}y|j|Wqtk r>|j|YqXqW||fS)zSame behavior as sorted_list_difference but for lists of unorderable items (like dicts). As it does a linear search per item (remove) it has O(n*n) performance.)popremove ValueErrorr*)r-r.r1itemr r runorderable_list_differencebsr9cCs||k||kS)z.Return -1 if x < y, 0 if x == y and 1 if x > yr )xyr r r three_way_cmpssr<ZMismatchzactual expected valuecCsDt|t|}}t|t|}}t}g}xt|D]\}} | |krJq8d} } x.t||D] } || | kr^| d7} ||| <q^Wx,t|D] \} } | | kr| d7} ||| <qW| | kr8t| | | }|j|q8Wxlt|D]`\}} | |krqd} x2t||D]$} || | kr| d7} ||| <qWtd| | }|j|qW|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differrr))listrr! enumeraterange _Mismatchr*)r.r-r tmnZNULLr$r/elemcnt_scnt_tr0Z other_elemdiffr r r_count_diff_all_purposeys<     rHcCs,t}x |D]}|j|dd||<q W|S)z@Return dict of element counts, in the order they were first seenrr))rget)iterablecrDr r r_ordered_counts rLc Cst|t|}}g}x>|jD]2\}}|j|d}||kr t|||}|j|q Wx2|jD]&\}}||kr`td||}|j|q`W|S)zHReturns list of (cnt_act, cnt_exp, elem) triples where the counts differr)rLitemsrIr@r*) r.r-r rAr$rDrErFrGr r r_count_diff_hashables   rNN)F)__doc__ collectionsrrZos.pathrZ __unittestrr rrrrrrrr(r4r9r<r@rHrLrNr r r rs*  ) #PK!tputil.cpython-36.opt-2.pycnu[3 \9@sddlmZmZddlmZdZdZdZdZdZ dZ eeee ee Z ddZ d d Z dd d ZddZddZddZddZeddZddZddZddZdS) ) namedtuple OrderedDict) commonprefixTP cCsBt|||}|tkr>d|d|||t||df}|S)Nz%s[%d chars]%s)len_PLACEHOLDER_LEN)s prefixlenZ suffixlenskipr %/usr/lib64/python3.6/unittest/util.py_shortens&rcsttt|}ttt|}|tkr(|St|tt|tt}|t krxt t|tfdd|DSt tt tfdd|DS)Nc3s|]}|dVqdS)Nr ).0r )prefixr r r 'sz'_common_shorten_repr..c3s&|]}t|dttVqdS)N)r _MIN_DIFF_LEN _MIN_END_LEN)rr )rr r rr*s) tuplemap safe_reprmaxr _MAX_LENGTHr_MIN_BEGIN_LENr _MIN_COMMON_LENr)argsmaxlenZ common_lenr )rr r_common_shorten_reprs  rFc CsRy t|}Wntk r*tj|}YnX| s>t|tkrB|S|dtdS)Nz [truncated]...)repr Exceptionobject__repr__rr)objZshortresultr r rr-s rcCsd|j|jfS)Nz%s.%s) __module__ __qualname__)clsr r rstrclass6sr(cCs*d}}g}g}xy||}||}||kr\|j||d7}x|||krX|d7}qBWn||kr|j||d7}xf|||kr|d7}qxWnL|d7}zx|||kr|d7}qWWd|d7}x|||kr|d7}qWXWqtk r|j||d|j||dPYqXqW||fS)Nr)append IndexErrorextend)expectedactualijmissingZ unexpectedear r rsorted_list_difference9s:   r4c CsLg}x>|rB|j}y|j|Wqtk r>|j|YqXqW||fS)N)popremove ValueErrorr*)r-r.r1itemr r runorderable_list_differencebsr9cCs||k||kS)Nr )xyr r r three_way_cmpssr<ZMismatchzactual expected valuecCsDt|t|}}t|t|}}t}g}xt|D]\}} | |krJq8d} } x.t||D] } || | kr^| d7} ||| <q^Wx,t|D] \} } | | kr| d7} ||| <qW| | kr8t| | | }|j|q8Wxlt|D]`\}} | |krqd} x2t||D]$} || | kr| d7} ||| <qWtd| | }|j|qW|S)Nrr))listrr! enumeraterange _Mismatchr*)r.r-r tmnZNULLr$r/elemcnt_scnt_tr0Z other_elemdiffr r r_count_diff_all_purposeys<     rHcCs,t}x |D]}|j|dd||<q W|S)Nrr))rget)iterablecrDr r r_ordered_counts rLc Cst|t|}}g}x>|jD]2\}}|j|d}||kr t|||}|j|q Wx2|jD]&\}}||kr`td||}|j|q`W|S)Nr)rLitemsrIr@r*) r.r-r rAr$rDrErFrGr r r_count_diff_hashables   rNN)F) collectionsrrZos.pathrZ __unittestrr rrrrrrrr(r4r9r<r@rHrLrNr r r rs(  ) #PK!Yo__init__.cpython-311.opt-1.pycnu[ !A?h-dZgdZdS)aCore XML support for Python. This package contains four sub-packages: dom -- The W3C Document Object Model. This supports DOM Level 1 + Namespaces. parsers -- Python wrappers for XML parsers (currently only supports Expat). sax -- The Simple API for XML, developed by XML-Dev, led by David Megginson and ported to Python by Lars Marius Garshol. This supports the SAX 2 API. etree -- The ElementTree XML library. This is a subset of the full ElementTree XML release. )domparserssaxetreeN)__doc____all__%/usr/lib64/python3.11/xml/__init__.pyr s & - , ,r PK!\ZW__init__.cpython-311.opt-2.pycnu[ !A?h- gdZdS))domparserssaxetreeN)__all__%/usr/lib64/python3.11/xml/__init__.pyr s& - , ,rPK!Yo__init__.cpython-311.pycnu[ !A?h-dZgdZdS)aCore XML support for Python. This package contains four sub-packages: dom -- The W3C Document Object Model. This supports DOM Level 1 + Namespaces. parsers -- Python wrappers for XML parsers (currently only supports Expat). sax -- The Simple API for XML, developed by XML-Dev, led by David Megginson and ported to Python by Lars Marius Garshol. This supports the SAX 2 API. etree -- The ElementTree XML library. This is a subset of the full ElementTree XML release. )domparserssaxetreeN)__doc____all__%/usr/lib64/python3.11/xml/__init__.pyr s & - , ,r PK!&%util.cpython-36.pycnu[PK!u __init__.cpython-36.opt-1.pycnu[PK!kR__init__.cpython-36.opt-2.pycnu[PK!u !$__init__.cpython-36.pycnu[PK!v?10__main__.cpython-36.opt-1.pycnu[PK!ݥ~~2__main__.cpython-36.opt-2.pycnu[PK!v?3__main__.cpython-36.pycnu[PK!0ĻĻ5case.cpython-36.opt-1.pycnu[PK!+!case.cpython-36.opt-2.pycnu[PK!(rcase.cpython-36.pycnu[PK!Fk955.loader.cpython-36.opt-1.pycnu[PK!bC+C+eloader.cpython-36.opt-2.pycnu[PK!,6,6loader.cpython-36.pycnu[PK!vffmain.cpython-36.opt-1.pycnu[PK!egmain.cpython-36.opt-2.pycnu[PK!vffmain.cpython-36.pycnu[PK!g"\\Ymock.cpython-36.opt-1.pycnu[PK!+eQdd mock.cpython-36.opt-2.pycnu[PK!g"\\mock.cpython-36.pycnu[PK!nԀ<<Jresult.cpython-36.opt-1.pycnu[PK!p4result.cpython-36.opt-2.pycnu[PK!nԀ<<result.cpython-36.pycnu[PK!kHrunner.cpython-36.opt-1.pycnu[PK!T`aarunner.cpython-36.opt-2.pycnu[PK!kH\4runner.cpython-36.pycnu[PK!~~kOsignals.cpython-36.opt-1.pycnu[PK!~~5Xsignals.cpython-36.opt-2.pycnu[PK!~~`signals.cpython-36.pycnu[PK!ZZ##isuite.cpython-36.opt-1.pycnu[PK!چsuite.cpython-36.opt-2.pycnu[PK!ZZ##ӭsuite.cpython-36.pycnu[PK!ZSPPutil.cpython-36.opt-1.pycnu[PK!tputil.cpython-36.opt-2.pycnu[PK!Yo__init__.cpython-311.opt-1.pycnu[PK!\ZW__init__.cpython-311.opt-2.pycnu[PK!Yo__init__.cpython-311.pycnu[PK$$ &