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: //proc/self/root/lib/python3/dist-packages/twisted/trial/test/__pycache__/test_tests.cpython-38.pyc
U


W[n��@s�dZddlmZmZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlmZmZddlmZmZmZddlmZdd	lmZdd
lmZddlmZmZmZGdd
�d
e�ZGdd�de�ZGdd�deej �Z!Gdd�deej"�Z#Gdd�de�Z$Gdd�de$ej �Z%Gdd�de$ej"�Z&Gdd�de�Z'Gdd�de'ej �Z(Gdd�de'ej"�Z)Gd d!�d!e�Z*Gd"d#�d#e*ej �Z+Gd$d%�d%e*ej"�Z,Gd&d'�d'e�Z-Gd(d)�d)e-ej �Z.Gd*d+�d+e-ej"�Z/Gd,d-�d-e�Z0Gd.d/�d/e0ej �Z1Gd0d1�d1e0ej"�Z2Gd2d3�d3ej �Z3Gd4d5�d5e�Z4Gd6d7�d7e4ej �Z5Gd8d9�d9e4ej"�Z6Gd:d;�d;eej"�Z7Gd<d=�d=e�Z8Gd>d?�d?e8ej �Z9Gd@dA�dAe8ej �Z:GdBdC�dCej �Z;GdDdE�dEe�Z<GdFdG�dGe<ej �Z=GdHdI�dIe<ej"�Z>GdJdK�dKe�Z?GdLdM�dMe?ej �Z@GdNdO�dOe?ej"�ZAGdPdQ�dQe�ZBGdRdS�dSeBej �ZCGdTdU�dUeBej"�ZDGdVdW�dWe�ZEGdXdY�dYeEej �ZFGdZd[�d[eEej"�ZGGd\d]�d]e�ZHGd^d_�d_eHej �ZIGd`da�daeHej"�ZJGdbdc�dcej �ZKdS)da�
Tests for the behaviour of unit tests.

Many tests in this module follow a simple pattern.  A mixin is defined which
includes test methods for a certain feature.  The mixin is inherited from twice,
once by a class also inheriting from SynchronousTestCase and once from a class
inheriting from TestCase.  These two subclasses are named like
I{SynchronousFooTests} and I{AsynchronousFooTests}, where I{Foo} is related to
the name of the mixin.  Sometimes the mixin is defined in another module, along
with the synchronous subclass.  The mixin is imported into this module to define
the asynchronous subclass.

This pattern allows the same tests to be applied to the two base test case
classes trial provides, ensuring their behavior is the same.

Most new tests should be added in this pattern.  Tests for functionality which
is intentionally only provided by TestCase, not SynchronousTestCase, is excepted
of course.
�)�division�absolute_importN)�NativeStringIO�_PY3)�namedAny)�defer�reactor)�unittest�reporter�util)�runner)�	erroneous)�SuppressionMixin)�_clearSuite� _ForceGarbageCollectionDecorator�
_iterateTestsc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ResultsTestMixinzG
    Provide useful APIs for test cases that are about test cases.
    cCs&t��|_|j�|�|_t��|_dS)zt
        Load tests from the given test case class and create a new reporter to
        use for running it.
        N)�pyunit�
TestLoader�loader�loadTestsFromTestCase�suiter
�
TestResult��selfr�r�?/usr/lib/python3/dist-packages/twisted/trial/test/test_tests.py�	loadSuite0s
zResultsTestMixin.loadSuitecCsD|�|j���|�|jjg�|�|jjg�|�|jjg�dS)z 
        test the setup
        N)�
assertTruer
�
wasSuccessful�assertEqual�errors�failures�skips�rrrr�
test_setUp9szResultsTestMixin.test_setUpcCs2|�|j��|�|�|j�|�|jj|�dS)z:
        Asserts that the test count is plausible
        N)r r�countTestCasesr
ZtestsRun)rZnumTestsrrr�assertCountBszResultsTestMixin.assertCountN)�__name__�
__module__�__qualname__�__doc__rr%r'rrrrr,s		rc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�SuccessMixinz\
    Tests for the reporting of successful tests in L{twisted.trial.unittest.TestCase}.
    cCst��|_dS��%
        Setup our test case
        N)r
r�resultr$rrr�setUpOszSuccessMixin.setUpcCsdS)z9
        A successful test, used by other tests.
        Nrr$rrr�test_successfulUszSuccessMixin.test_successfulcCsX|�|jd�|�|jg�|�|jg�|�|jg�|�|jg�|�|jg�dS)zd
        Utility function -- assert there is one success and the state is
        plausible
        �N)r �	successesr"r!�expectedFailures�unexpectedSuccessesr#�r�testr/rrr�assertSuccessfulZszSuccessMixin.assertSuccessfulcCs(|�d�}|�|j�|�||j�dS)z�
        Test that when a successful test is run, it is reported as a success,
        and not as any other kind of result.
        r1N��	__class__�runr/r8�rr7rrr�test_successfulIsReportedfs
z&SuccessMixin.test_successfulIsReportedcCs&|��}|�|j�|�||j�dS)zz
        The test case type can be instantiated with no arguments, run, and
        reported as being successful.
        Nr9r<rrr�test_defaultIsSuccessfulosz%SuccessMixin.test_defaultIsSuccessfulcCsJ|�d�}t�|�}|�|j�|�||j�~t��|�|�d�dS)zF
        Test that no reference is kept on a successful test.
        r1N)	r:�weakref�refr;r/r8�gc�collect�assertIdentical)rr7r@rrr�test_noReferencexs

zSuccessMixin.test_noReferenceN)
r(r)r*r+r0r1r8r=r>rDrrrrr,Ks		r,c@seZdZdZdS)�SynchronousSuccessTests�N
    Tests for the reporting of successful tests in the synchronous case.
    N�r(r)r*r+rrrrrE�srEc@seZdZdZdS)�AsynchronousSuccessTestsrFNrGrrrrrH�srHc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�SkipMethodsMixinzZ
    Tests for the reporting of skipping tests in L{twisted.trial.unittest.TestCase}.
    cCs|�|j�dSr-)r�Skippingr$rrrr0�szSkipMethodsMixin.setUpcCs|�d�dS)z4
        Assert that there are three tests.
        �N�r'r$rrr�
test_counting�szSkipMethodsMixin.test_countingcCsd|�|j�|�|j���|�|jjg�|�|jjg�|�t|jj�d�|�|jj	d�dS)z�
        Running a suite in which all methods are individually set to skip
        produces a successful result with no recorded errors or failures, all
        the skipped methods recorded as skips, and no methods recorded as
        successes.
        rKrN�
rr
rrr r!r"�lenr#r3r$rrr�test_results�szSkipMethodsMixin.test_resultscCsp|�|j�|�|j�|�|j���|�|jjg�|�|jjg�|�t	|jj
�d�|�|jjd�dS)a	
        Running a suite in which all methods are skipped by C{setUp} raising
        L{SkipTest} produces a successful result with no recorded errors or
        failures, all skipped methods recorded as skips, and no methods recorded
        as successes.
        �rN)r�
SkippingSetUprr
rrr r!r"rOr#r3r$rrrr%�szSkipMethodsMixin.test_setUpcCsF|�|j�d}|jjD](\}}|�|��t|�d�t|��qdS)z(
        Test that reasons work
        Ztest_N)rr
r#r ZshortDescriptionrO�str)r�prefixr7�reasonrrr�test_reasons�s�zSkipMethodsMixin.test_reasonscCsd|�|j�|�|j�|�|jjg�}|�dt|��|�t|dd�|�d|dd�dS)zo
        If a test method raises L{SkipTest} with no reason, a deprecation
        warning is emitted.
        r2r�categoryzSDo not raise unittest.SkipTest with no arguments! Give a reason for skipping tests!�messageN)	r�DeprecatedReasonlessSkiprr
Z
flushWarningsZtest_1r rO�DeprecationWarning)r�warningsrrr� test_deprecatedSkipWithoutReason�s�
�z1SkipMethodsMixin.test_deprecatedSkipWithoutReasonN)
r(r)r*r+r0rMrPr%rVr\rrrrrI�srIc@s(eZdZdZed�Zed�Zed�ZdS)�SynchronousSkipMethodTestsz�
    Tests for the reporting of skipping tests in the synchronous case.

    See: L{twisted.trial.test.test_tests.SkipMethodsMixin}
    z/twisted.trial.test.skipping.SynchronousSkippingz4twisted.trial.test.skipping.SynchronousSkippingSetUpz?twisted.trial.test.skipping.SynchronousDeprecatedReasonlessSkipN�r(r)r*r+rrJrRrYrrrrr]�s��r]c@s(eZdZdZed�Zed�Zed�ZdS)�AsynchronousSkipMethodTestsz�
    Tests for the reporting of skipping tests in the asynchronous case.

    See: L{twisted.trial.test.test_tests.SkipMethodsMixin}
    z0twisted.trial.test.skipping.AsynchronousSkippingz5twisted.trial.test.skipping.AsynchronousSkippingSetUpz@twisted.trial.test.skipping.AsynchronousDeprecatedReasonlessSkipNr^rrrrr_�s��r_c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�SkipClassesMixinzQ
    Test the class skipping features of L{twisted.trial.unittest.TestCase}.
    cCs|�|j�d|j_dS)r.FN)r�SkippedClass�	_setUpRanr$rrrr0�szSkipClassesMixin.setUpcCs|�d�dS)zP
        Skipped test methods still contribute to the total test count.
        �NrLr$rrrrM�szSkipClassesMixin.test_countingcCs|�|j�|�|jj�dS)zP
        The C{setUp} method is not called if the class is set to skip.
        N)rr
�assertFalserarbr$rrr�
test_setUpRanszSkipClassesMixin.test_setUpRancCsd|�|j�|�|j���|�|jjg�|�|jjg�|�t|jj�d�|�|jj	d�dS)a
        Skipped test methods don't cause C{wasSuccessful} to return C{False},
        nor do they contribute to the C{errors} or C{failures} of the reporter,
        or to the count of successes.  They do, however, add elements to the
        reporter's C{skips} list.
        rcrNrNr$rrrrPszSkipClassesMixin.test_resultscCs:|�|j�ddddg}dd�|jjD�}|�||�dS)z�
        Test methods which raise L{unittest.SkipTest} or have their C{skip}
        attribute set to something are skipped.
        �classZskip2cSsg|]\}}|�qSrr)�.0r7rUrrr�
<listcomp>"sz1SkipClassesMixin.test_reasons.<locals>.<listcomp>N)rr
r#r �r�expectedReasonsZreasonsGivenrrrrVszSkipClassesMixin.test_reasonsN)	r(r)r*r+r0rMrerPrVrrrrr`�sr`c@seZdZdZed�ZdS)�SynchronousSkipClassTestsz
    Test the class skipping features in the synchronous case.

    See: L{twisted.trial.test.test_tests.SkipClassesMixin}
    z3twisted.trial.test.skipping.SynchronousSkippedClassN�r(r)r*r+rrarrrrrk's�rkc@seZdZdZed�ZdS)�AsynchronousSkipClassTestsz�
    Test the class skipping features in the asynchronous case.

    See: L{twisted.trial.test.test_tests.SkipClassesMixin}
    z4twisted.trial.test.skipping.AsynchronousSkippedClassNrlrrrrrm2s�rmc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�	TodoMixinzv
    Tests for the individual test method I{expected failure} features of
    L{twisted.trial.unittest.TestCase}.
    cCs|�|j�dSr-)r�Todor$rrrr0BszTodoMixin.setUpcCs|�d�dS)z9
        Ensure that we've got three test cases.
        rKNrLr$rrrrMHszTodoMixin.test_countingcCs�|�|j�|�|j���|�|jjg�|�|jjg�|�|jjg�|�t|jj	�d�|�t|jj
�d�|�|jjd�dS)a�
        Running a suite in which all methods are individually marked as expected
        to fail produces a successful result with no recorded errors, failures,
        or skips, all methods which fail and were expected to fail recorded as
        C{expectedFailures}, and all methods which pass but which were expected
        to fail recorded as C{unexpectedSuccesses}.  Additionally, no tests are
        recorded as successes.
        rQr2rN�rr
rrr r!r"r#rOr4r5r3r$rrrrPNs	zTodoMixin.test_resultscCs6|�|j�ddg}dd�|jjD�}|�||�dS)�E
        Ensure that expected failures are handled properly.
        �todo1�todo2cSsg|]\}}}|j�qSr�rU�rg�t�e�rrrrrhfs�z3TodoMixin.test_expectedFailures.<locals>.<listcomp>N�rr
r4r rirrr�test_expectedFailures`s�zTodoMixin.test_expectedFailurescCs4|�|j�dg}dd�|jjD�}|�||�dS)�>
        Ensure that unexpected successes are caught.
        Ztodo3cSsg|]\}}|j�qSrrt�rgrvrxrrrrhps�z6TodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>N�rr
r5r rirrr�test_unexpectedSuccessesjs�z"TodoMixin.test_unexpectedSuccessescCs�|�|j�|�|j�|�|j���|�t|jj�d�|�|jj	g�|�|jj
g�|�t|jj�d�|�t|jj�d�|�|jj
d�dS)z|
        C{setUp} is excluded from the failure expectation defined by a C{todo}
        attribute on a test method.
        r2rN)r�	SetUpTodorr
rdrr rOr!r"r#r4r5r3r$rrr�test_expectedSetUpFailuretsz#TodoMixin.test_expectedSetUpFailurecCs�|�|j�|�|j�|�|j���|�t|jj�d�|�|jj	g�|�|jj
g�|�t|jj�d�|�t|jj�d�|�|jj
d�dS)z
        C{tearDown} is excluded from the failure expectation defined by a C{todo}
        attribute on a test method.
        r2rN)r�TearDownTodorr
rdrr rOr!r"r#r4r5r3r$rrr�test_expectedTearDownFailure�sz&TodoMixin.test_expectedTearDownFailureN)r(r)r*r+r0rMrPrzr~r�r�rrrrrn=s

rnc@s(eZdZdZed�Zed�Zed�ZdS)�SynchronousTodoTestszx
    Test the class skipping features in the synchronous case.

    See: L{twisted.trial.test.test_tests.TodoMixin}
    z+twisted.trial.test.skipping.SynchronousTodoz0twisted.trial.test.skipping.SynchronousSetUpTodoz3twisted.trial.test.skipping.SynchronousTearDownTodoN�r(r)r*r+rrorr�rrrrr��s�r�c@s(eZdZdZed�Zed�Zed�ZdS)�AsynchronousTodoTestszy
    Test the class skipping features in the asynchronous case.

    See: L{twisted.trial.test.test_tests.TodoMixin}
    z,twisted.trial.test.skipping.AsynchronousTodoz1twisted.trial.test.skipping.AsynchronousSetUpTodoz4twisted.trial.test.skipping.AsynchronousTearDownTodoNr�rrrrr��s�r�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ClassTodoMixinzj
    Tests for the class-wide I{expected failure} features of
    L{twisted.trial.unittest.TestCase}.
    cCs|�|j�dSr-)r�	TodoClassr$rrrr0�szClassTodoMixin.setUpcCs|�d�dS)z8
        Ensure that we've got four test cases.
        rcNrLr$rrrrM�szClassTodoMixin.test_countingcCs�|�|j�|�|j���|�|jjg�|�|jjg�|�|jjg�|�t|jj	�d�|�t|jj
�d�|�|jjd�dS)a�
        Running a suite in which an entire class is marked as expected to fail
        produces a successful result with no recorded errors, failures, or
        skips, all methods which fail and were expected to fail recorded as
        C{expectedFailures}, and all methods which pass but which were expected
        to fail recorded as C{unexpectedSuccesses}.  Additionally, no tests are
        recorded as successes.
        rQrNrpr$rrrrP�s	zClassTodoMixin.test_resultscCs6|�|j�ddg}dd�|jjD�}|�||�dS)rq�methodrfcSsg|]\}}}|j�qSrrtrurrrrh�s�z8ClassTodoMixin.test_expectedFailures.<locals>.<listcomp>Nryrirrrrz�s�z$ClassTodoMixin.test_expectedFailurescCs6|�|j�ddg}dd�|jjD�}|�||�dS)r{r�rfcSsg|]\}}|j�qSrrtr|rrrrh�s�z;ClassTodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>Nr}rirrrr~�s�z'ClassTodoMixin.test_unexpectedSuccessesN�	r(r)r*r+r0rMrPrzr~rrrrr��s
r�c@seZdZdZed�ZdS)�SynchronousClassTodoTestsz�
    Tests for the class-wide I{expected failure} features in the synchronous case.

    See: L{twisted.trial.test.test_tests.ClassTodoMixin}
    z0twisted.trial.test.skipping.SynchronousTodoClassN�r(r)r*r+rr�rrrrr��sr�c@seZdZdZed�ZdS)�AsynchronousClassTodoTestsz�
    Tests for the class-wide I{expected failure} features in the asynchronous case.

    See: L{twisted.trial.test.test_tests.ClassTodoMixin}
    z1twisted.trial.test.skipping.AsynchronousTodoClassNr�rrrrr��sr�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�StrictTodoMixinz�
    Tests for the I{expected failure} features of
    L{twisted.trial.unittest.TestCase} in which the exact failure which is
    expected is indicated.
    cCs|�|j�dSr-)r�
StrictTodor$rrrr0szStrictTodoMixin.setUpcCs|�d�dS)z3
        Assert there are seven test cases
        �NrLr$rrrrM
szStrictTodoMixin.test_countingcCs�|�|j�|�|j���|�t|jj�d�|�t|jj�d�|�t|jj�d�|�t|jj	�d�|�|jj
d�|�|jjg�dS)z�
        A test method which is marked as expected to fail with a particular
        exception is only counted as an expected failure if it does fail with
        that exception, not if it fails with some other exception.
        rQr2rKrN)rr
rdrr rOr!r"r4r5r3r#r$rrrrPszStrictTodoMixin.test_resultscCs8|�|j�dddg}dd�|jjD�}|�||�dS)rqrrrsZtodo5cSsg|]\}}}|j�qSrrtrurrrrh%s�z9StrictTodoMixin.test_expectedFailures.<locals>.<listcomp>Nry�rrjZ
reasonsGottenrrrrzs
�z%StrictTodoMixin.test_expectedFailurescCs:|�|j�tgdfg}dd�|jjD�}|�||�dS)r{Ztodo7cSsg|]\}}|j|jf�qSr)r!rUr|rrrrh/s�z<StrictTodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>N)rr
�RuntimeErrorr5r r�rrrr~)s�z(StrictTodoMixin.test_unexpectedSuccessesNr�rrrrr��s
r�c@seZdZdZed�ZdS)�SynchronousStrictTodoTestsz�
    Tests for the expected failure case when the exact failure that is expected
    is indicated in the synchronous case

    See: L{twisted.trial.test.test_tests.StrictTodoMixin}
    z1twisted.trial.test.skipping.SynchronousStrictTodoN�r(r)r*r+rr�rrrrr�5sr�c@seZdZdZed�ZdS)�AsynchronousStrictTodoTestsz�
    Tests for the expected failure case when the exact failure that is expected
    is indicated in the asynchronous case

    See: L{twisted.trial.test.test_tests.StrictTodoMixin}
    z2twisted.trial.test.skipping.AsynchronousStrictTodoNr�rrrrr�@sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�ReactorCleanupTestszc
    Tests for cleanup and reporting of reactor event sources left behind by test
    methods.
    cCst�t��|_t��|_dSr-)r
�Reporterrr/rrrr$rrrr0QszReactorCleanupTests.setUpcCs^|j�d�}|�|j�|�|j���|�|jjd�|jjdd}|�	|�
tj��dS)zm
        Trial reports a L{util.DirtyReactorAggregateError} if a test leaves
        sockets behind.
        z@twisted.trial.test.erroneous.SocketOpenTest.test_socketsLeftOpenr2rN)
rZ
loadByNamer;r/rdrr r3r!r�checkr�DirtyReactorAggregateError�rrZfailurerrr�test_leftoverSocketsYs�z(ReactorCleanupTests.test_leftoverSocketscCs\t�d�}|�|j�|�|j���|jjdd}|�|jjd�|�	|�
tj��dS)z�
        Trial reports a L{util.DirtyReactorAggregateError} and fails the test
        if a test leaves a L{DelayedCall} hanging.
        �test_leftoverPendingCallsrr2N)
r
r�r;r/rdrr!r r3rr�rr�r�rrrr�js
z-ReactorCleanupTests.test_leftoverPendingCallsN)r(r)r*r+r0r�r�rrrrr�Ksr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�FixtureMixinzB
    Tests for fixture helper methods (e.g. setUp, tearDown).
    cCst��|_t��|_dSr-)r
r�rrrr$rrrr0|s
zFixtureMixin.setUpcCs`|j�|j�}|�|j�|�t|jj�dk�|�|jjddj	t
j�|�d|jj
�dS)zO
        When setUp fails, the error is recorded in the result object.
        rr2N)rr�TestFailureInSetUpr;r
rrOr!�assertIsInstance�valuer
�FoolishErrorr r3rrrr�test_brokenSetUp�s�zFixtureMixin.test_brokenSetUpcCs`|j�|j�}|�|j�|jj}|�t|�dk�|�|ddj	t
j�|�d|jj
�dS)zR
        When tearDown fails, the error is recorded in the result object.
        rr2N)rr�TestFailureInTearDownr;r
r!rrOr�r�r
r�r r3)rrr!rrr�test_brokenTearDown�sz FixtureMixin.test_brokenTearDowncCs�|j�|j�}t|�d}|�|j�|�|j�|jj}|�	t
|�dk�|�|ddjt
j�|�d|jj�|�	|j�dS)zP
        L{SynchronousTestCase.tearDown} runs when a test method fails.
        rr2N)rr�TestFailureButTearDownRuns�listrdZtornDownr;r
r!rrOr�r�r
r�r r3)rrZcaser!rrr�test_tearDownRunsOnTestFailure�s�z+FixtureMixin.test_tearDownRunsOnTestFailureN)r(r)r*r+r0r�r�r�rrrrr�xs
r�c@s(eZdZdZed�Zed�Zed�ZdS)�SynchronousFixtureTestsz�
    Tests for broken fixture helper methods in the synchronous case

    See: L{twisted.trial.test.test_tests.FixtureMixin}
    z:twisted.trial.test.erroneous.SynchronousTestFailureInSetUpz=twisted.trial.test.erroneous.SynchronousTestFailureInTearDownzBtwisted.trial.test.erroneous.SynchronousTestFailureButTearDownRunsN�r(r)r*r+rr�r�r�rrrrr��s���r�c@s(eZdZdZed�Zed�Zed�ZdS)�AsynchronousFixtureTestsz�
    Tests for broken fixture helper methods in the asynchronous case

    See: L{twisted.trial.test.test_tests.FixtureMixin}
    z;twisted.trial.test.erroneous.AsynchronousTestFailureInSetUpz>twisted.trial.test.erroneous.AsynchronousTestFailureInTearDownzCtwisted.trial.test.erroneous.AsynchronousTestFailureButTearDownRunsNr�rrrrr��s���r�c@s0eZdZdZed�Zed�Zed�Zed�ZdS)�AsynchronousSuppressionTestsz�
    Tests for the warning suppression features of
    L{twisted.trial.unittest.TestCase}

    See L{twisted.trial.test.test_suppression.SuppressionMixin}
    z?twisted.trial.test.suppression.AsynchronousTestSetUpSuppressionzBtwisted.trial.test.suppression.AsynchronousTestTearDownSuppressionz:twisted.trial.test.suppression.AsynchronousTestSuppressionz;twisted.trial.test.suppression.AsynchronousTestSuppression2N)	r(r)r*r+rZTestSetUpSuppressionZTestTearDownSuppressionZTestSuppressionZTestSuppression2rrrrr��s����r�c@sBeZdZdZGdd�dej�Zdd�Zdd�Zdd	�Z	d
d�Z
dS)
�GCMixinz�
    I provide a few mock tests that log setUp, tearDown, test execution and
    garbage collection. I'm used to test whether gc.collect gets called.
    c@s(eZdZdZdd�Zdd�Zdd�ZdS)	zGCMixin.BasicTestz#
        Mock test to run.
        cCs|�d�dS)z$
            Mock setUp
            r0N��_logr$rrrr0�szGCMixin.BasicTest.setUpcCs|�d�dS)z(
            Mock test case
            r7Nr�r$rrr�test_foo�szGCMixin.BasicTest.test_foocCs|�d�dS)z,
            Mock tear tearDown
            �tearDownNr�r$rrrr��szGCMixin.BasicTest.tearDownN)r(r)r*r+r0r�r�rrrr�	BasicTest�sr�cCs|j�|�dS)z
        Log function
        N)�_collectCalled�append)r�msgrrrr��szGCMixin._logcCs|�d�dS)zFake gc.collectrBNr�r$rrrrB�szGCMixin.collectcCs$g|_|j|j_tj|_|jt_dSr-)r�r�r�rArB�_oldCollectr$rrrr0s
z
GCMixin.setUpcCs|jt_dS�z$
        Tear down the test
        N)r�rArBr$rrrr�szGCMixin.tearDownN)r(r)r*r+r	�SynchronousTestCaser�r�rBr0r�rrrrr��s	r�c@seZdZdZdd�ZdS)�GarbageCollectionDefaultTestsz@
    By default, tests should not force garbage collection.
    cCs4|�d�}t��}|�|�|�|jdddg�dS)zH
        By default, tests should not force garbage collection.
        r�r0r7r�N)r�r
rr;r r�r6rrr�test_collectNotDefaults

z4GarbageCollectionDefaultTests.test_collectNotDefaultN)r(r)r*r+r�rrrrr�sr�c@seZdZdZdd�ZdS)�GarbageCollectionTestsz-
    Test that, when force GC, it works.
    cCs@t�d�}t|�}t��}|�|�|�|jdddddg�dS)zG
        test gc.collect is called before and after each test.
        r�rBr0r7r�N)r�r�rr
rr;r r�r6rrr�test_collectCalled's

�z)GarbageCollectionTests.test_collectCalledN)r(r)r*r+r�rrrrr�#sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�UnhandledDeferredTestsz\
    Test what happens when we have an unhandled deferred left around after
    a test.
    cCs(ddlm}t��t|�d��|_dS)r.r)�weirdZtest_unhandledDeferredN)�twisted.trial.testr�rA�disablerZTestBleeding�test1)rr�rrrr0:s
�zUnhandledDeferredTests.setUpcCs*t��}|�|�|�t|j�dd�dS)zo
        Forcing garbage collection should cause unhandled Deferreds to be
        reported as errors.
        r2z(Unhandled deferred passed without noticeN)r
rr�r rOr!)rr/rrr�test_isReportedDs

�z&UnhandledDeferredTests.test_isReportedcCs^t��}|�|�|��tr*ttj�}nt��}|�	|dd�|��}|�	t|�dd�dS)z�
        Forcing garbage collection in the test should mean that there are
        no unreachable cycles immediately after the test completes.
        rzunreachable cycle still existedzErrors logged after gc.collectN)
r
rr��flushLoggedErrorsrrOrAZgarbagerBr )rr/�n�xrrr�test_doesntBleedNs
z'UnhandledDeferredTests.test_doesntBleedcCst��t��|��dSr�)rArB�enabler�r$rrrr�aszUnhandledDeferredTests.tearDownN)r(r)r*r+r0r�r�r�rrrrr�4s


r�csPeZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
�ZS)�AddCleanupMixinz1
    Test the addCleanup method of TestCase.
    cs&tt|���t��|_|��|_dSr-)�superr�r0r
rr/�
AddCleanupr7r$�r:rrr0ns
zAddCleanupMixin.setUpcCsD|jj|j_|j�|jjd�|j�|j�|�ddg|jj�dS)zQ
        Callables added with C{addCleanup} are run even if setUp fails.
        �foor0N)	r7ZbrokenSetUpr0�
addCleanupr�r;r/r �logr$rrr�!test_addCleanupCalledIfSetUpFailsvsz1AddCleanupMixin.test_addCleanupCalledIfSetUpFailscCsD|jj|j_|j�|jjd�|j�|j�|�ddg|jj�dS)z�
        Callables added with C{addCleanup} are run even if setUp raises
        L{SkipTest}. This allows test authors to reliably provide clean up
        code using C{addCleanup}.
        r�r0N)	r7Z
skippingSetUpr0r�r�r;r/r r�r$rrr�!test_addCleanupCalledIfSetUpSkipssz1AddCleanupMixin.test_addCleanupCalledIfSetUpSkipscCsP|j�|jjd�|j�|jjd�|j�|j�|�dddddg|jj�dS)z~
        Callables added with C{addCleanup} should be called before C{tearDown}
        in reverse order of addition.
        r��barr0�runTestr�N�r7r�r�r;r/r r�r$rrr�#test_addCleanupCalledInReverseOrder�s�z3AddCleanupMixin.test_addCleanupCalledInReverseOrdercCst|j�|jjd�|j�|j�|�|j���|�dt|jj	��|jj	\\}}|�||j�|�|�
�d�dS)z�
        Errors raised in cleanup functions should be treated like errors in
        C{tearDown}. They should be added as errors and fail the test. Skips,
        todos and failures are all treated as errors.
        r�r2N)r7r��failr;r/rdrr rOr!�getErrorMessage�rr7�errorrrr�test_errorInCleanupIsCaptured�sz-AddCleanupMixin.test_errorInCleanupIsCapturedcCs�|j�|jjd�|j�|jjd�|j�|j�|�ddddg|jj�|�dt|jj	��|jj	\\}}|�||j�|�|�
�d�dS)zq
        If a cleanup raises an error then that does not stop the other
        cleanups from being run.
        r�r�r0r�r�r2N)r7r�r�r�r;r/r r�rOr!r�r�rrr�&test_cleanupsContinueRunningAfterError�s�z6AddCleanupMixin.test_cleanupsContinueRunningAfterErrorcCs�|j�|jjd�|j�|jjd�|j�|j�|�dddg|jj�|�dt|jj��|jj\\}}\}}|�||j�|�||j�|�|�	�d�|�|�	�d�dS)zm
        If more than one cleanup fails, then the test should fail with more
        than one error.
        r�r�r0r�r�rQN)
r7r�r�r;r/r r�rOr!r�)rr�Zerror1Ztest2Zerror2rrr�test_multipleErrorsReported�s�z+AddCleanupMixin.test_multipleErrorsReported)r(r)r*r+r0r�r�r�r�r�r��
__classcell__rrr�rr�js	r�c@seZdZdZed�ZdS)�SynchronousAddCleanupTestsz�
    Test the addCleanup method of TestCase in the synchronous case

    See: L{twisted.trial.test.test_tests.AddCleanupMixin}
    z1twisted.trial.test.skipping.SynchronousAddCleanupN)r(r)r*r+rr�rrrrr��sr�c@s eZdZdZed�Zdd�ZdS)�AsynchronousAddCleanupTestsz�
    Test the addCleanup method of TestCase in the asynchronous case

    See: L{twisted.trial.test.test_tests.AddCleanupMixin}
    z2twisted.trial.test.skipping.AsynchronousAddCleanupcsX�fdd�}�j��jjd��j�|d��j��j���dddddg�jj�dS)	z�
        If an added callable returns a L{Deferred}, then the test should wait
        until that L{Deferred} has fired before running the next cleanup
        method.
        cs&t��}t�d|j|�|��jj�S)Nr)rZDeferredrZ	callLater�callbackZaddCallbackr7r�)rX�dr$rr�cleanup�szMAsynchronousAddCleanupTests.test_addCleanupWaitsForDeferreds.<locals>.cleanupr�r�r0r�r�Nr�)rr�rr$r� test_addCleanupWaitsForDeferreds�s�z<AsynchronousAddCleanupTests.test_addCleanupWaitsForDeferredsN)r(r)r*r+rr�r�rrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)�SuiteClearingMixinzM
    Tests for our extension that allows us to clear out a L{TestSuite}.
    cCsBt��}|�|���|�d|���t|�|�d|���dS)z_
        Calling L{_clearSuite} on a populated L{TestSuite} removes
        all tests.
        r2rN)r	�	TestSuite�addTest�TestCaser r&rrrrr�test_clearSuite�s
z"SuiteClearingMixin.test_clearSuitecCsJtd�}|��}|�|���|�d|���t|�|�d|���dS)z�
        Calling L{_clearSuite} on a populated standard library
        L{TestSuite} removes all tests.

        This test is important since C{_clearSuite} operates by mutating
        internal variables.
        r	r2rN)�
__import__r�r�r�r r&r)rrrrrr�test_clearPyunitSuite�sz(SuiteClearingMixin.test_clearPyunitSuiteN)r(r)r*r+r�r�rrrrr��s
r�c@seZdZdZejZdS)�SynchronousSuiteClearingTestsz�
    Tests for our extension that allows us to clear out a L{TestSuite} in the
    synchronous case.

    See L{twisted.trial.test.test_tests.SuiteClearingMixin}
    N�r(r)r*r+r	r�r�rrrrr�sr�c@seZdZdZejZdS)�AsynchronousSuiteClearingTestsz�
    Tests for our extension that allows us to clear out a L{TestSuite} in the
    asynchronous case.

    See L{twisted.trial.test.test_tests.SuiteClearingMixin}
    N�r(r)r*r+r	r�rrrrr�sr�c@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�TestDecoratorMixinz1
    Tests for our test decoration features.
    cCs^|�|j|jd�t|dd�}t|dd�}|�||�||krJdkrZnn|�||�dS)zB
        Assert that the given decorated tests are equal.
        �Different classZ
_originalTestN)r r:�getattrrC)r�observed�expectedZobservedOriginalZexpectedOriginalrrr�assertTestsEqual#s�z#TestDecoratorMixin.assertTestsEqualcCsr|�|j|jd�|�t|j�t|j�d�t|j|j�D]2\}}t|dd�dk	r`|�||�q:|�||�q:dS)zS
        Assert that the given test suites with decorated tests are equal.
        r�zDifferent number of tests.�_testsN)r r:rOr��zipr��assertSuitesEqualr�)rr�r�ZobservedTestZexpectedTestrrrr�/s���z$TestDecoratorMixin.assertSuitesEqualcCs@|��}t�|�}ddlm}|�}|�|�|�|j|�dS)z�
        For decorated tests, C{run} uses a result adapter that preserves the
        test decoration for calls to C{addError}, C{startTest} and the like.

        See L{reporter._AdaptedReporter}.
        r��LoggingReporterN)r�r	�
TestDecorator� twisted.trial.test.test_reporterr�r;r�r7�rr7�
decoratedTestr�r/rrr�test_usesAdaptedReporterWithRun>s

z2TestDecoratorMixin.test_usesAdaptedReporterWithRuncCs>|��}t�|�}ddlm}|�}||�|�|j|�dS)z�
        For decorated tests, C{__call__} uses a result adapter that preserves
        the test decoration for calls to C{addError}, C{startTest} and the
        like.

        See L{reporter._AdaptedReporter}.
        rr�N)r�r	r�r�r�r�r7r�rrr� test_usesAdaptedReporterWithCallMs
z3TestDecoratorMixin.test_usesAdaptedReporterWithCallcCs,|��}t�|tj�}|�t�|�|�dS)z�
        Calling L{decorate} on a single test case returns the test case
        decorated with the provided decorator.
        N�r�r	�decorater�r�)rr7r�rrr�test_decorateSingleTest]sz*TestDecoratorMixin.test_decorateSingleTestcCs@|��}t�|g�}t�|tj�}|�|t�t�|�g��dS)z�
        Calling L{decorate} on a test suite will return a test suite with
        each test decorated with the provided decorator.
        N�r�r	r�r�r�r��rr7rr�rrr�test_decorateTestSuitefs�z)TestDecoratorMixin.test_decorateTestSuitecCsZ|��}t�|g�}t�|tj�}|�|t�t�|�g��|�|t�t�|�g��dS)zU
        Calling L{decorate} on a test suite will mutate the original suite.
        Nrrrrr�#test_decorateInPlaceMutatesOriginalqs���z6TestDecoratorMixin.test_decorateInPlaceMutatesOriginalcCs`ttdd�}|dkrt�d��|��}t�|g�}||�}t�|tj�||�}|�||�dS)ac
        When decorating a test suite in-place, the number of references to the
        test objects in that test suite should stay the same.

        Previously, L{unittest.decorate} recreated a test suite, so the
        original suite kept references to the test objects. This test is here
        to ensure the problem doesn't reappear again.
        �getrefcountNz*getrefcount not supported on this platform)	r��sysr	ZSkipTestr�r�r�r�r )rrr7rZcount1Zcount2rrr� test_decorateTestSuiteReferences~s	�z3TestDecoratorMixin.test_decorateTestSuiteReferencescCsT|��}t�t�|g�g�}t�|tj�}t�t�t�|�g�g�}|�||�dS)z�
        Calling L{decorate} on a test suite with nested suites will return a
        test suite that maintains the same structure, but with all tests
        decorated.
        Nr)rr7rr�r�rrr�test_decorateNestedTestSuite�s�z/TestDecoratorMixin.test_decorateNestedTestSuitecCs:|��}t�|tj�}t�|tj�}|�|t�|��dS)z�
        Calling L{decorate} on a test suite with already-decorated tests
        decorates all of the tests in the suite again.
        Nr�)rr7r�ZredecoratedTestrrr�test_decorateDecoratedSuite�s��z.TestDecoratorMixin.test_decorateDecoratedSuitecCs@|��}t�|g�}t�|tj�}|�|t�t�|�g��dS)z�
        Tests can be in non-standard suites. L{decorate} preserves the
        non-standard suites when it decorates the tests.
        N)r�rZDestructiveTestSuiter	r�r�r�)rr7rZ	decoratedrrr�test_decoratePreservesSuite�s�z.TestDecoratorMixin.test_decoratePreservesSuiteN)r(r)r*r+r�r�r�r�r�rrrrrr	rrrrr�s	

r�c@seZdZdZejZdS)�SynchronousTestDecoratorTestsz�
    Tests for our test decoration features in the synchronous case.

    See L{twisted.trial.test.test_tests.TestDecoratorMixin}
    Nr�rrrrr
�sr
c@seZdZdZejZdS)�AsynchronousTestDecoratorTestsz�
    Tests for our test decoration features in the asynchronous case.

    See L{twisted.trial.test.test_tests.TestDecoratorMixin}
    Nr�rrrrr�src@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�MonkeyPatchMixinzF
    Tests for the patch() helper method in L{unittest.TestCase}.
    cCs"d|_d|_|j|_|��|_dS)r.ZoriginalZpatchedN)�
originalValue�patchedValue�
objectToPatchr�r7r$rrrr0�szMonkeyPatchMixin.setUpcCs&|j�|d|j�|�|j|j�dS)zi
        Calling C{patch()} on a test monkey patches the specified object and
        attribute.
        rN)r7�patchrr rr$rrr�
test_patch�szMonkeyPatchMixin.test_patchcCs6|j�|d|j�|j�t���|�|j|j�dS)zw
        Any monkey patches introduced by a test using C{patch()} are reverted
        after the test has run.
        rN)	r7rrr;r
r�r rr
r$rrr�test_patchRestoredAfterRun�sz+MonkeyPatchMixin.test_patchRestoredAfterRuncCs.|j�|d|j�}|��|�|j|j�dS)z�
        C{patch()} return a L{monkey.MonkeyPatcher} object that can be used to
        restore the original values before the end of the test.
        rN)r7rr�restorer rr
�rrrrr�test_revertDuringTest�sz&MonkeyPatchMixin.test_revertDuringTestcCs6|j�|d|j�}|��|��|�|j|j�dS)zq
        The returned L{monkey.MonkeyPatcher} object can re-apply the patch
        during the test run.
        rN)r7rrrr rrrrr�test_revertAndRepatch�sz&MonkeyPatchMixin.test_revertAndRepatchcCsd|j�|d|j�|�|j|j�|j�|dd�|�|jd�|j�t���|�|j|j�dS)zW
        Successive patches are applied and reverted just like a single patch.
        rzsecond valueN)	r7rrr rr;r
r�r
r$rrr�test_successivePatches�sz'MonkeyPatchMixin.test_successivePatchesN)
r(r)r*r+r0rrrrrrrrrr�s			
rc@seZdZdZejZdS)�SynchronousMonkeyPatchTestsz�
    Tests for the patch() helper method in the synchronous case.

    See L{twisted.trial.test.test_tests.MonkeyPatchMixin}
    Nr�rrrrrsrc@seZdZdZejZdS)�AsynchronousMonkeyPatchTestsz�
    Tests for the patch() helper method in the asynchronous case.

    See L{twisted.trial.test.test_tests.MonkeyPatchMixin}
    Nr�rrrrrsrc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�IterateTestsMixinz]
    L{_iterateTests} returns a list of all test cases in a test suite or test
    case.
    cCs"|��}|�|gtt|���dS)zj
        L{_iterateTests} on a single test case returns a list containing that
        test case.
        N)r�r r�rr<rrr�test_iterateTestCasesz&IterateTestsMixin.test_iterateTestCasecCs.|��}t�|g�}|�|gtt|���dS)z�
        L{_iterateTests} on a test suite that contains a single test case
        returns a list containing that test case.
        N�r�rr�r r�r�rr7rrrr�test_iterateSingletonTestSuite'sz0IterateTestsMixin.test_iterateSingletonTestSuitecCs6|��}t�t�|g�g�}|�|gtt|���dS)zP
        L{_iterateTests} returns tests that are in nested test suites.
        Nrrrrr�test_iterateNestedTestSuite1sz-IterateTestsMixin.test_iterateNestedTestSuitecCs:|��}t�t�|g�|g�}|�||gtt|���dS)zU
        L{_iterateTests} returns tests in left-to-right, depth-first order.
        Nrrrrr�#test_iterateIsLeftToRightDepthFirst:sz5IterateTestsMixin.test_iterateIsLeftToRightDepthFirstN)r(r)r*r+rrrr rrrrrs
	
	rc@seZdZdZejZdS)�SynchronousIterateTestsTestsz�
    Check that L{_iterateTests} returns a list of all test cases in a test suite
    or test case for synchronous tests.

    See L{twisted.trial.test.test_tests.IterateTestsMixin}
    Nr�rrrrr!Csr!c@seZdZdZejZdS)�AsynchronousIterateTestsTestsz�
    Check that L{_iterateTests} returns a list of all test cases in a test suite
    or test case for asynchronous tests.

    See L{twisted.trial.test.test_tests.IterateTestsMixin}
    Nr�rrrrr"Msr"c@s eZdZdZdd�Zdd�ZdS)�TrialGeneratorFunctionTestsz=
    Tests for generator function methods in test cases.
    cCs�Gdd�dtj�}|d�}t��}|�|�|�t|j�d�|�t|j�d�|�	d|jddj
jd�|�	d|jddj
jd�|�	d|jddj
jd�d	S)
z�
        In a TestCase, a test method which is a generator function is reported
        as an error, as such a method will never run assertions.
        c@seZdZdZdd�ZdS)zTTrialGeneratorFunctionTests.test_errorOnGeneratorFunction.<locals>.GeneratorTestCasez?
            A fake TestCase for testing purposes.
            css|�d�dVdS�zt
                A method which is also a generator function, for testing
                purposes.
                zthis should never be reachedN�r�r$rrr�test_generatorhs
zcTrialGeneratorFunctionTests.test_errorOnGeneratorFunction.<locals>.GeneratorTestCase.test_generatorN�r(r)r*r+r&rrrr�GeneratorTestCasecsr(r&rr2z GeneratorTestCase.test_generatorz+GeneratorTestCase testMethod=test_generator�4is a generator function and therefore will never runN)r	r�r
rr;r rOr"r!�assertInr��args)rr(�testCaser/rrr�test_errorOnGeneratorFunction]s

���z9TrialGeneratorFunctionTests.test_errorOnGeneratorFunctioncCs�Gdd�dtj�}|d�}t��}|�|�|�t|j�d�|�t|j�d�|�	d|jddj
jd�|�	d|jddj
jd�|�	d|jddj
jd�d	S)
z�
        In a SynchronousTestCase, a test method which is a generator function
        is reported as an error, as such a method will never run assertions.
        c@seZdZdZdd�ZdS)zrTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction.<locals>.GeneratorSynchronousTestCasezJ
            A fake SynchronousTestCase for testing purposes.
            css|�d�dVdSr$r%r$rrrr&�s
z�TrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction.<locals>.GeneratorSynchronousTestCase.test_generatorNr'rrrr�GeneratorSynchronousTestCase�sr.r&rr2z+GeneratorSynchronousTestCase.test_generatorz6GeneratorSynchronousTestCase testMethod=test_generatorr)N)r	r�r
rr;r rOr"r!r*r�r+)rr.r,r/rrr�0test_synchronousTestCaseErrorOnGeneratorFunction|s

���zLTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunctionN)r(r)r*r+r-r/rrrrr#Xsr#)Lr+Z
__future__rrrArr?r	rZtwisted.python.compatrrZtwisted.python.reflectrZtwisted.internetrrZ
twisted.trialr
rrr�r
Z#twisted.trial.test.test_suppressionrZtwisted.trial._asyncrunnerrrr�objectrr,r�rEr�rHrIr]r_r`rkrmrnr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rrrrrr!r"r#rrrr�<module>sp:I

3Z

9

7-656[
#

		=		*