Your IP : 18.227.183.161


Current Path : /usr/lib64/python3.8/unittest/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/unittest/__pycache__/case.cpython-38.pyc

U

e5d���@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZdZe�ZdZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�Zdd�ZgZdd�Zdd�Z dd�Z!dd�Z"dd�Z#dd�Z$dd�Z%Gd d!�d!�Z&Gd"d#�d#e&�Z'Gd$d%�d%e'�Z(Gd&d'�d'e'�Z)e�*d(d)d*g�Z+Gd+d,�d,ej,�Z-Gd-d.�d.e&�Z.Gd/d0�d0ej/�Z0Gd1d2�d2e�Z1Gd3d4�d4e1�Z2Gd5d6�d6e1�Z3dS)7zTest case implementation�N�)�result)�strclass�	safe_repr�_count_diff_all_purpose�_count_diff_hashable�_common_shorten_reprTz@
Diff is %s characters long. Set self.maxDiff to None to see it.c@seZdZdZdS)�SkipTestz�
    Raise this exception in a test to skip it.

    Usually you can use TestCase.skipTest() or one of the skipping decorators
    instead of raising this directly.
    N��__name__�
__module__�__qualname__�__doc__�rr�%/usr/lib64/python3.8/unittest/case.pyr	sr	c@seZdZdZdS)�_ShouldStopz
    The test should stop.
    Nr
rrrrr"src@seZdZdZdS)�_UnexpectedSuccessz7
    The test was supposed to fail, but it didn't!
    Nr
rrrrr'src@s&eZdZddd�Zejddd��ZdS)	�_OutcomeNcCs4d|_||_t|d�|_d|_g|_d|_g|_dS)NF�
addSubTestT)�expecting_failurer�hasattr�result_supports_subtests�success�skipped�expectedFailure�errors)�selfrrrr�__init__.sz_Outcome.__init__Fc
cs�|j}d|_z�z
dVWn�tk
r.�Yn�tk
rh}zd|_|j�|t|�f�W5d}~XYnjtk
rzYnXt��}|j	r�||_
nd|_|j�||f�d}YnX|jr�|jr�|j�|df�W5|jo�||_XdS)NTF)
r�KeyboardInterruptr	r�append�strr�sys�exc_inforrrr)r�	test_case�isTestZold_success�er"rrr�testPartExecutor7s*
$
z_Outcome.testPartExecutor)N)F)rrr
r�
contextlib�contextmanagerr&rrrrr-s
	rcCs|S�Nr)�objrrr�_idUsr+cOst�|||f�dS)znSame as addCleanup, except the cleanup items are called even if
    setUpModule fails (unlike tearDownModule).N)�_module_cleanupsr)�function�args�kwargsrrr�addModuleCleanupZsr0c
Csdg}trTt��\}}}z|||�Wqtk
rP}z|�|�W5d}~XYqXq|r`|d�dS)zWExecute all module cleanup functions. Normally called for you after
    tearDownModule.Nr)r,�pop�	Exceptionr)�
exceptionsr-r.r/�excrrr�doModuleCleanups`sr5cs,�fdd�}t�tj�r(�}d�||�S|S)z&
    Unconditionally skip a test.
    cs4t|t�s$t�|��fdd��}|}d|_�|_|S)Ncst���dSr)�r	�r.r/��reasonrr�skip_wrappervsz-skip.<locals>.decorator.<locals>.skip_wrapperT)�
isinstance�type�	functools�wraps�__unittest_skip__�__unittest_skip_why__)�	test_itemr:r8rr�	decoratorts
zskip.<locals>.decorator�)r;�types�FunctionType)r9rBrArr8r�skipps
rFcCs|rt|�StS)z/
    Skip a test if the condition is true.
    �rFr+�Z	conditionr9rrr�skipIf�srIcCs|st|�StS)z3
    Skip a test unless the condition is true.
    rGrHrrr�
skipUnless�srJcCs
d|_|S)NT)�__unittest_expecting_failure__)rArrrr�srcs4t|t�r t�fdd�|D��St|t�o2t|��S)Nc3s|]}t|��VqdSr))�_is_subtype)�.0r%��basetyperr�	<genexpr>�sz_is_subtype.<locals>.<genexpr>)r;�tuple�allr<�
issubclass)�expectedrOrrNrrL�s
rLc@seZdZdd�Zdd�ZdS)�_BaseTestCaseContextcCs
||_dSr))r#)rr#rrrr�sz_BaseTestCaseContext.__init__cCs |j�|j|�}|j�|��dSr))r#�_formatMessage�msg�failureException)r�standardMsgrWrrr�
_raiseFailure�sz"_BaseTestCaseContext._raiseFailureN)rrr
rrZrrrrrU�srUc@seZdZddd�Zdd�ZdS)�_AssertRaisesBaseContextNcCs@t�||�||_||_|dk	r*t�|�}||_d|_d|_dSr))	rUrrTr#�re�compile�expected_regex�obj_namerW)rrTr#r^rrrr�s
z!_AssertRaisesBaseContext.__init__c	Cs�z�t|j|j�s"td||jf��|sV|�dd�|_|rNtdtt|��f��|W�TS|^}}z|j	|_
Wntk
r�t|�|_
YnX|�|||�W5QRXW5d}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.
        Nz%s() arg 1 must be %srWz3%r is an invalid keyword argument for this function)
rLrT�
_base_type�	TypeError�_base_type_strr1rW�next�iterrr_�AttributeErrorr )r�namer.r/Zcallable_objrrr�handle�s(��z_AssertRaisesBaseContext.handle)N)rrr
rrgrrrrr[�s

r[c@s(eZdZdZeZdZdd�Zdd�ZdS)�_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-an exception type or tuple of exception typescCs|Sr)r�rrrr�	__enter__�sz_AssertRaisesContext.__enter__cCs�|dkrbz|jj}Wntk
r2t|j�}YnX|jrP|�d�||j��ql|�d�|��n
t�|�t	||j�s|dS|�
d�|_|jdkr�dS|j}|�
t|��s�|�d�|jt|���dS)Nz{} not raised by {}z
{} not raisedFT�"{}" does not match "{}")rTrrer r_rZ�format�	traceback�clear_framesrS�with_tracebackZ	exceptionr^�search�pattern)r�exc_type�	exc_value�tb�exc_namer^rrr�__exit__�s.
�

�z_AssertRaisesContext.__exit__N)	rrr
r�
BaseExceptionr`rbrjrvrrrrrh�s
rhc@s(eZdZdZeZdZdd�Zdd�ZdS)�_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRttj���D]}t|dd�ri|_qtjdd�|_|j�	�|_t�
d|j�|S)N�__warningregistry__T)�record�always)�listr!�modules�values�getattrry�warnings�catch_warnings�warnings_managerrj�simplefilterrT)r�vrrrrj�sz_AssertWarnsContext.__enter__cCs|j�|||�|dk	rdSz|jj}Wntk
rFt|j�}YnXd}|jD]Z}|j}t||j�sjqR|dkrv|}|j	dk	r�|j	�
t|��s�qR||_|j|_|j
|_
dS|dk	r�|�d�|j	jt|���|jr�|�d�||j��n|�d�|��dS)Nrkz{} not triggered by {}z{} not triggered)r�rvrTrrer r��messager;r^rpZwarning�filename�linenorZrlrqr_)rrrrsrtruZfirst_matching�m�wrrrrvs@

��
�z_AssertWarnsContext.__exit__N)	rrr
r�Warningr`rbrjrvrrrrrx�s
rx�_LoggingWatcher�records�outputc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_CapturingHandlerzM
    A logging handler capturing all (raw and formatted) logging output.
    cCstj�|�tgg�|_dSr))�logging�Handlerrr��watcherrirrrr3sz_CapturingHandler.__init__cCsdSr)rrirrr�flush7sz_CapturingHandler.flushcCs*|jj�|�|�|�}|jj�|�dSr))r�r�rrlr�)rrzrWrrr�emit:s
z_CapturingHandler.emitN)rrr
rrr�r�rrrrr�.sr�c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�_AssertLogsContextz:A context manager used to implement TestCase.assertLogs().z"%(levelname)s:%(name)s:%(message)scCs:t�||�||_|r(tj�||�|_ntj|_d|_dSr))	rUr�logger_namer�Z_nameToLevel�get�level�INFOrW)rr#r�r�rrrrFsz_AssertLogsContext.__init__cCs�t|jtj�r|j}|_nt�|j�}|_t�|j�}t�}|�	|�|j
|_
|jdd�|_|j
|_|j|_|g|_|�|j
�d|_|j
S)NF)r;r�r�ZLogger�loggerZ	getLoggerZ	Formatter�LOGGING_FORMATr�ZsetFormatterr��handlers�old_handlersr��	old_level�	propagate�
old_propagate�setLevel)rr�Z	formatterZhandlerrrrrjOs
z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|j�|j�|dk	r.dSt|jj	�dkr\|�
d�t�
|j�|jj��dS)NFrz-no logs of level {} or higher triggered on {})r�r�r�r�r�r�r��lenr�r�rZrlr�ZgetLevelNamer�rf)rrrrsrtrrrrv`s


��z_AssertLogsContext.__exit__N)rrr
rr�rrjrvrrrrr�As
	r�c@seZdZdd�ZdS)�_OrderedChainMapccs8t�}|jD]&}|D]}||kr|�|�|VqqdSr))�set�maps�add)r�seen�mapping�krrr�__iter__ns

z_OrderedChainMap.__iter__N)rrr
r�rrrrr�msr�c@seZdZdZeZdZdZdZdZ	gZ
d�dd�Zd	d
�Zdd�Z
d
e
_edd��Zdd�Zdd�Zedd��Zedd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zeje fd*d+��Z!d,d-�Z"d.d/�Z#d0d1�Z$d2d3�Z%d4d5�Z&d6d7�Z'd8d9�Z(d�d;d<�Z)d=d>�Z*ed?d@��Z+dAdB�Z,dCdD�Z-dEdF�Z.d�dGdH�Z/d�dIdJ�Z0d�dKdL�Z1dMdN�Z2dOdP�Z3dQdR�Z4d�dSdT�Z5dUdV�Z6d�dWdX�Z7d�dYdZ�Z8d�d[d\�Z9d�d]d^�Z:d�d_d`�Z;d�dadb�Z<dcdd�Z=d�dedf�Z>d�dgdh�Z?d�didj�Z@d�dkdl�ZAd�dmdn�ZBd�dodp�ZCd�dqdr�ZDd�dsdt�ZEd�dudv�ZFd�dwdx�ZGd�dydz�ZHd�d{d|�ZId�d}d~�ZJd�dd��ZKd�d�d��ZLd�d�d��ZMd�d�d��ZNd�d�d��ZOd�d�d��ZPd�d��ZQd�d��ZRd�d�d��ZSd�d�d��ZTd�d��ZUeUe8�ZVZWeUe9�ZXZYeUe:�ZZZ[eUe;�Z\Z]eUe1�Z^Z_eUe3�Z`eUe0�ZaeUeQ�ZbeUeS�ZceUeT�Zdd:S)��TestCaseaWA class whose instances are single test cases.

    By default, the test code itself should be placed in a method named
    'runTest'.

    If the fixture may be used for many test cases, create as
    many test methods as are needed. When instantiating such a TestCase
    subclass, specify in the constructor arguments the name of the test method
    that the instance is to execute.

    Test authors should subclass TestCase for their own tests. Construction
    and deconstruction of the test's environment ('fixture') can be
    implemented by overriding the 'setUp' and 'tearDown' methods respectively.

    If it is necessary to override the __init__ method, the base class
    __init__ method must always be called. It is important that subclasses
    should not change the signature of their __init__ method, since instances
    of the classes are instantiated automatically by parts of the framework
    in order to be run.

    When subclassing TestCase, you can set these attributes:
    * failureException: determines which exception will be raised when
        the instance's assertion methods fail; test methods raising this
        exception will be deemed to have 'failed' rather than 'errored'.
    * longMessage: determines whether long messages (including repr of
        objects used in assert methods) will be printed on failure in *addition*
        to any explicit message passed.
    * maxDiff: sets the maximum length of a diff in failure messages
        by assert methods using difflib. It is looked up as an instance
        attribute so can be configured by individual tests if required.
    Ti�iF�runTestcCs�||_d|_d|_zt||�}Wn.tk
rN|dkrJtd|j|f��Yn
X|j|_g|_d|_	i|_
|�td�|�t
d�|�td�|�td�|�td�|�td	�dS)
z�Create an instance of the class that will use the named test
           method when executed. Raises a ValueError if the instance does
           not have a method with the specified name.
        NzNo testr�zno such test method in %s: %s�assertDictEqual�assertListEqual�assertTupleEqual�assertSetEqual�assertMultiLineEqual)�_testMethodName�_outcome�_testMethodDocrre�
ValueError�	__class__r�	_cleanups�_subtest�_type_equality_funcs�addTypeEqualityFunc�dictr|rQr��	frozensetr )rZ
methodName�
testMethodrrrr�s(�zTestCase.__init__cCs||j|<dS)a[Add a type specific assertEqual style function to compare a type.

        This method is for use by TestCase subclasses that need to register
        their own type equality functions to provide nicer error messages.

        Args:
            typeobj: The data type to call this function on when both values
                    are of the same type in assertEqual().
            function: The callable taking two arguments and an optional
                    msg= argument that raises self.failureException with a
                    useful error message when the two arguments are not equal.
        N)r�)rZtypeobjr-rrrr��s
zTestCase.addTypeEqualityFunccOs�t|�dkr|^}}}nV|s&td��nHd|krZ|�d�}|^}}ddl}|jdtdd�ntdt|�d	��t|�}|j�|||f�dS)
aAdd a function, with arguments, to be called when the test is
        completed. Functions added are called on a LIFO basis and are
        called after tearDown on test failure or success.

        Cleanup items are called even if setUp fails (unlike tearDown).�z>descriptor 'addCleanup' of 'TestCase' object needs an argumentr-rNz4Passing 'function' as keyword argument is deprecated)�
stacklevelz:addCleanup expected at least 1 positional argument, got %dr)	r�rar1r��warn�DeprecationWarningrQr�r)r.r/rr-r�rrr�
addCleanup�s"

�
�zTestCase.addCleanupz%($self, function, /, *args, **kwargs)cOs|j�|||f�dS)zpSame as addCleanup, except the cleanup items are called even if
        setUpClass fails (unlike tearDownClass).N)�_class_cleanupsr)�clsr-r.r/rrr�addClassCleanup�szTestCase.addClassCleanupcCsdS)zAHook method for setting up the test fixture before exercising it.Nrrirrr�setUp�szTestCase.setUpcCsdS)zAHook method for deconstructing the test fixture after testing it.Nrrirrr�tearDown�szTestCase.tearDowncCsdS)zKHook method for setting up class fixture before running tests in the class.Nr�r�rrr�
setUpClass�szTestCase.setUpClasscCsdS)zVHook method for deconstructing the class fixture after running all tests in the class.Nrr�rrr�
tearDownClassszTestCase.tearDownClasscCsdS)Nrrrirrr�countTestCasesszTestCase.countTestCasescCst��Sr))rZ
TestResultrirrr�defaultTestResult	szTestCase.defaultTestResultcCs$|j}|r |���d�d��SdS)z�Returns a one-line description of the test, or None if no
        description has been provided.

        The default implementation of this method returns the first line of
        the specified test method's docstring.
        �
rN)r��strip�split�r�docrrr�shortDescriptionszTestCase.shortDescriptioncCsdt|j�|jfS)Nz%s.%s�rr�r�rirrr�idszTestCase.idcCs t|�t|�k	rtS|j|jkSr))r<�NotImplementedr��r�otherrrr�__eq__szTestCase.__eq__cCstt|�|jf�Sr))�hashr<r�rirrr�__hash__ szTestCase.__hash__cCsd|jt|j�fS�Nz%s (%s))r�rr�rirrr�__str__#szTestCase.__str__cCsdt|j�|jfS)Nz<%s testMethod=%s>r�rirrr�__repr__&s�zTestCase.__repr__cCs<t|dd�}|dk	r |||�nt�dtd�|�|�dS)N�addSkipz4TestResult has no addSkip method, skips not reportedr�)rr�r��RuntimeWarning�
addSuccess)rrr#r9r�rrr�_addSkip*s�zTestCase._addSkipc	ks�|jdks|jjsdVdS|j}|dkr4t|�}n|j�|�}t|||�|_zX|jj|jdd��dVW5QRX|jjs�|jj	}|dk	r�|j
r�t�n|jjr�t�W5||_XdS)aPReturn a context manager that will return the enclosed block
        of code in a subtest identified by the optional message and
        keyword parameters.  A failure in the subtest marks the test
        case as failed but resumes execution at the end of the enclosed
        block, allowing further test code to be executed.
        NT�r$)
r�rr�r��params�	new_child�_SubTestr&rrZfailfastrr)rrWr��parentZ
params_maprrrr�subTest3s$
zTestCase.subTestcCs`|D]V\}}t|t�r(|�|j||�q|dk	rt|d|j�rN|�||�q|�||�qdS)Nr)r;r�rr#rSrX�
addFailureZaddError)rrr�testr"rrr�_feedErrorsToResultRs
zTestCase._feedErrorsToResultcCsDz
|j}Wn*tk
r4t�dt�|�|�YnX|||�dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)�addExpectedFailurerer�r�r�r�)rrr"r�rrr�_addExpectedFailure\s
�zTestCase._addExpectedFailurecCshz
|j}WnPtk
rZt�dt�z
td�Wn$tk
rT|�|t���YnXYn
X||�dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	�addUnexpectedSuccessrer�r�r�rr�r!r")rrr�rrr�_addUnexpectedSuccessfs
�
zTestCase._addUnexpectedSuccesscCs|��dSr))r�rirrr�
_callSetUpuszTestCase._callSetUpcCs
|�dSr)r)r�methodrrr�_callTestMethodxszTestCase._callTestMethodcCs|��dSr))r�rirrr�
_callTearDown{szTestCase._callTearDowncOs|||�dSr)r�rr-r.r/rrr�_callCleanup~szTestCase._callCleanupNc

Cs|}|dkr.|��}t|dd�}|dk	r.|�|�|�t||j�}t|jdd�s^t|dd�r�z,t|jdd�pxt|dd�}|�|||�W5|�|�XdSt|dd�}t|dd�}|p�|}t|�}	z�|	|_|	�|��|�
�W5QRX|	j�r@||	_|	j|dd	��|�|�W5QRXd|	_|	�|��|��W5QRX|��|	jD]\}}|�|||��qN|�||	j�|	j�r�|�r�|	j
�r�|�||	j
�n
|�|�n
|�|�|W�S|�|�|dk�r�t|dd�}
|
dk	�r�|
�|	j�	�d|	_
d|_XdS)
N�startTestRunr?Fr@rCrK�stopTestRunTr�)r�rZ	startTestr�r�ZstopTestr�rr�clearrr�r&r�rrr�r��
doCleanupsrr�r�r�r�)
rrZorig_resultr�r�Zskip_whyZexpecting_failure_methodZexpecting_failure_classr�outcomer�r�r9rrr�run�st

�
���




zTestCase.runc	CsR|jp
t�}|jrL|j��\}}}|�|��|j|f|�|�W5QRXq|jS)zNExecute all cleanup functions. Normally called for you after
        tearDown.)r�rr�r1r&r�r)rr�r-r.r/rrrr��szTestCase.doCleanupsc
Csdg|_|jr`|j��\}}}z|||�Wqtk
r\}z|j�t���W5d}~XYqXqdS)zYExecute all class cleanup functions. Normally called for you after
        tearDownClass.N)ZtearDown_exceptionsr�r1r2rr!r")r�r-r.r/r4rrr�doClassCleanups�szTestCase.doClassCleanupscOs|j||�Sr))r�)rr.�kwdsrrr�__call__�szTestCase.__call__cCsF|��t||j��|��|jrB|j�d�\}}}|||�qdS)z6Run the test without collecting errors in a TestResult���N)r�rr�r�r�r1r�rrr�debug�szTestCase.debugcCst|��dS)zSkip this test.Nr6)rr9rrr�skipTest�szTestCase.skipTestcCs|�|��dS)z)Fail immediately, with the given message.N)rX)rrWrrr�fail�sz
TestCase.failcCs&|r"|�|dt|��}|�|��dS)z#Check that the expression is false.z%s is not falseN�rVrrX�r�exprrWrrr�assertFalse�szTestCase.assertFalsecCs&|s"|�|dt|��}|�|��dS)z"Check that the expression is true.z%s is not trueNrrrrr�
assertTrue�szTestCase.assertTruecCsV|js|p|S|dkr|Szd||fWStk
rPdt|�t|�fYSXdS)a�Honour the longMessage attribute when generating failure messages.
        If longMessage is False this means:
        * Use only an explicit message if it is provided
        * Otherwise use the standard message for the assert

        If longMessage is True:
        * Use the standard message
        * If an explicit message is provided, plus ' : ' and the explicit message
        Nz%s : %s)�longMessage�UnicodeDecodeErrorr)rrWrYrrrrV�s
zTestCase._formatMessagecOs(t||�}z|�d||�W�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)
        N�assertRaises�rhrg)r�expected_exceptionr.r/�contextrrrrs
zTestCase.assertRaisescOst||�}|�d||�S)a�Fail unless a warning of class warnClass is triggered
           by the callable when invoked with specified positional and
           keyword arguments.  If a different type of warning is
           triggered, it will not be handled: depending on the other
           warning filtering rules in effect, it might be silenced, printed
           out, or raised as an exception.

           If called with the callable and arguments omitted, will return a
           context object used like this::

                with self.assertWarns(SomeWarning):
                    do_something()

           An optional keyword argument 'msg' can be provided when assertWarns
           is used as a context object.

           The context manager keeps a reference to the first matching
           warning as the 'warning' attribute; similarly, the 'filename'
           and 'lineno' attributes give you information about the line
           of Python code from which the warning was triggered.
           This allows you to inspect the warning after the assertion::

               with self.assertWarns(SomeWarning) as cm:
                   do_something()
               the_warning = cm.warning
               self.assertEqual(the_warning.some_attribute, 147)
        �assertWarns�rxrg)r�expected_warningr.r/rrrrr5s
zTestCase.assertWarnscCst|||�S)a�Fail unless a log message of level *level* or higher is emitted
        on *logger_name* or its children.  If omitted, *level* defaults to
        INFO and *logger* defaults to the root logger.

        This method must be used as a context manager, and will yield
        a recording object with two attributes: `output` and `records`.
        At the end of the context manager, the `output` attribute will
        be a list of the matching formatted log messages and the
        `records` attribute will be a list of the corresponding LogRecord
        objects.

        Example::

            with self.assertLogs('foo', level='INFO') as cm:
                logging.getLogger('foo').info('first message')
                logging.getLogger('foo.bar').error('second message')
            self.assertEqual(cm.output, ['INFO:foo:first message',
                                         'ERROR:foo.bar:second message'])
        )r�)rr�r�rrr�
assertLogsTszTestCase.assertLogscCsFt|�t|�kr@|j�t|��}|dk	r@t|t�r<t||�}|S|jS)aGet a detailed comparison function for the types of the two args.

        Returns: A callable accepting (first, second, msg=None) that will
        raise a failure exception if first != second with a useful human
        readable error message for those types.
        N)r<r�r�r;r r�_baseAssertEqual)r�first�secondZasserterrrr�_getAssertEqualityFuncjs

zTestCase._getAssertEqualityFunccCs0||ks,dt||�}|�||�}|�|��dS)z:The default assertEqual implementation, not type specific.�%s != %sN)rrVrX)rrrrWrYrrrr�szTestCase._baseAssertEqualcCs|�||�}||||d�dS)z[Fail if the two objects are unequal as determined by the '=='
           operator.
        )rWN)r)rrrrWZassertion_funcrrr�assertEqual�szTestCase.assertEqualcCs2||ks.|�|dt|�t|�f�}|�|��dS)zYFail if the two objects are equal as determined by the '!='
           operator.
        z%s == %sNr)rrrrWrrr�assertNotEqual�s
�zTestCase.assertNotEqualcCs�||krdS|dk	r$|dk	r$td��t||�}|dk	rf||krDdSdt|�t|�t|�t|�f}n:|dkrrd}t||�dkr�dSdt|�t|�|t|�f}|�||�}|�|��dS)a'Fail if the two objects are unequal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is more than the given
           delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           If the two objects compare equal then they will automatically
           compare almost equal.
        N� specify delta or places not bothz(%s != %s within %s delta (%s difference)�rz)%s != %s within %r places (%s difference)�ra�absr�roundrVrX�rrrZplacesrWZdelta�diffrYrrr�assertAlmostEqual�s4��zTestCase.assertAlmostEqualcCs�|dk	r|dk	rtd��t||�}|dk	rb||ks@||kr@dSdt|�t|�t|�t|�f}n<|dkrnd}||ks�t||�dkr�dSdt|�t|�|f}|�||�}|�|��dS)a�Fail if the two objects are equal as determined by their
           difference rounded to the given number of decimal places
           (default 7) and comparing to zero, or by comparing that the
           difference between the two objects is less than the given delta.

           Note that decimal places (from zero) are usually not the same
           as significant digits (measured from the most significant digit).

           Objects that are equal automatically fail.
        Nrz(%s == %s within %s delta (%s difference)rrz%s == %s within %r placesrrrrr�assertNotAlmostEqual�s,��zTestCase.assertNotAlmostEqualcCs�|dk	rP|j}t||�s.|�d|t|�f��t||�sT|�d|t|�f��nd}d}zt|�}Wn ttfk
r�d|}YnX|dkr�zt|�}Wn ttfk
r�d|}YnX|dk�r�||kr�dSd|��ft||�}t	t
||��D]�}	z||	}
Wn4tttfk
�r<|d|	|f7}Y�q�YnXz||	}Wn4tttfk
�r~|d	|	|f7}Y�q�YnX|
|kr�|d
|	ft|
|�7}�q�q�||k�r�|dk�r�t|�t|�k�r�dS||k�r<|d|||f7}z|d|t||�f7}Wn,tttfk
�r8|d
||f7}YnXnh||k�r�|d|||f7}z|d|t||�f7}Wn,tttfk
�r�|d||f7}YnX|}dd�
t�t�|���t�|�����}
|�||
�}|�||�}|�|�dS)aAAn equality assertion for ordered sequences (like lists and tuples).

        For the purposes of this function, a valid ordered sequence type is one
        which can be indexed, has a length, and has an equality operator.

        Args:
            seq1: The first sequence to compare.
            seq2: The second sequence to compare.
            seq_type: The expected datatype of the sequences, or None if no
                    datatype should be enforced.
            msg: Optional message to use on failure instead of a list of
                    differences.
        NzFirst sequence is not a %s: %szSecond sequence is not a %s: %sZsequencez(First %s has no length.    Non-sequence?z)Second %s has no length.    Non-sequence?z%ss differ: %s != %s
z(
Unable to index element %d of first %s
z)
Unable to index element %d of second %s
z#
First differing element %d:
%s
%s
z+
First %s contains %d additional elements.
zFirst extra element %d:
%s
z'Unable to index element %d of first %s
z,
Second %s contains %d additional elements.
z(Unable to index element %d of second %s
r�)rr;rXrr�ra�NotImplementedError�
capitalizer�range�min�
IndexErrorr<�join�difflib�ndiff�pprint�pformat�
splitlines�_truncateMessagerVr)rZseq1Zseq2rW�seq_typeZ
seq_type_nameZ	differingZlen1Zlen2�iZitem1Zitem2rY�diffMsgrrr�assertSequenceEqual�s�

�

��
�

������

��
�

��
���zTestCase.assertSequenceEqualcCs2|j}|dkst|�|kr"||S|tt|�Sr))�maxDiffr��DIFF_OMITTED)rr�rZmax_diffrrrr+NszTestCase._truncateMessagecCs|j|||td�dS)aA list-specific equality assertion.

        Args:
            list1: The first list to compare.
            list2: The second list to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        �r,N)r/r|)rZlist1Zlist2rWrrrr�Ts
zTestCase.assertListEqualcCs|j|||td�dS)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.
        r2N)r/rQ)rZtuple1Ztuple2rWrrrr�`s	zTestCase.assertTupleEqualc

Cs`z|�|�}Wn^tk
r>}z|�d|�W5d}~XYn0tk
rl}z|�d|�W5d}~XYnXz|�|�}Wn^tk
r�}z|�d|�W5d}~XYn0tk
r�}z|�d|�W5d}~XYnX|s�|s�dSg}|�r|�d�|D]}|�t|���q|�r@|�d�|D]}|�t|���q*d�|�}	|�|�||	��dS)a�A set-specific equality assertion.

        Args:
            set1: The first set to compare.
            set2: The second set to compare.
            msg: Optional message to use on failure instead of a list of
                    differences.

        assertSetEqual uses ducktyping to support different types of sets, and
        is optimized for sets specifically (parameters must support a
        difference method).
        z/invalid type when attempting set difference: %sNz2first argument does not support set difference: %sz3second argument does not support set difference: %sz*Items in the first set but not the second:z*Items in the second set but not the first:r�)�
differencerarrer�reprr%rV)
rZset1Zset2rWZdifference1r%Zdifference2�lines�itemrYrrrr�ks2
  


zTestCase.assertSetEqualcCs2||kr.dt|�t|�f}|�|�||��dS)zDJust like self.assertTrue(a in b), but with a nicer default message.z%s not found in %sN�rrrV�r�memberZ	containerrWrYrrr�assertIn�s
�zTestCase.assertIncCs2||kr.dt|�t|�f}|�|�||��dS)zHJust like self.assertTrue(a not in b), but with a nicer default message.z%s unexpectedly found in %sNr7r8rrr�assertNotIn�s
�zTestCase.assertNotIncCs2||k	r.dt|�t|�f}|�|�||��dS)zDJust like self.assertTrue(a is b), but with a nicer default message.z%s is not %sNr7�rZexpr1Zexpr2rWrYrrr�assertIs�s
�zTestCase.assertIscCs,||kr(dt|�f}|�|�||��dS)zHJust like self.assertTrue(a is not b), but with a nicer default message.zunexpectedly identical: %sNr7r<rrr�assertIsNot�szTestCase.assertIsNotc	Cs~|�|td�|�|td�||krzdt||�}dd�t�t�|���t�|�����}|�	||�}|�
|�||��dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryrr�)�assertIsInstancer�rr%r&r'r(r)r*r+rrV)rZd1Zd2rWrYrrrrr��s
�zTestCase.assertDictEqualc		Cs�t�dt�g}g}|��D]L\}}||kr8|�|�q|||kr|�dt|�t|�t||�f�q|sv|svdSd}|r�dd�dd�|D��}|r�|r�|d	7}|d
d�|�7}|�|�||��dS)z2Checks whether dictionary is a superset of subset.z&assertDictContainsSubset is deprecatedz%s, expected: %s, actual: %sNrCzMissing: %s�,css|]}t|�VqdSr))r)rMr�rrrrP�sz4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	r�r�r��itemsrrr%rrV)	rZsubsetZ
dictionaryrWZmissingZ
mismatched�key�valuerYrrr�assertDictContainsSubset�s4�
���
z!TestCase.assertDictContainsSubsetc
Cs�t|�t|�}}zt�|�}t�|�}Wntk
rHt||�}YnX||krVdSt||�}|r�d}dd�|D�}d�|�}	|�||	�}|�||�}|�	|�dS)a[Asserts that two iterables have the same elements, the same number of
        times, without regard to order.

            self.assertEqual(Counter(list(first)),
                             Counter(list(second)))

         Example:
            - [0, 1, 1] and [1, 0, 1] compare equal.
            - [0, 0, 1] and [0, 1] compare unequal.

        NzElement counts were not equal:
cSsg|]}d|�qS)z First has %d, Second has %d:  %rr)rMrrrr�
<listcomp>�sz-TestCase.assertCountEqual.<locals>.<listcomp>r�)
r|�collections�Counterrarrr%r+rVr)
rrrrWZ	first_seqZ
second_seqZdifferencesrYr5r.rrr�assertCountEqual�s 


zTestCase.assertCountEqualcCs�|�|td�|�|td�||kr�t|�|jks@t|�|jkrN|�|||�|jdd�}|jdd�}t|�dkr�|�d�|kr�|dg}|dg}dt||�}dd	�t	�
||��}|�||�}|�|�
||��d
S)z-Assert that two multi-line strings are equal.zFirst argument is not a stringzSecond argument is not a stringT)�keependsrz
r�rrCN)r?r r��_diffThresholdrr*r�rr%r&r'r+rrV)rrrrWZ
firstlinesZsecondlinesrYrrrrr��s �

zTestCase.assertMultiLineEqualcCs2||ks.dt|�t|�f}|�|�||��dS)zCJust like self.assertTrue(a < b), but with a nicer default message.z%s not less than %sNr7�r�a�brWrYrrr�
assertLessszTestCase.assertLesscCs2||ks.dt|�t|�f}|�|�||��dS)zDJust like self.assertTrue(a <= b), but with a nicer default message.z%s not less than or equal to %sNr7rKrrr�assertLessEqualszTestCase.assertLessEqualcCs2||ks.dt|�t|�f}|�|�||��dS)zCJust like self.assertTrue(a > b), but with a nicer default message.z%s not greater than %sNr7rKrrr�
assertGreaterszTestCase.assertGreatercCs2||ks.dt|�t|�f}|�|�||��dS)zDJust like self.assertTrue(a >= b), but with a nicer default message.z"%s not greater than or equal to %sNr7rKrrr�assertGreaterEqual szTestCase.assertGreaterEqualcCs,|dk	r(dt|�f}|�|�||��dS)zCSame as self.assertTrue(obj is None), with a nicer default message.Nz%s is not Noner7�rr*rWrYrrr�assertIsNone&szTestCase.assertIsNonecCs"|dkrd}|�|�||��dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)rrVrRrrr�assertIsNotNone,szTestCase.assertIsNotNonecCs0t||�s,dt|�|f}|�|�||��dS)zTSame as self.assertTrue(isinstance(obj, cls)), with a nicer
        default message.z%s is not an instance of %rN�r;rrrV�rr*r�rWrYrrrr?2s
zTestCase.assertIsInstancecCs0t||�r,dt|�|f}|�|�||��dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rNrUrVrrr�assertNotIsInstance9s
zTestCase.assertNotIsInstancecOst|||�}|�d||�S)aAsserts that the message in a raised exception matches a regex.

        Args:
            expected_exception: Exception class expected to be raised.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertRaisesRegex is used as a context manager.
        �assertRaisesRegexr	)rr
r^r.r/rrrrrX?s
zTestCase.assertRaisesRegexcOst|||�}|�d||�S)a�Asserts that the message in a triggered warning matches a regexp.
        Basic functioning is similar to assertWarns() with the addition
        that only warnings whose messages also match the regular expression
        are considered successful matches.

        Args:
            expected_warning: Warning class expected to be triggered.
            expected_regex: Regex (re.Pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertWarnsRegex is used as a context manager.
        �assertWarnsRegexr
)rrr^r.r/rrrrrYOszTestCase.assertWarnsRegexcCsVt|ttf�r$|std��t�|�}|�|�sRd|j|f}|�||�}|�	|��dS)z=Fail the test unless the text matches the regular expression.z!expected_regex must not be empty.z&Regex didn't match: %r not found in %rN)
r;r �bytes�AssertionErrorr\r]rprqrVrX)r�textr^rWrYrrr�assertRegexbs

�zTestCase.assertRegexcCs`t|ttf�rt�|�}|�|�}|r\d||��|���|j|f}|�	||�}|�
|��dS)z9Fail the test if the text matches the regular expression.z"Regex matched: %r matches %r in %rN)r;r rZr\r]rp�start�endrqrVrX)rr\Zunexpected_regexrW�matchrYrrr�assertNotRegexns

�zTestCase.assertNotRegexcs�fdd�}|S)Ncs t�d��j�td��||�S)NzPlease use {0} instead.r�)r�r�rlrr�r7��
original_funcrr�deprecated_func~s
�z,TestCase._deprecate.<locals>.deprecated_funcr)rcrdrrbr�
_deprecate}szTestCase._deprecate)r�)N)N)N)N)NN)N)N)N)NNN)NNN)NN)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)N)errr
rr[rXrr0rJZ_classSetupFailedr�rr�r��__text_signature__�classmethodr�r�r�r�r�r�r�r�r�r�r�r�r�r�r'r(�_subtest_msg_sentinelr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrVrrrrrrrrrr/r+r�r�r�r:r;r=r>r�rDrHr�rNrOrPrQrSrTr?rWrXrYr]rareZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrr�ws� 
 


	


E

	


!



	�
-�
#
c


+






 










	r�csjeZdZdZd�fdd�	Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
�ZS)�FunctionTestCaseaIA test case that wraps a test function.

    This is useful for slipping pre-existing test functions into the
    unittest framework. Optionally, set-up and tidy-up functions can be
    supplied. As with TestCase, the tidy-up ('tearDown') function will
    always be called if the set-up ('setUp') function ran successfully.
    Ncs*tt|���||_||_||_||_dSr))�superrir�
_setUpFunc�
_tearDownFunc�	_testFunc�_description)rZtestFuncr�r�Zdescription�r�rrr�s
zFunctionTestCase.__init__cCs|jdk	r|��dSr))rkrirrrr��s
zFunctionTestCase.setUpcCs|jdk	r|��dSr))rlrirrrr��s
zFunctionTestCase.tearDowncCs|��dSr))rmrirrrr��szFunctionTestCase.runTestcCs|jjSr))rmrrirrrr��szFunctionTestCase.idcCs@t||j�stS|j|jko>|j|jko>|j|jko>|j|jkSr))r;r�r�rkrlrmrnr�rrrr��s
�
�
�zFunctionTestCase.__eq__cCstt|�|j|j|j|jf�Sr))r�r<rkrlrmrnrirrrr��s�zFunctionTestCase.__hash__cCsdt|j�|jjfSr�)rr�rmrrirrrr��s
�zFunctionTestCase.__str__cCsdt|j�|jfS)Nz<%s tec=%s>)rr�rmrirrrr��s
�zFunctionTestCase.__repr__cCs2|jdk	r|jS|jj}|r.|�d�d��p0dS)Nr�r)rnrmrr�r�r�rrrr��s
z!FunctionTestCase.shortDescription)NNN)rrr
rrr�r�r�r�r�r�r�r�r��
__classcell__rrrorri�s	ricsDeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z�Z	S)
r�cs(t���||_||_||_|j|_dSr))rjr�_messager#r�rX)rr#r�r�rorrr�s

z_SubTest.__init__cCstd��dS)Nzsubtests cannot be run directly)r rirrrr��sz_SubTest.runTestcCs^g}|jtk	r |�d�|j��|jrPd�dd�|j��D��}|�d�|��d�|�p\dS)Nz[{}]z, css|]\}}d�||�VqdS)z{}={!r}N)rl)rMr�r�rrrrP�s�z+_SubTest._subDescription.<locals>.<genexpr>z({})� z(<subtest>))rqrhrrlr�r%rA)r�partsZparams_descrrr�_subDescription�s

�z_SubTest._subDescriptioncCsd�|j��|���S�Nz{} {})rlr#r�rtrirrrr��sz_SubTest.idcCs
|j��S)zlReturns a one-line description of the subtest, or None if no
        description has been provided.
        )r#r�rirrrr��sz_SubTest.shortDescriptioncCsd�|j|���Sru)rlr#rtrirrrr��sz_SubTest.__str__)
rrr
rr�rtr�r�r�rprrrorr��sr�)4rr!r=r&r�r(r\r�rFr'rmrDrCr�utilrrrrrZ
__unittest�objectrhr1r2r	rrrr+r,r0r5rFrIrJrrLrUr[rhrx�
namedtupler�r�r�r��ChainMapr�r�rir�rrrr�<module>sd(	*%5�,
$:

?>