HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/trial/test/__pycache__/test_assertions.cpython-38.pyc
U


W[&��@sjdZddlmZmZddlZddlZddlmZddl	m
Z
mZmZddl
mZddlmZmZddlmZdd	lmZdd
lmZmZmZGdd�dee�ZGd
d�de�ZGdd�dej�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!Gdd�dej�Z"Gdd�dej�Z#Gdd�dej�Z$Gdd�dej�Z%ee%j&�dd ��Z'ee%j&d!d"�d#d$��Z(dS)%a�
Tests for assertions provided by C{SynchronousTestCase} and C{TestCase},
provided by L{twisted.trial.unittest}.

L{TestFailureTests} demonstrates that L{SynchronousTestCase.fail} works, so that
is the only method on C{twisted.trial.unittest.SynchronousTestCase} that is
initially assumed to work.  The test classes are arranged so that the methods
demonstrated to work earlier in the file are used by those later in the file
(even though the runner will probably not run the tests in this order).
�)�division�absolute_importN)�FancyEqMixin)�prefixedMethods�accumulateMethods�fullyQualifiedName��
deprecated)�Version�getVersionString)�Failure)�unittest)�Deferred�fail�succeedc@s eZdZdZdd�Zdd�ZdS)�MockEquality��namecCs
||_dS�Nr)�selfr�r�D/usr/lib/python3/dist-packages/twisted/trial/test/test_assertions.py�__init__ szMockEquality.__init__cCsd|jfS)NzMockEquality(%s)r�rrrr�__repr__$szMockEquality.__repr__N)�__name__�
__module__�__qualname__ZcompareAttributesrrrrrrrsrc@s eZdZdZdd�ZeZZdS)�ComparisonErrorzH
    An object which raises exceptions from its comparison methods.
    cCstd��dS)NzComparison is broken)�
ValueError)r�otherrrr�_error,szComparisonError._errorN)rrr�__doc__r!�__eq__�__ne__rrrrr(src@s:eZdZdZGdd�dej�Zdd�Zdd�Zdd	�Z	d
S)�TestFailureTestsa�
    Tests for the most basic functionality of L{SynchronousTestCase}, for
    failing tests.

    This class contains tests to demonstrate that L{SynchronousTestCase.fail}
    can be used to fail a test, and that that failure is reflected in the test
    result object.  This should be sufficient functionality so that further
    tests can be built on L{SynchronousTestCase} instead of
    L{unittest.TestCase}.  This depends on L{unittest.TestCase} working.
    c@seZdZdd�ZdS)zTestFailureTests.FailingTestcCs|�d�dS)NzThis test fails.�rrrrr�
test_fails?sz'TestFailureTests.FailingTest.test_failsN)rrrr'rrrr�FailingTest>sr(cCsDt|jj|jjg}t��|_|j�d�|��|_t	|j�d|_
dS)zo
        Load a suite of one test which can be used to exercise the failure
        handling behavior.
        �.rN)r�	__class__r(�pyunitZ
TestLoader�loaderZloadTestsFromName�join�suite�list�test)rZ
componentsrrr�setUpCs�
zTestFailureTests.setUpc
CsVz|j�d�Wn6|jjk
rF}z|�dt|��W5d}~XYnX|�d�dS)z}
        L{SynchronousTestCase.fail} raises
        L{SynchronousTestCase.failureException} with the given argument.
        ZfailedNzRSynchronousTestCase.fail method did not raise SynchronousTestCase.failureException)r0r�failureException�assertEqual�str�r�resultrrr�	test_failOs"�zTestFailureTests.test_failcCs^t��}|j�|�|�|���|�|jg�|�t|j	�d�|�|j	dd|j
�dS)z�
        When a test method raises L{SynchronousTestCase.failureException}, the test is
        marked as having failed on the L{TestResult}.
        �rN)r+Z
TestResultr.�run�assertFalseZ
wasSuccessfulr3�errors�lenZfailuresr0r5rrr�test_failingExceptionFails^sz+TestFailureTests.test_failingExceptionFailsN)
rrrr"r
�SynchronousTestCaser(r1r7r=rrrrr%3s

r%c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�AssertFalseTestsa
    Tests for L{SynchronousTestCase}'s C{assertFalse} and C{failIf} assertion
    methods.

    This is pretty paranoid.  Still, a certain paranoia is healthy if you
    are testing a unit testing framework.

    @note: As of 11.2, C{assertFalse} is preferred over C{failIf}.
    cCsBdddddgfD],}||d|f�}||kr|�d|f�qdS)z�
        Perform the positive case test for C{failIf} or C{assertFalse}.

        @param method: The test method to test.
        r�FNr�failed on %r�Did not return argument %rr&)r�method�notTruer6rrr�_assertFalseFalsevsz"AssertFalseTests._assertFalseFalsecCs�dddddgdfD]r}z||d|f�WnD|jk
rn}z$|�d|ft|�d||f�W5d}~XYqX|�d	|j|f�qdS)
z�
        Perform the negative case test for C{failIf} or C{assertFalse}.

        @param method: The test method to test.
        r8T�cat����rA�$Raised incorrect exception on %r: %rN�Call to %s(%r) didn't fail�r2�assertInr4rr)rrC�true�errr�_assertFalseTrue�s
��z!AssertFalseTests._assertFalseTruecCs|�|j�dS)zt
        L{SynchronousTestCase.failIf} returns its argument if its argument is
        not considered true.
        N)rE�failIfrrrr�test_failIfFalse�sz!AssertFalseTests.test_failIfFalsecCs|�|j�dS)zy
        L{SynchronousTestCase.assertFalse} returns its argument if its argument
        is not considered true.
        N)rEr:rrrr�test_assertFalseFalse�sz&AssertFalseTests.test_assertFalseFalsecCs|�|j�dS)z�
        L{SynchronousTestCase.failIf} raises
        L{SynchronousTestCase.failureException} if its argument is considered
        true.
        N)rQrRrrrr�test_failIfTrue�sz AssertFalseTests.test_failIfTruecCs|�|j�dS)z�
        L{SynchronousTestCase.assertFalse} raises
        L{SynchronousTestCase.failureException} if its argument is considered
        true.
        N)rQr:rrrr�test_assertFalseTrue�sz%AssertFalseTests.test_assertFalseTrueN)
rrrr"rErQrSrTrUrVrrrrr?ls		r?c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�AssertTrueTestsa
    Tests for L{SynchronousTestCase}'s C{assertTrue} and C{failUnless} assertion
    methods.

    This is pretty paranoid.  Still, a certain paranoia is healthy if you
    are testing a unit testing framework.

    @note: As of 11.2, C{assertTrue} is preferred over C{failUnless}.
    cCs�dddddgfD]r}z||d|f�WnD|jk
rl}z$|�d|ft|�d||f�W5d}~XYqX|�d|j|f�qdS)	z�
        Perform the negative case test for C{assertTrue} and C{failUnless}.

        @param method: The test method to test.
        rr@FNrrArKrLrM)rrCrDrPrrr�_assertTrueFalse�s
��z AssertTrueTests._assertTrueFalsecCsDdddddgdfD],}||d|f�}||kr|�d|f�qdS)	z�
        Perform the positive case test for C{assertTrue} and C{failUnless}.

        @param method: The test method to test.
        r8TrFrGrHrArBNr&)rrCrOr6rrr�_assertTrueTrue�szAssertTrueTests._assertTrueTruecCs|�|j�dS)z�
        L{SynchronousTestCase.assertTrue} raises
        L{SynchronousTestCase.failureException} if its argument is not
        considered true.
        N)rX�
assertTruerrrr�test_assertTrueFalse�sz$AssertTrueTests.test_assertTrueFalsecCs|�|j�dS)z�
        L{SynchronousTestCase.failUnless} raises
        L{SynchronousTestCase.failureException} if its argument is not
        considered true.
        N)rX�
failUnlessrrrr�test_failUnlessFalse�sz$AssertTrueTests.test_failUnlessFalsecCs|�|j�dS)zt
        L{SynchronousTestCase.assertTrue} returns its argument if its argument
        is considered true.
        N)rYrZrrrr�test_assertTrueTrue�sz#AssertTrueTests.test_assertTrueTruecCs|�|j�dS)zt
        L{SynchronousTestCase.failUnless} returns its argument if its argument
        is considered true.
        N)rYr\rrrr�test_failUnlessTrue�sz#AssertTrueTests.test_failUnlessTrueN)
rrrr"rXrYr[r]r^r_rrrrrW�s			rWc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+e,e-j.dRdS�dSk�rfdTe+_/dSS)U�SynchronousAssertionsTestsa�
    Tests for L{SynchronousTestCase}'s assertion methods.  That is, failUnless*,
    failIf*, assert* (not covered by other more specific test classes).

    Note: As of 11.2, assertEqual is preferred over the failUnlessEqual(s)
    variants.  Tests have been modified to reflect this preference.

    This is pretty paranoid.  Still, a certain paranoia is healthy if you are
    testing a unit testing framework.
    cCs"|�||�}||kr|�d�dS)Nz)assertEqual should return first parameter)r3r)r�first�second�xrrr�_testEqualPairsz)SynchronousAssertionsTests._testEqualPairc	
Cs�d}z|�||�Wn�|jk
r�}zrt�d�}z|�||�WnR|jk
r�}z2d}t|�}t|�}||kr�|�d||f�W5d}~XYnXW5d}~XYnX|s�|�d||f�dS)z�
        Assert that when called with unequal arguments, C{assertEqual} raises a
        failure exception with the same message as the standard library
        C{assertEqual} would have raised.
        Fr1TzExpected: %r; Got: %rNz'Call to assertEqual(%r, %r) didn't fail)r3r2r+�TestCaser4r)	rrarbZraisedZ
ourFailureZcaseZtheirFailureZgot�expectedrrr�_testUnequalPairs"
6
�z+SynchronousAssertionsTests._testUnequalPaircCs:|�dd�|�dd�|�dgdg�|�dgd�dS)NrFZdogr8�orange)rdrgrrrr�test_assertEqual_basic1sz1SynchronousAssertionsTests.test_assertEqual_basiccCsLtd�}td�}td�}|�||�|�||�|�||�|�||�dS)Nrarb)rrdrg)rrc�y�zrrr�test_assertEqual_custom8sz2SynchronousAssertionsTests.test_assertEqual_customcCs.d}|�|j|jdd|�}|�|t|��dS)zi
        When a message is passed to L{assertEqual} it is included in the error
        message.
        �message�foo�barN)�assertRaisesr2r3rNr4)rrm�	exceptionrrr�test_assertEqualMessageBs�z2SynchronousAssertionsTests.test_assertEqualMessagecCsB|�|j|jddd�}|�|j|jdd�}|�t|�t|��dS)zz
        If a message is specified as L{None}, it is not included in the error
        message of L{assertEqual}.
        rnroN)rpr2r3r4)rZexceptionForNoneZexceptionWithoutrrr�test_assertEqualNoneMessageOs��z6SynchronousAssertionsTests.test_assertEqualNoneMessagecCsft�}dg}z|�||�Wn2|jk
r<|�d�Yn&tk
rNYnX|�d||f�dS)Nrhz6Fail raised when ValueError ought to have been raised.z3Comparing %r and %r should have raised an exception)rr3r2rr)rZapplerhrrr�test_assertEqual_incomparable]s�z8SynchronousAssertionsTests.test_assertEqual_incomparablecCs|�dSrr)r�errorrrr�_raiseErrorlsz&SynchronousAssertionsTests._raiseErrorcCs&|�t|jt�}|�t|t�d�dS)Nz?Expect failUnlessRaises to return instance of raised exception.)�failUnlessRaisesrrvrZ�
isinstance�rrcrrr�test_failUnlessRaises_expectedps�z9SynchronousAssertionsTests.test_failUnlessRaises_expectedcCsVz|�t|jt�Wn2tk
r2|�d�Yn |jk
rFYnX|�d�dS)Nz9failUnlessRaises shouldn't re-raise unexpected exceptionsz4Expected exception wasn't raised. Should have failed)rwrrv�	TypeErrorrr2rrrr� test_failUnlessRaises_unexpectedvsz;SynchronousAssertionsTests.test_failUnlessRaises_unexpectedc
s`d�z|�t�fdd��Wn4|jk
rP}z|�t|�d�W5d}~XYnX|�d�dS)NrIcs�Srrr�ZreturnValuerr�<lambda>��zNSynchronousAssertionsTests.test_failUnlessRaises_noException.<locals>.<lambda>z"ValueError not raised (3 returned)z(Exception not raised. Should have failed)rwrr2r3r4r�rrPrr}r�!test_failUnlessRaises_noException�s
�z<SynchronousAssertionsTests.test_failUnlessRaises_noExceptioncCsl|�|j|j|j�}|�t||j�d|jf�z|�|j|jt�}Wn|jk
r\YnX|�d�dS)Nz#Expected %r instance to be returnedzShould have raised exception)rwr2rvrZrxrrryrrr�&test_failUnlessRaises_failureException�s����zASynchronousAssertionsTests.test_failUnlessRaises_failureExceptionc	Cs4td�}|�t��
}|�W5QRX|�||j�dS)z�
        If C{assertRaises} is used to create a context manager and an exception
        is raised from the body of the C{with} statement then the context
        manager's C{exception} attribute is set to the exception that was
        raised.
        �markerN)rrp�assertIsrq)rrq�contextrrr� test_assertRaisesContextExpected�sz;SynchronousAssertionsTests.test_assertRaisesContextExpectedc
Cs�z"|�t��td��W5QRXWnT|jk
rv}z4t|�}djtt�d�}|�|�|�d�|��W5d}~XYnX|�	d�dS)z�
        If C{assertRaises} is used to create a context manager and the wrong
        exception type is raised from the body of the C{with} statement then
        the C{with} statement raises C{failureException} describing the
        mismatch.
        r�z/{type} raised instead of ValueError:
 Traceback)�typez>Exception message did not begin with expected information: {0}N�:Mismatched exception type should have caused test failure.)
rprr{r2r4�formatrrZ�
startswithr)rrqrmrfrrr�"test_assertRaisesContextUnexpected�s$�����z=SynchronousAssertionsTests.test_assertRaisesContextUnexpectedc
Csbz|�t��W5QRXWn8|jk
rR}zt|�}|�|d�W5d}~XYnX|�d�dS)z�
        If C{assertRaises} is used to create a context manager and no exception
        is raised from the body of the C{with} statement then the C{with}
        statement raises C{failureException} describing the lack of exception.
        z%ValueError not raised (None returned)Nz5Non-exception result should have caused test failure.)rprr2r4r3r)rrqrmrrr�#test_assertRaisesContextNoException�sz>SynchronousAssertionsTests.test_assertRaisesContextNoExceptionc
Cs�z$|�ttf��t��W5QRXWnx|jk
r�}zXt|�}d|k}d|k}g}|rb|�d�|rp|�d�|r�|�d�|�d�	|��W5d}~XYnX|�d�dS)	z�
        If the exception type passed to C{assertRaises} does not have a
        C{__name__} then the context manager still manages to construct a
        descriptive string for it.
        rr{z(expected ValueError in exception messagez'expected TypeError in exception messagez; z
message = {0}Nr�)
rprr{�AttributeErrorr2r4�appendrr-r�)rrqrmZ
valueErrorZ	typeErrorr;rrr�test_brokenName�s"

*�z*SynchronousAssertionsTests.test_brokenNamecCs\dgdgdg}}}|�||�}|�||d�|�|j|j||�|�|j|j||�dS)Nr8rG�)failIfEqual should return first parameter)�failIfEqualr3rwr2�rrcrjrk�retrrr�test_failIfEqual_basic�s���z1SynchronousAssertionsTests.test_failIfEqual_basiccCsXtd�}td�}td�}|�||�}|�||d�|�|j|j||�|�||d�dS)NrarbZfecundr�z"__ne__ should make these not equal)rr�r3rwr2r�rrr�test_failIfEqual_customEq�s��z4SynchronousAssertionsTests.test_failIfEqual_customEqcCs(t�}t�}|�||�}|�||�dS)z�
        C{failIfIdentical} returns its first argument if its first and second
        arguments are not the same object.
        N)�object�failIfIdenticalr3)rrcrjr6rrr�test_failIfIdenticalPositive	sz7SynchronousAssertionsTests.test_failIfIdenticalPositivecCst�}|�|j|j||�dS)z~
        C{failIfIdentical} raises C{failureException} if its first and second
        arguments are the same object.
        N)r�rwr2r�ryrrr�test_failIfIdenticalNegatives�z7SynchronousAssertionsTests.test_failIfIdenticalNegativecCs\dgdgdg}}}|�||�}|�||d�|�|j|j||�|�|j|j||�dS)Nr8rGz1failUnlessIdentical should return first parameter)ZfailUnlessIdenticalr3rwr2r�rrr�test_failUnlessIdenticals���z3SynchronousAssertionsTests.test_failUnlessIdenticalcCsdd\}}}|�||d�|�||d�}|�||d�|�|j|j||d�|�|j|j||d�dS)N)g�?g�������?g333333�?g�������?z4failUnlessApproximates should return first parameterg�������?)ZfailUnlessApproximatesr3rwr2r�rrr�test_failUnlessApproximates)s 
��z6SynchronousAssertionsTests.test_failUnlessApproximatescCs\d}d}d}d}|�|||�|�|||�}|�||d||f�|�|j|j|||�dS)N��A�! @�X�O @��C @z<failUnlessAlmostEqual should return first parameter (%r, %r))ZfailUnlessAlmostEqualr3rwr2�rZ	precisionrcrjrkr�rrr�test_failUnlessAlmostEqual5s
��z5SynchronousAssertionsTests.test_failUnlessAlmostEqualcCsdd}d}d}d}|�|||�}|�||d||f�|�|j|j|||�|�|j|j|||�dS)Nr�r�r�r�z8failIfAlmostEqual should return first parameter (%r, %r))ZfailIfAlmostEqualr3rwr2r�rrr�test_failIfAlmostEqualBs(
���z1SynchronousAssertionsTests.test_failIfAlmostEqualcCs^d}d}d}|�||�|�||�}|�||d�|�|j|j||�|�|j|j||�dS�NrFzthe dog satzthe cat satzshould return first parameter)ZfailUnlessSubstringr3rwr2r�rrr�test_failUnlessSubstringPs ��z3SynchronousAssertionsTests.test_failUnlessSubstringcCs^d}d}d}|�||�|�||�}|�||d�|�|j|j||�|�|j|j||�dSr�)ZfailIfSubstringr3rwr2r�rrr�test_failIfSubstring]s ��z/SynchronousAssertionsTests.test_failIfSubstringcCstd�}|�||�dS)zB
        L{assertIs} passes if two objects are identical.
        raN)rr��r�arrr�
test_assertIsjsz(SynchronousAssertionsTests.test_assertIscCs6td�td�}}|�||�|�|j|j||�dS)zE
        L{assertIs} fails if two objects are not identical.
        raN)rr3rpr2r��rr��brrr�test_assertIsErrorrsz-SynchronousAssertionsTests.test_assertIsErrorcCs.td�td�}}|�||�|�||�dS)zI
        L{assertIsNot} passes if two objects are not identical.
        raN)rr3�assertIsNotr�rrr�test_assertIsNot{sz+SynchronousAssertionsTests.test_assertIsNotcCs td�}|�|j|j||�dS)zD
        L{assertIsNot} fails if two objects are identical.
        raN)rrpr2r�r�rrr�test_assertIsNotError�sz0SynchronousAssertionsTests.test_assertIsNotErrorcCs$tdtfi�}|�}|�||�dS)z<
        Test a true condition of assertIsInstance.
        �AN�r�r��assertIsInstance)rr�r�rrr�test_assertIsInstance�sz0SynchronousAssertionsTests.test_assertIsInstancecCs6tdtfi�}tdtfi�}|�}|�|||f�dS)zR
        Test a true condition of assertIsInstance with multiple classes.
        r��BNr��rr�r�r�rrr�$test_assertIsInstanceMultipleClasses�sz?SynchronousAssertionsTests.test_assertIsInstanceMultipleClassescCs:tdtfi�}tdtfi�}|�}|�|j|j||�dS)z6
        Test an error with assertIsInstance.
        r�r�N�r�r�rpr2r�r�rrr�test_assertIsInstanceError�sz5SynchronousAssertionsTests.test_assertIsInstanceErrorcCsLtdtfi�}tdtfi�}tdtfi�}|�}|�|j|j|||f�dS)zK
        Test an error with assertIsInstance and multiple classes.
        r�r��CNr��rr�r�r�r�rrr�)test_assertIsInstanceErrorMultipleClasses�s
zDSynchronousAssertionsTests.test_assertIsInstanceErrorMultipleClassescCs*|�|j|jdtd�}|�dt|��dS)z�
        If L{TestCase.assertIsInstance} is passed a custom message as its 3rd
        argument, the message is included in the failure exception raised when
        the assertion fails.
        rIzSilly assertionN)rpr2r�r4rN)r�excrrr�"test_assertIsInstanceCustomMessage�s�z=SynchronousAssertionsTests.test_assertIsInstanceCustomMessagecCs2tdtfi�}tdtfi�}|�}|�||�dS)z?
        Test a true condition of assertNotIsInstance.
        r�r�N�r�r��assertNotIsInstancer�rrr�test_assertNotIsInstance�sz3SynchronousAssertionsTests.test_assertNotIsInstancecCsDtdtfi�}tdtfi�}tdtfi�}|�}|�|||f�dS)zT
        Test a true condition of assertNotIsInstance and multiple classes.
        r�r�r�Nr�r�rrr�'test_assertNotIsInstanceMultipleClasses�s
zBSynchronousAssertionsTests.test_assertNotIsInstanceMultipleClassescCsDtdtfi�}|�}|�|j|j||�}|�t|�d||f�dS)z9
        Test an error with assertNotIsInstance.
        r�z%r is an instance of %sN)r�r�rpr2r�r3r4)rr�r�rurrr�test_assertNotIsInstanceError�s�z8SynchronousAssertionsTests.test_assertNotIsInstanceErrorcCs>tdtfi�}tdtfi�}|�}|�|j|j|||f�dS)zN
        Test an error with assertNotIsInstance and multiple classes.
        r�r�N)r�r�rpr2r�r�rrr�,test_assertNotIsInstanceErrorMultipleClasses�szGSynchronousAssertionsTests.test_assertNotIsInstanceErrorMultipleClassescCs|�ddiddi�dS)z�
        L{twisted.trial.unittest.TestCase} supports the C{assertDictEqual}
        method inherited from the standard library in Python 2.7.
        r�r8N)�assertDictEqualrrrr�test_assertDictEqual�sz/SynchronousAssertionsTests.test_assertDictEqualr�Nz:assertDictEqual is not available on this version of Python)0rrrr"rdrgrirlrrrsrtrvrzr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��getattrr
r>�skiprrrrr`sX







			



�r`c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�WarningAssertionTestscCs*dd�}|�tdt|d�}|�|d�dS)z0
        Test basic assertWarns report.
        cSstjdtd�|S�N�Woo deprecated��category��warnings�warn�DeprecationWarning�r�rrrr	�sz:WarningAssertionTests.test_assertWarns.<locals>.deprecatedr��{N��assertWarnsr��__file__r3�rr	�rrrr�test_assertWarns�s
�z&WarningAssertionTests.test_assertWarnscCsHdd�}|�tdt|d�}|�|d�|�tdt|d�}|�|d�dS)z}
        Test that assertWarns cleans the warning registry, so the warning is
        not swallowed the second time.
        cSstjdtd�|Sr�r�r�rrrr	szGWarningAssertionTests.test_assertWarnsRegistryClean.<locals>.deprecatedr�r��ANr�)rr	Zr1Zr2rrr�test_assertWarnsRegistryCleans
�
�z3WarningAssertionTests.test_assertWarnsRegistryCleanc	Cs&dd�}|�|j|jtdt|d�dS)zH
        Test assertWarns failure when no warning is generated.
        cSs|Srrr�rrr�normalsz;WarningAssertionTests.test_assertWarnsError.<locals>.normalr�r�N�rpr2r�r�r�)rr�rrr�test_assertWarnsErrors�z+WarningAssertionTests.test_assertWarnsErrorc	Cs&dd�}|�|j|jtdt|d�dS)zF
        Test assertWarns failure when the category is wrong.
        cSstjdtd�|S�N�Foo deprecatedr�r�r�rrrr	#szGWarningAssertionTests.test_assertWarnsWrongCategory.<locals>.deprecatedr�r�N)rpr2r��UserWarningr��rr	rrr�test_assertWarnsWrongCategorys�z3WarningAssertionTests.test_assertWarnsWrongCategoryc	Cs&dd�}|�|j|jtdt|d�dS)zE
        Test assertWarns failure when the message is wrong.
        cSstjdtd�|Sr�r�r�rrrr	/szFWarningAssertionTests.test_assertWarnsWrongMessage.<locals>.deprecated�Bar deprecatedr�Nr�r�rrr�test_assertWarnsWrongMessage+s�z2WarningAssertionTests.test_assertWarnsWrongMessagec	Cs&dd�}|�|j|jtdt|d�dS)z�
        If the warning emitted by a function refers to a different file than is
        passed to C{assertWarns}, C{failureException} is raised.
        cSstjdtdd�dS)Nr�rG)r��
stacklevelr�r�rrrr	<s

�zCWarningAssertionTests.test_assertWarnsWrongFile.<locals>.deprecatedr�r�Nr�r�rrr�test_assertWarnsWrongFile7s�z/WarningAssertionTests.test_assertWarnsWrongFilecCsRGdd�d�}|�tdt|�}|�t||��|�tdt|�}|�t||��dS)zH
        Test assertWarns works when creating a class instance.
        c@seZdZdd�ZdS)z;WarningAssertionTests.test_assertWarnsOnClass.<locals>.WarncSstjdtd�dS)N�Do not call mer�)r�r��RuntimeWarningrrrrrUszDWarningAssertionTests.test_assertWarnsOnClass.<locals>.Warn.__init__N)rrrrrrrr�WarnTsr�r�N)r�r�r�rZrx)rr�r�rrr�test_assertWarnsOnClassPs
�
�z-WarningAssertionTests.test_assertWarnsOnClasscCsXGdd�d�}|�}|�tdt|jd�}|�|d�|�tdt|jd�}|�|d�dS)zI
        Test assertWarns works when used on an instance method.
        c@seZdZdd�ZdS)z<WarningAssertionTests.test_assertWarnsOnMethod.<locals>.WarncSstjdtd�|S)Nr�r�r�r�rrrr	dszGWarningAssertionTests.test_assertWarnsOnMethod.<locals>.Warn.deprecatedN)rrrr	rrrrr�csr�r�r�N)r�r�r�r	r3�rr��wr�rrr�test_assertWarnsOnMethod_s
�
�z.WarningAssertionTests.test_assertWarnsOnMethodcCsTGdd�d�}|�}|�tdt|d�}|�|d�|�tdt|d�}|�|d�dS)zM
        Test assertWarns works on instance with C{__call__} method.
        c@seZdZdd�ZdS)z:WarningAssertionTests.test_assertWarnsOnCall.<locals>.WarncSstjdtd�|S)N�Egg deprecatedr�r�r�rrr�__call__uszCWarningAssertionTests.test_assertWarnsOnCall.<locals>.Warn.__call__N)rrrr�rrrrr�tsr�r�r�Nr�r�rrr�test_assertWarnsOnCallps
�
�z,WarningAssertionTests.test_assertWarnsOnCallcCs*dd�}|�tdt|d�}|�|d�dS)zD
        Test assertWarns on a warning filtered by default.
        cSstjdtd�|Sr��r�r��PendingDeprecationWarningr�rrrr	�sz@WarningAssertionTests.test_assertWarnsFilter.<locals>.deprecatedr�r�N)r�r�r�r3r�rrr�test_assertWarnsFilter�s�z,WarningAssertionTests.test_assertWarnsFiltercs(dd���fdd�}|�tdt|�dS)z�
        C{assertWarns} does not raise an exception if the function it is passed
        triggers the same warning more than once.
        cSstjdtd�dSr�r�rrrrr	�szJWarningAssertionTests.test_assertWarnsMultipleWarnings.<locals>.deprecatedcs����dSrrrrrr�f�szAWarningAssertionTests.test_assertWarnsMultipleWarnings.<locals>.fr�N)r�r�r�)rr�rrr� test_assertWarnsMultipleWarnings�s�z6WarningAssertionTests.test_assertWarnsMultipleWarningsc	Cs6dd�}|�|j|jtdt|d�}|�t|�d�dS)z�
        For now, assertWarns is unable to handle multiple different warnings,
        so it should raise an exception if it's the case.
        cSs tjdtd�tjdtd�dS)Nr�r�zAnother one)r�r�r�r�r�rrrr	�szKWarningAssertionTests.test_assertWarnsDifferentWarnings.<locals>.deprecatedr�r�zCan't handle different warningsN)rpr2r�r�r�r3r4)rr	rPrrr�!test_assertWarnsDifferentWarnings�s�z7WarningAssertionTests.test_assertWarnsDifferentWarningscsXGdd�dt���fdd�}|d�|��dt|d�|�|g�\}|�|dd�dS)	z�
        Warnings emitted before L{TestCase.assertWarns} is called do not get
        flushed and do not alter the behavior of L{TestCase.assertWarns}.
        c@seZdZdS)zPWarningAssertionTests.test_assertWarnsAfterUnassertedWarning.<locals>.TheWarningN)rrrrrrr�
TheWarning�sr�cstj|�d�dS)Nr�)r�r�)rm�r�rrr��szGWarningAssertionTests.test_assertWarnsAfterUnassertedWarning.<locals>.frnrormN)�Warningr�r��
flushWarningsr3)rr�Zwarningrr�r�&test_assertWarnsAfterUnassertedWarning�sz<WarningAssertionTests.test_assertWarnsAfterUnassertedWarningN)rrrr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sr�c@s�eZdZdZe�Zeed��Zdd�Z	dd�Z
dd�Zd	d
�Zdd�Z
d
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�ResultOfAssertionsTestsz�
    Tests for L{SynchronousTestCase.successResultOf},
    L{SynchronousTestCase.failureResultOf}, and
    L{SynchronousTestCase.assertNoResult}.
    z	Bad timescCs|�|j|jt��dS)z�
        L{SynchronousTestCase.successResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with no current result.
        N)rpr2�successResultOfrrrrr�test_withoutSuccessResult�s
�z1ResultOfAssertionsTests.test_withoutSuccessResultcCs|�|j|jt|j��dS)z�
        L{SynchronousTestCase.successResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with a failure result.
        N)rpr2r�r�failurerrrr�test_successResultOfWithFailure�s
�z7ResultOfAssertionsTests.test_successResultOfWithFailurec
CsTz|�t|j��Wn:|jk
rN}z|�|j��t|��W5d}~XYnXdS)z�
        L{SynchronousTestCase.successResultOf} raises a
        L{SynchronousTestCase.failureException} that has the original failure
        traceback when called with a L{Deferred} with a failure result.
        N)r�rr�r2rN�getTracebackr4r�rrr�+test_successResultOfWithFailureHasTraceback�szCResultOfAssertionsTests.test_successResultOfWithFailureHasTracebackcCs|�|j|jt��dS)z�
        L{SynchronousTestCase.failureResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with no current result.
        N)rpr2�failureResultOfrrrrr�test_withoutFailureResult�s
�z1ResultOfAssertionsTests.test_withoutFailureResultcCs|�|j|jt|j��dS)z�
        L{SynchronousTestCase.failureResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with a success result.
        N)rpr2rrr6rrrr�test_failureResultOfWithSuccess�s
�z7ResultOfAssertionsTests.test_failureResultOfWithSuccesscCs|�|j|jt|j�t�dS)z�
        L{SynchronousTestCase.failureResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with a failure type that was not expected.
        N)rpr2rrr��KeyErrorrrrr�$test_failureResultOfWithWrongFailure�s�z<ResultOfAssertionsTests.test_failureResultOfWithWrongFailurec
Csrz|�t|j�t�WnV|jk
rl}z6|�|j��t|��|�d�tj	tj
�t|��W5d}~XYnXdS)aV
        L{SynchronousTestCase.failureResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with a failure type that was not expected, and the
        L{SynchronousTestCase.failureException} message contains the original
        failure traceback as well as the expected failure type
        z%Failure of type ({0}.{1}) expected onN)rrr�rr2rNrr4r�rrr�rrr�6test_failureResultOfWithWrongFailureOneExpectedFailures��zNResultOfAssertionsTests.test_failureResultOfWithWrongFailureOneExpectedFailurecCs|z|�t|j�tt�Wn^|jk
rv}z>|�|j��t|��|�d�	tj
tjtj
tj�t|��W5d}~XYnXdS)at
        L{SynchronousTestCase.failureResultOf} raises
        L{SynchronousTestCase.failureException} when called with a L{Deferred}
        with a failure type that was not expected, and the
        L{SynchronousTestCase.failureException} message contains the original
        failure traceback as well as the expected failure types in the error
        message
        z0Failure of type ({0}.{1} or {2}.{3}) expected onN)rrr�r�IOErrorr2rNrr4r�rrr�rrr�8test_failureResultOfWithWrongFailureMultiExpectedFailures	��zPResultOfAssertionsTests.test_failureResultOfWithWrongFailureMultiExpectedFailurecCs|�|j|�t|j���dS)a
        When passed a L{Deferred} which currently has a result (ie,
        L{Deferred.addCallback} would cause the added callback to be called
        before C{addCallback} returns), L{SynchronousTestCase.successResultOf}
        returns that result.
        N)�assertIdenticalr6r�rrrrr�test_withSuccessResult's�z.ResultOfAssertionsTests.test_withSuccessResultcCs&|�|j|�t|j�|jjt��dS)a7
        When passed a L{Deferred} which currently has a L{Failure} result (ie,
        L{Deferred.addErrback} would cause the added errback to be called
        before C{addErrback} returns), L{SynchronousTestCase.failureResultOf}
        returns that L{Failure} if that L{Failure}'s type is expected.
        N)r
r�rrr�rrrrr�test_withExpectedFailureResult2s��z6ResultOfAssertionsTests.test_withExpectedFailureResultcCs|�|j|�t|j���dS)a
        When passed a L{Deferred} which currently has a L{Failure} result
        (ie, L{Deferred.addErrback} would cause the added errback to be called
        before C{addErrback} returns), L{SynchronousTestCase.failureResultOf}
        returns that L{Failure}.
        N)r
r�rrrrrr�test_withFailureResult?s�z.ResultOfAssertionsTests.test_withFailureResultcCs|�|j|jt|j��dS)z�
        When passed a L{Deferred} which currently has a success result (see
        L{test_withSuccessResult}), L{SynchronousTestCase.assertNoResult} raises
        L{SynchronousTestCase.failureException}.
        N)rpr2�assertNoResultrr6rrrr�test_assertNoResultSuccessJs
�z2ResultOfAssertionsTests.test_assertNoResultSuccesscCs|�|j|jt|j��dS)z�
        When passed a L{Deferred} which currently has a failure result (see
        L{test_withFailureResult}), L{SynchronousTestCase.assertNoResult} raises
        L{SynchronousTestCase.failureException}.
        N)rpr2rrr�rrrr�test_assertNoResultFailureTs
�z2ResultOfAssertionsTests.test_assertNoResultFailurecCs|�t��dS)zC
        When passed a L{Deferred} with no current result,
        N)rrrrrr�test_assertNoResult^sz+ResultOfAssertionsTests.test_assertNoResultcCs4t�}|�|�|�|j�|�|j|�|��dS)z�
        When passed a L{Deferred} with no current result, which is then
        fired with a success result, L{SynchronousTestCase.assertNoResult}
        doesn't modify the result of the L{Deferred}.
        N)rr�callbackr6r3r��r�drrr�$test_assertNoResultPropagatesSuccesses
z<ResultOfAssertionsTests.test_assertNoResultPropagatesSuccesscCs4t�}|�|�|�|j�|�|j|�|��dS)z�
        When passed a L{Deferred} with no current result, which is then
        fired with a L{Failure} result, L{SynchronousTestCase.assertNoResult}
        doesn't modify the result of the L{Deferred}.
        N)rrZerrbackr�r3rrrrr�)test_assertNoResultPropagatesLaterFailureqs
zAResultOfAssertionsTests.test_assertNoResultPropagatesLaterFailurecCsFt|j�}z|�|�Wn|jk
r.YnX|�d|�|��dS)z�
        When passed a L{Deferred} which currently has a L{Failure} result,
        L{SynchronousTestCase.assertNoResult} changes the result of the
        L{Deferred} to a success.
        N)rr�rr2r3r�rrrr�+test_assertNoResultSwallowsImmediateFailure}s
zCResultOfAssertionsTests.test_assertNoResultSwallowsImmediateFailureN)rrrr"r�r6r�	Exceptionr�r�r�rrrrrr	rrr
rrrrrrrrrrr��s(


	


r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�AssertionNamesTestszK
    Tests for consistency of naming within TestCase assertion methods
    cs"i�t|�d��fdd��D�S)N�assertcs&g|]}|�d�s|dkr�|�qS)ZNot�_)r�)�.0�k�Zdctrr�
<listcomp>�s
z3AssertionNamesTests._getAsserts.<locals>.<listcomp>)rrrrr�_getAsserts�szAssertionNamesTests._getAssertscCs|jSr)rryrrr�_name�szAssertionNamesTests._namecCs0t|���}tt|d��}|�||�|��dS)a�
        The C{failUnless*} test methods are a subset of the C{assert*} test
        methods.  This is intended to ensure that methods using the
        I{failUnless} naming scheme are not added without corresponding methods
        using the I{assert} naming scheme.  The I{assert} naming scheme is
        preferred, and new I{assert}-prefixed methods may be added without
        corresponding I{failUnless}-prefixed methods.
        r\N)�setr rr3�intersection)r�assertsZfailUnlessesrrr�test_failUnlessMatchesAssert�s	�z0AssertionNamesTests.test_failUnlessMatchesAssertcCs<ttjd�}ttjd�}|�t||jd�t||jd��dS)NZ	assertNotrR)�key)rr
r>r3�sortedr!)rr$ZfailIfsrrr�test_failIf_matches_assertNot�s
�z1AssertionNamesTests.test_failIf_matches_assertNotc	Cs�t|���D]�\}}t|�sq|�d�r\|�t||d�d||f�|�|t||d��|�d�r|�t||dd��d||dd�f�|�|t||dd���qdS)NZEqual�sz
%s but no %ssZEquals���z%s but no %s)�vars�items�callable�endswithrZ�hasattrr3r�)rr�valuerrr�test_equalSpelling�s

�
�z&AssertionNamesTests.test_equalSpellingN)	rrrr"r r!r%r(r1rrrrr�src@sVeZdZdZedddd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdS)�CallDeprecatedTestsz\
    Test use of the L{SynchronousTestCase.callDeprecated} method with version objects.
    ZTwisted�rcCs&|�|jtd�|�|��gd�dS)zj
        callDeprecated calls a deprecated callable, suppressing the
        deprecation warning.
        rnzNo warnings should be shownN)�callDeprecated�version�	oldMethodr3r�rrrr�$test_callDeprecatedSuppressesWarning�s�z8CallDeprecatedTests.test_callDeprecatedSuppressesWarningcCs |�|jtd�}|�d|�dS)zn
        L{callDeprecated} actually calls the callable passed to it, and
        forwards the result.
        rnN)r4r5r6r3r5rrr� test_callDeprecatedCallsFunction�sz4CallDeprecatedTests.test_callDeprecatedCallsFunctioncCs6dd�}|�|j|j|j|�}|�d|t|��dS)zd
        L{callDeprecated} raises a test failure if the callable is not
        deprecated.
        cSsdSrrrrrr�
notDeprecated�szGCallDeprecatedTests.test_failsWithoutDeprecation.<locals>.notDeprecatedz%r is not deprecated.N)rpr2r4r5r3r4)rr9rqrrr�test_failsWithoutDeprecation�s��z0CallDeprecatedTests.test_failsWithoutDeprecationcCsRtdddd�}|�|j|j|td�}|�t|j�t|��|�t|�t|��dS)z�
        callDeprecated raises a test failure if the callable was deprecated
        at a different version to the one expected.
        �Foor8rGrIrnN)	r
rpr2r4r6rNrr5r4)r�differentVersionrqrrr�"test_failsWithIncorrectDeprecation�s�z6CallDeprecatedTests.test_failsWithIncorrectDeprecationcCsTtdddd�}dd�}t|�|�}|�||d�|��}|�t|�dd�|��d	S)
a:
        L{callDeprecated} ignores all deprecations apart from the first.

        Multiple warnings are generated when a deprecated function calls
        another deprecated function. The first warning is the one generated by
        the explicitly called function. That's the warning that we care about.
        r;r8rGrIcWst|�Sr)r6)�argsrrr�nestedDeprecation�szECallDeprecatedTests.test_nestedDeprecation.<locals>.nestedDeprecation�zUnexpected warnings: {}N)r
r	r4r�r3r<r�)rr<r?Z
warningsShownrrr�test_nestedDeprecation�s�z*CallDeprecatedTests.test_nestedDeprecationcCs|�|jdftd�dS)zj
        L{callDeprecated} can take a message argument used to check the warning
        emitted.
        �	newMethodr8N)r4r5�oldMethodReplacedrrrr�test_callDeprecationWithMessage
s�z3CallDeprecatedTests.test_callDeprecationWithMessagecCsF|�|j|j|jdftd�}|�t|j�t|��|�dt|��dS)z|
        If the message passed to L{callDeprecated} doesn't match,
        L{callDeprecated} raises a test failure.
        zsomething.wrongr8zplease use newMethod insteadN)rpr2r4r5rCrNrr4)rrqrrr�$test_callDeprecationWithWrongMessages�z8CallDeprecatedTests.test_callDeprecationWithWrongMessageN)
rrrr"r
r5r7r8r:r=rArDrErrrrr2�s
		r2cCs|S)z(
    Deprecated method for testing.
    r�rcrrrr6#sr6rB)ZreplacementcCsd|S)zh
    Another deprecated method, which has been deprecated in favor of the
    mythical 'newMethod'.
    rGrrFrrrrC+srC))r"Z
__future__rrr�r
r+Ztwisted.python.utilrZtwisted.python.reflectrrrZtwisted.python.deprecater	Zincrementalr
rZtwisted.python.failurerZ
twisted.trialZtwisted.internet.deferrrrr�rrrer%r>r?rWr`r�r�rr2r5r6rCrrrr�<module>s:9MMsES0g