%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/self/root/usr/lib64/python3.6/unittest/__pycache__/
Upload File :
Create Path :
Current File : //proc/self/root/usr/lib64/python3.6/unittest/__pycache__/case.cpython-36.pyc

3

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

    Usually you can use TestCase.skipTest() or one of the skipping decorators
    instead of raising this directly.
    N)�__name__�
__module__�__qualname__�__doc__�rr�%/usr/lib64/python3.6/unittest/case.pyr	sr	c@seZdZdZdS)�_ShouldStopz
    The test should stop.
    N)r
rrr
rrrrr"src@seZdZdZdS)�_UnexpectedSuccessz7
    The test was supposed to fail, but it didn't!
    N)r
rrr
rrrrr'src@s&eZdZddd�Zejddd��ZdS)	�_OutcomeNcCs4d|_||_t|d�|_d|_g|_d|_g|_dS)NF�
addSubTestT)�expecting_failurer�hasattr�result_supports_subtests�success�skipped�expectedFailure�errors)�selfrrrr�__init__.sz_Outcome.__init__Fccs�|j}d|_z�y
dVWn�tk
r.�Yn�tk
rh}z d|_|jj|t|�f�WYdd}~Xnjtk
rzYnXtj�}|j	r�||_
nd|_|jj||f�d}YnX|jr�|jr�|jj|df�Wd|jo�||_XdS)NTF)
r�KeyboardInterruptr	r�append�strr�sys�exc_inforrrr)r�	test_case�isTestZold_success�er!rrr�testPartExecutor7s*
$
z_Outcome.testPartExecutor)N)F)r
rrr�
contextlib�contextmanagerr%rrrrr-s
	rcCs|S)Nr)�objrrr�_idUsr)cs�fdd�}|S)z&
    Unconditionally skip a test.
    cs4t|t�s$tj|��fdd��}|}d|_�|_|S)Ncst���dS)N)r	)�args�kwargs)�reasonrr�skip_wrapper^sz-skip.<locals>.decorator.<locals>.skip_wrapperT)�
isinstance�type�	functools�wraps�__unittest_skip__�__unittest_skip_why__)�	test_itemr-)r,rr�	decorator\s
zskip.<locals>.decoratorr)r,r5r)r,r�skipXs
r6cCs|rt|�StS)z/
    Skip a test if the condition is true.
    )r6r))�	conditionr,rrr�skipIfhsr8cCs|st|�StS)z3
    Skip a test unless the condition is true.
    )r6r))r7r,rrr�
skipUnlesspsr9cCs
d|_|S)NT)�__unittest_expecting_failure__)r4rrrrxsrcs4t|t�r t�fdd�|D��St|t�o2t|��S)Nc3s|]}t|��VqdS)N)�_is_subtype)�.0r$)�basetyperr�	<genexpr>~sz_is_subtype.<locals>.<genexpr>)r.�tuple�allr/�
issubclass)�expectedr=r)r=rr;|s
r;c@seZdZdd�Zdd�ZdS)�_BaseTestCaseContextcCs
||_dS)N)r")rr"rrrr�sz_BaseTestCaseContext.__init__cCs |jj|j|�}|jj|��dS)N)r"�_formatMessage�msg�failureException)r�standardMsgrErrr�
_raiseFailure�sz"_BaseTestCaseContext._raiseFailureN)r
rrrrHrrrrrC�srCcCsdtjkrt|�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)�os�environr6r))r,rrr�_skipInRpmBuild�s
rKc@seZdZddd�Zdd�ZdS)�_AssertRaisesBaseContextNcCs@tj||�||_||_|dk	r*tj|�}||_d|_d|_dS)N)	rCrrBr"�re�compile�expected_regex�obj_namerE)rrBr"rOrrrr�s
z!_AssertRaisesBaseContext.__init__cCs�z�t|j|j�s"td||jf��|rD|ddkrDtjdtd�f}|sx|jdd�|_	|rttjdt
t|��td�|S|^}}y|j|_
Wntk
r�t|�|_
YnX|�|||�WdQRXWdd}XdS)z�
        If args is empty, assertRaises/Warns is being used as a
        context manager, so check for a 'msg' kwarg and return self.
        If args is not empty, call a callable passing positional and keyword
        arguments.
        z%s() arg 1 must be %srNzcallable is None�rEz3%r is an invalid keyword argument for this function)r;rB�
_base_type�	TypeError�_base_type_str�warnings�warn�DeprecationWarning�poprE�next�iterr
rP�AttributeErrorr)r�namer*r+Zcallable_objrrr�handle�s.z_AssertRaisesBaseContext.handle)N)r
rrrr]rrrrrL�s

rLc@s(eZdZdZeZdZdd�Zdd�ZdS)�_AssertRaisesContextzCA context manager used to implement TestCase.assertRaises* methods.z-an exception type or tuple of exception typescCs|S)Nr)rrrr�	__enter__�sz_AssertRaisesContext.__enter__c
Cs�|dkrby|jj}Wntk
r2t|j�}YnX|jrP|jdj||j��ql|jdj|��n
tj|�t	||j�s|dS|j
d�|_|jdkr�dS|j}|j
t|��s�|jdj|jt|���dS)Nz{} not raised by {}z
{} not raisedFTz"{}" does not match "{}")rBr
r[rrPrH�format�	traceback�clear_framesrA�with_tracebackZ	exceptionrO�search�pattern)r�exc_type�	exc_value�tb�exc_namerOrrr�__exit__�s(


z_AssertRaisesContext.__exit__N)	r
rrr
�
BaseExceptionrRrTr_rjrrrrr^�s
r^c@s(eZdZdZeZdZdd�Zdd�ZdS)�_AssertWarnsContextzBA context manager used to implement TestCase.assertWarns* methods.z(a warning type or tuple of warning typescCsRx$tjj�D]}t|dd�ri|_qWtjdd�|_|jj�|_tj	d|j
�|S)N�__warningregistry__T)�record�always)r �modules�values�getattrrmrU�catch_warnings�warnings_managerr_�simplefilterrB)r�vrrrr_�s
z_AssertWarnsContext.__enter__c
Cs|jj|||�|dk	rdSy|jj}Wntk
rFt|j�}YnXd}xd|jD]Z}|j}t||j�slqT|dkrx|}|j	dk	r�|j	j
t|��r�qT||_|j|_|j
|_
dSW|dk	r�|jdj|j	jt|���|jr�|jdj||j��n|jdj|��dS)Nz"{}" does not match "{}"z{} not triggered by {}z{} not triggered)rtrjrBr
r[rrU�messager.rOrdZwarning�filename�linenorHr`rerP)rrfrgrhriZfirst_matching�m�wrrrrj�s8

z_AssertWarnsContext.__exit__N)	r
rrr
�WarningrRrTr_rjrrrrrl�s
rl�_LoggingWatcher�records�outputc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�_CapturingHandlerzM
    A logging handler capturing all (raw and formatted) logging output.
    cCstjj|�tgg�|_dS)N)�logging�Handlerrr}�watcher)rrrrr,sz_CapturingHandler.__init__cCsdS)Nr)rrrr�flush0sz_CapturingHandler.flushcCs*|jjj|�|j|�}|jjj|�dS)N)r�r~rr`r)rrnrErrr�emit3s
z_CapturingHandler.emitN)r
rrr
rr�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:tj||�||_|r(tjj||�|_ntj|_d|_dS)N)	rCr�logger_namer�Z_nameToLevel�get�level�INFOrE)rr"r�r�rrrr?sz_AssertLogsContext.__init__cCs�t|jtj�r|j}|_ntj|j�}|_tj|j�}t�}|j	|�|j
|_
|jdd�|_|j
|_|j|_|g|_|j|j
�d|_|j
S)NF)r.r�r�ZLogger�loggerZ	getLoggerZ	Formatter�LOGGING_FORMATr�ZsetFormatterr��handlers�old_handlersr��	old_level�	propagate�
old_propagate�setLevel)rr�Z	formatterZhandlerrrrr_Hs
z_AssertLogsContext.__enter__cCs`|j|j_|j|j_|jj|j�|dk	r.dSt|jj	�dkr\|j
djtj
|j�|jj��dS)NFrz-no logs of level {} or higher triggered on {})r�r�r�r�r�r�r��lenr�r~rHr`r�ZgetLevelNamer�r\)rrfrgrhrrrrjYs

z_AssertLogsContext.__exit__N)r
rrr
r�rr_rjrrrrr�:s
	r�c@s�eZdZdZeZdZd�Zd�ZdZ	d�d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zedd��Zedd��Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zejefd)d*��Zd+d,�Zd-d.�Z d/d0�Z!d�d2d3�Z"d4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d�d<d=�Z'd�d>d?�Z(d�d@dA�Z)dBdC�Z*dDdE�Z+dFdG�Z,d�dHdI�Z-dJdK�Z.d�dLdM�Z/d�dNdO�Z0d�dPdQ�Z1d�dRdS�Z2d�dTdU�Z3d�dVdW�Z4dXdY�Z5d�dZd[�Z6d�d\d]�Z7d�d^d_�Z8d�d`da�Z9d�dbdc�Z:d�ddde�Z;d�dfdg�Z<d�dhdi�Z=d�djdk�Z>d�dldm�Z?d�dndo�Z@d�dpdq�ZAd�drds�ZBd�dtdu�ZCd�dvdw�ZDd�dxdy�ZEd�dzd{�ZFd�d|d}�ZGd�d~d�ZHd�d��ZId�d��ZJd�d�d��ZKd�d�d��ZLd�d��ZMeMe0�ZNZOeMe1�ZPZQeMe2�ZRZSeMe3�ZTZUeMe)�ZVZWeMe+�ZXeMe(�ZYeMeI�ZZeMeK�Z[eMeL�Z\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.
    T�P���F�runTestcCs�||_d|_d|_yt||�}Wn.tk
rN|dkrJtd|j|f��Yn
X|j|_g|_d|_	i|_
|jtd�|jt
d�|jtd�|jtd�|jtd�|jtd	�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�_testMethodDocrrr[�
ValueError�	__class__r
�	_cleanups�_subtest�_type_equality_funcs�addTypeEqualityFunc�dict�listr?�set�	frozensetr)rZ
methodName�
testMethodrrrr�s&zTestCase.__init__cCs||j|<dS)a[Add a type specific assertEqual style function to compare a type.

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

        Args:
            typeobj: The data type to call this function on when both values
                    are of the same type in assertEqual().
            function: The callable taking two arguments and an optional
                    msg= argument that raises self.failureException with a
                    useful error message when the two arguments are not equal.
        N)r�)rZtypeobj�functionrrrr��s
zTestCase.addTypeEqualityFunccOs|jj|||f�dS)aAdd a function, with arguments, to be called when the test is
        completed. Functions added are called on a LIFO basis and are
        called after tearDown on test failure or success.

        Cleanup items are called even if setUp fails (unlike tearDown).N)r�r)rr�r*r+rrr�
addCleanup�szTestCase.addCleanupcCsdS)zAHook method for setting up the test fixture before exercising it.Nr)rrrr�setUp�szTestCase.setUpcCsdS)zAHook method for deconstructing the test fixture after testing it.Nr)rrrr�tearDown�szTestCase.tearDowncCsdS)zKHook method for setting up class fixture before running tests in the class.Nr)�clsrrr�
setUpClass�szTestCase.setUpClasscCsdS)zVHook method for deconstructing the class fixture after running all tests in the class.Nr)r�rrr�
tearDownClass�szTestCase.tearDownClasscCsdS)Nrr)rrrr�countTestCases�szTestCase.countTestCasescCstj�S)N)rZ
TestResult)rrrr�defaultTestResult�szTestCase.defaultTestResultcCs |j}|r|jd�dj�pdS)z�Returns a one-line description of the test, or None if no
        description has been provided.

        The default implementation of this method returns the first line of
        the specified test method's docstring.
        �
rN)r��split�strip)r�docrrr�shortDescription�szTestCase.shortDescriptioncCsdt|j�|jfS)Nz%s.%s)rr�r�)rrrr�id�szTestCase.idcCs t|�t|�k	rtS|j|jkS)N)r/�NotImplementedr�)r�otherrrr�__eq__�szTestCase.__eq__cCstt|�|jf�S)N)�hashr/r�)rrrr�__hash__�szTestCase.__hash__cCsd|jt|j�fS)Nz%s (%s))r�rr�)rrrr�__str__�szTestCase.__str__cCsdt|j�|jfS)Nz<%s testMethod=%s>)rr�r�)rrrr�__repr__�szTestCase.__repr__cCs<t|dd�}|dk	r |||�ntjdtd�|j|�dS)N�addSkipz4TestResult has no addSkip method, skips not reportedr�)rrrUrV�RuntimeWarning�
addSuccess)rrr"r,r�rrr�_addSkipszTestCase._addSkipcks�|jdks|jjrdVdS|j}|dkr8tj|�}n|jj|�}t|||�|_zX|jj|jdd��dVWdQRX|jj	s�|jj
}|dk	r�|jr�t�n|jj
r�t�Wd||_XdS)aPReturn a context manager that will return the enclosed block
        of code in a subtest identified by the optional message and
        keyword parameters.  A failure in the subtest marks the test
        case as failed but resumes execution at the end of the enclosed
        block, allowing further test code to be executed.
        NT)r#)r�rr��collections�ChainMap�params�	new_child�_SubTestr%rrZfailfastrr)rrEr��parentZ
params_maprrrr�subTest	s$zTestCase.subTestcCsdx^|D]V\}}t|t�r*|j|j||�q|dk	rt|d|j�rP|j||�q|j||�qWdS)Nr)r.r�rr"rArF�
addFailureZaddError)rrr�testr!rrr�_feedErrorsToResult(s
zTestCase._feedErrorsToResultcCsDy
|j}Wn*tk
r4tjdt�|j|�YnX|||�dS)Nz@TestResult has no addExpectedFailure method, reporting as passes)�addExpectedFailurer[rUrVr�r�)rrr!r�rrr�_addExpectedFailure2s
zTestCase._addExpectedFailurecCshy
|j}WnPtk
rZtjdt�y
td�Wn$tk
rT|j|tj��YnXYn
X||�dS)NzCTestResult has no addUnexpectedSuccess method, reporting as failure)	�addUnexpectedSuccessr[rUrVr�rr�r r!)rrr�rrr�_addUnexpectedSuccess<s

zTestCase._addUnexpectedSuccessNc
(Cs|}|dkr.|j�}t|dd�}|dk	r.|�|j|�t||j�}t|jdd�s^t|dd�r�z,t|jdd�pxt|dd�}|j|||�Wd|j|�XdSt|dd�}t|dd�}|p�|}t|�}	z�|	|_|	j	|��|j
�WdQRX|	j�r<||	_|	j	|dd��|�WdQRXd|	_|	j	|��|j
�WdQRX|j�x"|	jD]\}
}|j||
|��qLW|j||	j�|	j�r�|�r�|	j�r�|j||	j�n
|j|�n
|j|�|S|j|�|dk�r�t|d	d�}|dk	�r�|�|	jj�d|	_d|_XdS)
N�startTestRunr2Fr3�r:T)r#�stopTestRun)r�rrZ	startTestr�r�r�ZstopTestrr�r%r�rrr��
doCleanupsrr�rrr�r�r��clear)
rrZorig_resultr�r�Zskip_whyZexpecting_failure_methodZexpecting_failure_classr�outcomer�r,r�rrr�runKsh





zTestCase.runc
CsN|jp
t�}x:|jrF|jj�\}}}|j|��|||�WdQRXqW|jS)zNExecute all cleanup functions. Normally called for you after
        tearDown.N)r�rr�rXr%r)rr�r�r*r+rrrr��szTestCase.doCleanupscOs|j||�S)N)r�)rr*�kwdsrrr�__call__�szTestCase.__call__cCsJ|j�t||j��|j�x&|jrD|jjd�\}}}|||�q WdS)z6Run the test without collecting errors in a TestResultrN���)r�rrr�r�r�rX)rr�r*r+rrr�debug�szTestCase.debugcCst|��dS)zSkip this test.N)r	)rr,rrr�skipTest�szTestCase.skipTestcCs|j|��dS)z)Fail immediately, with the given message.N)rF)rrErrr�fail�sz
TestCase.failcCs&|r"|j|dt|��}|j|��dS)z#Check that the expression is false.z%s is not falseN)rDrrF)r�exprrErrr�assertFalse�szTestCase.assertFalsecCs&|s"|j|dt|��}|j|��dS)z"Check that the expression is true.z%s is not trueN)rDrrF)rr�rErrr�
assertTrue�szTestCase.assertTruecCsP|js|p|S|dkr|Syd||fStk
rJdt|�t|�fSXdS)a�Honour the longMessage attribute when generating failure messages.
        If longMessage is False this means:
        * Use only an explicit message if it is provided
        * Otherwise use the standard message for the assert

        If longMessage is True:
        * Use the standard message
        * If an explicit message is provided, plus ' : ' and the explicit message
        Nz%s : %s)�longMessage�UnicodeDecodeErrorr)rrErGrrrrD�s
zTestCase._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])r�expected_exceptionr*r+�contextrrrr��s
zTestCase.assertRaisescOst||�}|jd||�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)rlr])r�expected_warningr*r+r�rrrr��s
zTestCase.assertWarnscCst|||�S)a�Fail unless a log message of level *level* or higher is emitted
        on *logger_name* or its children.  If omitted, *level* defaults to
        INFO and *logger* defaults to the root logger.

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

        Example::

            with self.assertLogs('foo', level='INFO') as cm:
                logging.getLogger('foo').info('first message')
                logging.getLogger('foo.bar').error('second message')
            self.assertEqual(cm.output, ['INFO:foo:first message',
                                         'ERROR:foo.bar:second message'])
        )r�)rr�r�rrr�
assertLogsszTestCase.assertLogscCsFt|�t|�kr@|jjt|��}|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.rrr�_baseAssertEqual)r�first�secondZasserterrrr�_getAssertEqualityFunc(s

zTestCase._getAssertEqualityFunccCs0||ks,dt||�}|j||�}|j|��dS)z:The default assertEqual implementation, not type specific.z%s != %sN)rrDrF)rr�r�rErGrrrr�BszTestCase._baseAssertEqualcCs|j||�}||||d�dS)z[Fail if the two objects are unequal as determined by the '=='
           operator.
        )rEN)r�)rr�r�rEZassertion_funcrrr�assertEqualIszTestCase.assertEqualcCs2||ks.|j|dt|�t|�f�}|j|��dS)zYFail if the two objects are equal as determined by the '!='
           operator.
        z%s == %sN)rDrrF)rr�r�rErrr�assertNotEqualPszTestCase.assertNotEqualcCs�||krdS|dk	r$|dk	r$td��|dk	r\t||�|kr@dSdt|�t|�t|�f}n<|dkrhd}tt||�|�dkr�dSdt|�t|�|f}|j||�}|j|��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.
        Nz specify delta or places not bothz%s != %s within %s delta�rz%s != %s within %r places)rS�absr�roundrDrF)rr�r��placesrE�deltarGrrr�assertAlmostEqualYs&zTestCase.assertAlmostEqualcCs�|dk	r|dk	rtd��|dk	rZ||kr>t||�|kr>dSdt|�t|�t|�f}nF|dkrfd}||kr�tt||�|�dkr�dSdt|�t|�|f}|j||�}|j|��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.
        Nz specify delta or places not bothz%s == %s within %s deltar�rz%s == %s within %r places)rSr�rr�rDrF)rr�r�r�rEr�rGrrr�assertNotAlmostEqual�s" zTestCase.assertNotAlmostEqualc'Cs�|dk	rP|j}t||�s.|jd|t|�f��t||�sT|jd|t|�f��nd}d}yt|�}Wn ttfk
r�d|}YnX|dkr�yt|�}Wn ttfk
r�d|}YnX|dk�r�||kr�dSd|j�ft||�}x�t	t
||��D]�}	y||	}
Wn.tttfk
�r8|d|	|f7}PYnXy||	}Wn.tttfk
�rt|d	|	|f7}PYnX|
|kr�|d
|	ft|
|�7}Pq�W||k�r�|dk�r�t|�t|�k�r�dS||k�r0|d|||f7}y|d|t||�f7}Wn,tttfk
�r,|d
||f7}YnXnh||k�r�|d|||f7}y|d|t||�f7}Wn,tttfk
�r�|d||f7}YnX|}ddj
tjtj|�j�tj|�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.rFrr�rS�NotImplementedError�
capitalizer�range�min�
IndexErrorr/�join�difflib�ndiff�pprint�pformat�
splitlines�_truncateMessagerDr�)rZseq1Zseq2rE�seq_typeZ
seq_type_nameZ	differingZlen1Zlen2�iZitem1Zitem2rG�diffMsgrrr�assertSequenceEqual�s�




zTestCase.assertSequenceEqualcCs2|j}|dkst|�|kr"||S|tt|�S)N)�maxDiffr��DIFF_OMITTED)rrw�diffZmax_diffrrrrszTestCase._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.

        )rN)r	r�)rZlist1Zlist2rErrrr�s
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.
        )rN)r	r?)rZtuple1Ztuple2rErrrr�s	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�|s�dSg}|�r|jd�x|D]}|jt|���qW|�rH|jd�x|D]}|jt|���q0Wdj|�}	|j|j||	��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�)�
differencerSr�r[r�reprr�rD)
rZset1Zset2rEZdifference1r$Zdifference2�lines�itemrGrrrr�"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)rr�rD)r�member�	containerrErGrrr�assertInMs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)rr�rD)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)rr�rD)r�expr1�expr2rErGrrr�assertIs[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)rr�rD)rrrrErGrrr�assertIsNotbszTestCase.assertIsNotcCs~|j|td�|j|td�||krzdt||�}ddjtjtj|�j�tj|�j���}|j	||�}|j
|j||��dS)Nz"First argument is not a dictionaryz#Second argument is not a dictionaryz%s != %sr�)�assertIsInstancer�rr�rrrrrrr�rD)rZd1Zd2rErGrrrrr�hs
zTestCase.assertDictEqualc	Cs�tjdt�g}g}xX|j�D]L\}}||kr:|j|�q|||kr|jdt|�t|�t||�f�qW|pt|szdSd}|r�ddjdd�|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: %sNr�zMissing: %s�,css|]}t|�VqdS)N)r)r<rzrrrr>�sz4TestCase.assertDictContainsSubset.<locals>.<genexpr>z; zMismatched values: %s)	rUrVrW�itemsrrr�r�rD)	rZsubsetZ
dictionaryrEZmissingZ
mismatched�key�valuerGrrr�assertDictContainsSubsetts,z!TestCase.assertDictContainsSubsetc
Cs�t|�t|�}}ytj|�}tj|�}Wntk
rHt||�}YnX||krVdSt||�}|r�d}dd�|D�}dj|�}	|j||	�}|j||�}|j	|�dS)a�An unordered sequence comparison asserting that the same elements,
        regardless of order.  If the same element occurs more than once,
        it verifies that the elements occur the same number of times.

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

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

        NzElement counts were not equal:
cSsg|]}d|�qS)z First has %d, Second has %d:  %rr)r<rrrr�
<listcomp>�sz-TestCase.assertCountEqual.<locals>.<listcomp>r�)
r�r��CounterrSrrr�rrDr�)
rr�r�rEZ	first_seqZ
second_seqZdifferencesrGrrrrr�assertCountEqual�s 



zTestCase.assertCountEqualcCs�|j|td�|j|td�||kr�t|�|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
r�z%s != %sr�N)rrr��_diffThresholdr�rr�rr�rrrr�rD)rr�r�rEZ
firstlinesZsecondlinesrGrrrrr��s

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)rr�rD)r�a�brErGrrr�
assertLess�szTestCase.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)rr�rD)rr$r%rErGrrr�assertLessEqual�szTestCase.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)rr�rD)rr$r%rErGrrr�
assertGreater�szTestCase.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)rr�rD)rr$r%rErGrrr�assertGreaterEqual�szTestCase.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)rr�rD)rr(rErGrrr�assertIsNone�szTestCase.assertIsNonecCs"|dkrd}|j|j||��dS)z(Included for symmetry with assertIsNone.Nzunexpectedly None)r�rD)rr(rErGrrr�assertIsNotNone�szTestCase.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.rr�rD)rr(r�rErGrrrr�s
zTestCase.assertIsInstancecCs0t||�r,dt|�|f}|j|j||��dS)z,Included for symmetry with assertIsInstance.z%s is an instance of %rN)r.rr�rD)rr(r�rErGrrr�assertNotIsInstance�s
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])rr�rOr*r+r�rrrr-�s
zTestCase.assertRaisesRegexcOst|||�}|jd||�S)a�Asserts that the message in a triggered warning matches a regexp.
        Basic functioning is similar to assertWarns() with the addition
        that only warnings whose messages also match the regular expression
        are considered successful matches.

        Args:
            expected_warning: Warning class expected to be triggered.
            expected_regex: Regex (re pattern object or string) expected
                    to be found in error message.
            args: Function to be called and extra positional args.
            kwargs: Extra kwargs.
            msg: Optional message used in case of failure. Can only be used
                    when assertWarnsRegex is used as a context manager.
        �assertWarnsRegex)rlr])rr�rOr*r+r�rrrr.szTestCase.assertWarnsRegexcCsVt|ttf�r$|std��tj|�}|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.r�bytes�AssertionErrorrMrNrdrerDrF)r�textrOrErGrrr�assertRegexs

zTestCase.assertRegexcCs`t|ttf�rtj|�}|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/rMrNrd�start�endrerDrF)rr1Zunexpected_regexrE�matchrGrrr�assertNotRegex&s

zTestCase.assertNotRegexcs�fdd�}|S)Ncs tjdj�j�td��||�S)NzPlease use {0} instead.r�)rUrVr`r
rW)r*r+)�
original_funcrr�deprecated_func6s
z,TestCase._deprecate.<locals>.deprecated_funcr)r7r8r)r7r�
_deprecate5szTestCase._deprecatei�i)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
rrr
r0rFr�r
r#Z_classSetupFailedrr�r�r�r��classmethodr�r�r�r�r�r�r�r�r�r�r�r&r'�_subtest_msg_sentinelr�r�r�r�r�r�r�r�r�r�r�r�rDr�r�r�r�r�r�r�r�r�r	rr�r�r�rrrrr�rr!r�r&r'r(r)r*r+rr,r-r.r2r6r9ZfailUnlessEqualZassertEqualsZfailIfEqualZassertNotEqualsZfailUnlessAlmostEqualZassertAlmostEqualsZfailIfAlmostEqualZassertNotAlmostEqualsZ
failUnlessZassert_ZfailUnlessRaisesZfailIfZassertRaisesRegexpZassertRegexpMatchesZassertNotRegexpMatchesrrrrr�fs�
 	


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|�j�||_||_||_||_dS)N)�superr<r�
_setUpFunc�
_tearDownFunc�	_testFunc�_description)rZtestFuncr�r�Zdescription)r�rrrTs
zFunctionTestCase.__init__cCs|jdk	r|j�dS)N)r>)rrrrr�[s
zFunctionTestCase.setUpcCs|jdk	r|j�dS)N)r?)rrrrr�_s
zFunctionTestCase.tearDowncCs|j�dS)N)r@)rrrrr�cszFunctionTestCase.runTestcCs|jjS)N)r@r
)rrrrr�fszFunctionTestCase.idcCs@t||j�stS|j|jko>|j|jko>|j|jko>|j|jkS)N)r.r�r�r>r?r@rA)rr�rrrr�iszFunctionTestCase.__eq__cCstt|�|j|j|j|jf�S)N)r�r/r>r?r@rA)rrrrr�rszFunctionTestCase.__hash__cCsdt|j�|jjfS)Nz%s (%s))rr�r@r
)rrrrr�vs
zFunctionTestCase.__str__cCsdt|j�|jfS)Nz<%s tec=%s>)rr�r@)rrrrr�zs
zFunctionTestCase.__repr__cCs2|jdk	r|jS|jj}|r.|jd�dj�p0dS)Nr�r)rAr@r
r�r�)rr�rrrr�~s
z!FunctionTestCase.shortDescription)NNN)r
rrr
rr�r�r�r�r�r�r�r�r��
__classcell__rr)r�rr<Ks	r<csDeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Z�Z	S)
r�cs(t�j�||_||_||_|j|_dS)N)r=r�_messager"r�rF)rr"rwr�)r�rrr�s

z_SubTest.__init__cCstd��dS)Nzsubtests cannot be run directly)r�)rrrrr��sz_SubTest.runTestcCsbg}|jtk	r |jdj|j��|jrTdjdd�t|jj��D��}|jdj|��dj|�p`dS)Nz[{}]z, css|]\}}dj||�VqdS)z{}={!r}N)r`)r<�krvrrrr>�sz+_SubTest._subDescription.<locals>.<genexpr>z({})� z(<subtest>))rCr;rr`r�r��sortedr)r�partsZparams_descrrr�_subDescription�s
z_SubTest._subDescriptioncCsdj|jj�|j��S)Nz{} {})r`r"r�rH)rrrrr��sz_SubTest.idcCs
|jj�S)zlReturns a one-line description of the subtest, or None if no
        description has been provided.
        )r"r�)rrrrr��sz_SubTest.shortDescriptioncCsdj|j|j��S)Nz{} {})r`r"rH)rrrrr��sz_SubTest.__str__)
r
rrrr�rHr�r�r�rBrr)r�rr��sr�)0r
r r0rrIr�rrMrUr�r&rar�r�utilrrrrrZ
__unittest�objectr;r�	Exceptionr	rrrr)r6r8r9rr;rCrKrLr^rl�
namedtupler}r�r�r�r�r<r�rrrr�<module>sZ(
/%5
,l:

Zerion Mini Shell 1.0