o
    ¯b\Á  ã                   @   sÀ  d Z ddlZddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZ G dd„ dƒZG dd„ dƒZG dd„ deejƒZG dd„ deejƒZ G dd„ deƒZ!G dd„ de!ejƒZ"G dd„ de!ejƒZ#G dd„ deƒZ$G dd„ de$ejƒZ%G dd„ de$ejƒZ&G dd „ d eƒZ'G d!d"„ d"e'ejƒZ(G d#d$„ d$e'ejƒZ)G d%d&„ d&eƒZ*G d'd(„ d(e*ejƒZ+G d)d*„ d*e*ejƒZ,G d+d,„ d,eƒZ-G d-d.„ d.e-ejƒZ.G d/d0„ d0e-ejƒZ/G d1d2„ d2ejƒZ0G d3d4„ d4ƒZ1G d5d6„ d6e1ejƒZ2G d7d8„ d8e1ejƒZ3G d9d:„ d:eejƒZ4G d;d<„ d<ƒZ5G d=d>„ d>e5ejƒZ6G d?d@„ d@e5ejƒZ7G dAdB„ dBejƒZ8G dCdD„ dDƒZ9G dEdF„ dFe9ejƒZ:G dGdH„ dHe9ejƒZ;G dIdJ„ dJƒZ<G dKdL„ dLe<ejƒZ=G dMdN„ dNe<ejƒZ>G dOdP„ dPƒZ?G dQdR„ dRe?ejƒZ@G dSdT„ dTe?ejƒZAG dUdV„ dVƒZBG dWdX„ dXeBejƒZCG dYdZ„ dZeBejƒZDG d[d\„ d\ƒZEG d]d^„ d^eEejƒZFG d_d`„ d`eEejƒZGG dadb„ dbejƒZHdS )ca•  
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.
é    N)ÚStringIO)ÚdeferÚreactor)Ú_PYPY)ÚnamedAny)ÚreporterÚrunnerÚunittestÚutil)Ú_clearSuiteÚ _ForceGarbageCollectionDecoratorÚ_iterateTests)Ú	erroneous)ÚSuppressionMixinc                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚResultsTestMixinzG
    Provide useful APIs for test cases that are about test cases.
    c                 C   s&   t  ¡ | _| j |¡| _t ¡ | _dS )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Ú	loadSuite1   s   
zResultsTestMixin.loadSuitec                 C   sD   |   | j ¡ ¡ |  | jjg ¡ |  | jjg ¡ |  | jjg ¡ dS )z 
        test the setup
        N)Ú
assertTruer   ÚwasSuccessfulÚassertEqualÚerrorsÚfailuresÚskips©r   r   r   r   Ú
test_setUp:   s   zResultsTestMixin.test_setUpc                 C   s2   |   | j ¡ |¡ |  | j¡ |   | jj|¡ dS )z:
        Asserts that the test count is plausible
        N)r   r   ÚcountTestCasesr   ÚtestsRun)r   ÚnumTestsr   r   r   ÚassertCountC   s   zResultsTestMixin.assertCountN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r(   r   r   r   r   r   ,   s
    		r   c                   @   ó@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚSuccessMixinz\
    Tests for the reporting of successful tests in L{twisted.trial.unittest.TestCase}.
    c                 C   s   t  ¡ | _dS ©ú%
        Setup our test case
        N)r   r   Úresultr#   r   r   r   ÚsetUpQ   ó   zSuccessMixin.setUpc                 C   s   dS )z9
        A successful test, used by other tests.
        Nr   r#   r   r   r   Útest_successfulW   s    zSuccessMixin.test_successfulc                 C   sX   |   |jd¡ |   |jg ¡ |   |jg ¡ |   |jg ¡ |   |jg ¡ |   |jg ¡ dS )zd
        Utility function -- assert there is one success and the state is
        plausible
        é   N)r   Ú	successesr!   r    ÚexpectedFailuresÚunexpectedSuccessesr"   ©r   Útestr1   r   r   r   ÚassertSuccessful\   s   zSuccessMixin.assertSuccessfulc                 C   s(   |   d¡}| | j¡ |  || j¡ dS )z„
        Test that when a successful test is run, it is reported as a success,
        and not as any other kind of result.
        r4   N©Ú	__class__Úrunr1   r;   ©r   r:   r   r   r   Útest_successfulIsReportedh   s   
z&SuccessMixin.test_successfulIsReportedc                 C   s&   |   ¡ }| | j¡ |  || j¡ dS )zz
        The test case type can be instantiated with no arguments, run, and
        reported as being successful.
        Nr<   r?   r   r   r   Útest_defaultIsSuccessfulq   s   z%SuccessMixin.test_defaultIsSuccessfulc                 C   sJ   |   d¡}t |¡}| | j¡ |  || j¡ ~t ¡  |  |ƒ d¡ dS )zF
        Test that no reference is kept on a successful test.
        r4   N)	r=   ÚweakrefÚrefr>   r1   r;   ÚgcÚcollectÚassertIdentical)r   r:   rC   r   r   r   Útest_noReferencez   s   

zSuccessMixin.test_noReferenceN)
r)   r*   r+   r,   r2   r4   r;   r@   rA   rG   r   r   r   r   r.   L   s    		r.   c                   @   ó   e Zd ZdZdS )ÚSynchronousSuccessTestsúN
    Tests for the reporting of successful tests in the synchronous case.
    N©r)   r*   r+   r,   r   r   r   r   rI   ‡   ó    rI   c                   @   rH   )ÚAsynchronousSuccessTestsrJ   NrK   r   r   r   r   rM      rL   rM   c                   @   r-   )ÚSkipMethodsMixinzZ
    Tests for the reporting of skipping tests in L{twisted.trial.unittest.TestCase}.
    c                 C   ó   |   | j¡ dS r/   )r   ÚSkippingr#   r   r   r   r2   ˜   ó   zSkipMethodsMixin.setUpc                 C   ó   |   d¡ dS )z4
        Assert that there are three tests.
        é   N©r(   r#   r   r   r   Útest_countingž   r3   zSkipMethodsMixin.test_countingc                 C   ód   |   | j¡ |  | j ¡ ¡ |  | jjg ¡ |  | jjg ¡ |  t| jjƒd¡ |  | jj	d¡ dS )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.
        rS   r   N©
r   r   r   r   r   r    r!   Úlenr"   r6   r#   r   r   r   Útest_results¤   ó   zSkipMethodsMixin.test_resultsc                 C   sp   |   | j¡ |  | j¡ |  | j ¡ ¡ |  | jjg ¡ |  | jjg ¡ |  t	| jj
ƒd¡ |  | jjd¡ dS )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.
        é   r   N)r   ÚSkippingSetUpr   r   r   r   r   r    r!   rX   r"   r6   r#   r   r   r   r$   ²   s   zSkipMethodsMixin.test_setUpc                 C   sF   |   | j¡ d}| jjD ]\}}|  | ¡ t|ƒd… t|ƒ¡ qdS )z(
        Test that reasons work
        Útest_N)r   r   r"   r   ÚshortDescriptionrX   Ústr)r   Úprefixr:   Úreasonr   r   r   Útest_reasonsÁ   s
   "ÿzSkipMethodsMixin.test_reasonsc                 C   sd   |   | j¡ |  | j¡ |  | jjg¡}|  dt|ƒ¡ |  t|d d ¡ |  d|d d ¡ dS )zo
        If a test method raises L{SkipTest} with no reason, a deprecation
        warning is emitted.
        r5   r   ÚcategoryzSDo not raise unittest.SkipTest with no arguments! Give a reason for skipping tests!ÚmessageN)	r   ÚDeprecatedReasonlessSkipr   r   ÚflushWarningsÚtest_1r   rX   ÚDeprecationWarning)r   Úwarningsr   r   r   Ú test_deprecatedSkipWithoutReasonË   s   
ýz1SkipMethodsMixin.test_deprecatedSkipWithoutReasonN)
r)   r*   r+   r,   r2   rU   rY   r$   rb   rj   r   r   r   r   rN   “   s    
rN   c                   @   ó(   e Zd ZdZedƒZedƒZedƒZdS )Ú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,   r   rP   r\   re   r   r   r   r   rl   Ü   ó    ÿrl   c                   @   rk   )Ú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.AsynchronousDeprecatedReasonlessSkipNrm   r   r   r   r   ro   ê   rn   ro   c                   @   ó8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚSkipClassesMixinzQ
    Test the class skipping features of L{twisted.trial.unittest.TestCase}.
    c                 C   s   |   | j¡ d| j_dS )r0   FN)r   ÚSkippedClassÚ	_setUpRanr#   r   r   r   r2   ý   s   zSkipClassesMixin.setUpc                 C   rR   )zP
        Skipped test methods still contribute to the total test count.
        é   NrT   r#   r   r   r   rU     r3   zSkipClassesMixin.test_countingc                 C   s   |   | j¡ |  | jj¡ dS )zP
        The C{setUp} method is not called if the class is set to skip.
        N)r   r   ÚassertFalserr   rs   r#   r   r   r   Útest_setUpRan
  s   zSkipClassesMixin.test_setUpRanc                 C   rV   )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.
        rt   r   NrW   r#   r   r   r   rY     rZ   zSkipClassesMixin.test_resultsc                 C   ó6   |   | j¡ g d¢}dd„ | jjD ƒ}|  ||¡ dS )z…
        Test methods which raise L{unittest.SkipTest} or have their C{skip}
        attribute set to something are skipped.
        )ÚclassÚskip2rx   rx   c                 S   s   g | ]\}}|‘qS r   r   )Ú.0r:   ra   r   r   r   Ú
<listcomp>'  s    z1SkipClassesMixin.test_reasons.<locals>.<listcomp>N)r   r   r"   r   ©r   ÚexpectedReasonsÚreasonsGivenr   r   r   rb     s   zSkipClassesMixin.test_reasonsN)	r)   r*   r+   r,   r2   rU   rv   rY   rb   r   r   r   r   rq   ø   s    rq   c                   @   ó   e Zd ZdZedƒZdS )Ú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,   r   rr   r   r   r   r   r€   +  ó    r€   c                   @   r   )ÚAsynchronousSkipClassTestsz€
    Test the class skipping features in the asynchronous case.

    See: L{twisted.trial.test.test_tests.SkipClassesMixin}
    z4twisted.trial.test.skipping.AsynchronousSkippedClassNr   r   r   r   r   rƒ   5  r‚   rƒ   c                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )Ú	TodoMixinzv
    Tests for the individual test method I{expected failure} features of
    L{twisted.trial.unittest.TestCase}.
    c                 C   rO   r/   )r   ÚTodor#   r   r   r   r2   E  rQ   zTodoMixin.setUpc                 C   rR   )z9
        Ensure that we've got three test cases.
        rS   NrT   r#   r   r   r   rU   K  r3   zTodoMixin.test_countingc                 C   sˆ   |   | j¡ |  | j ¡ ¡ |  | jjg ¡ |  | jjg ¡ |  | jjg ¡ |  t| jj	ƒd¡ |  t| jj
ƒd¡ |  | jjd¡ dS )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.
        r[   r5   r   N©r   r   r   r   r   r    r!   r"   rX   r7   r8   r6   r#   r   r   r   rY   Q  ó   	zTodoMixin.test_resultsc                 C   ó6   |   | j¡ ddg}dd„ | jjD ƒ}|  ||¡ dS )úE
        Ensure that expected failures are handled properly.
        Útodo1Útodo2c                 S   ó   g | ]\}}}|j ‘qS r   ©ra   ©rz   ÚtÚeÚrr   r   r   r{   i  ó    z3TodoMixin.test_expectedFailures.<locals>.<listcomp>N©r   r   r7   r   r|   r   r   r   Útest_expectedFailuresc  ó   zTodoMixin.test_expectedFailuresc                 C   s4   |   | j¡ dg}dd„ | jjD ƒ}|  ||¡ dS )ú>
        Ensure that unexpected successes are caught.
        Útodo3c                 S   ó   g | ]\}}|j ‘qS r   r   ©rz   r   r‘   r   r   r   r{   r  ó    z6TodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>N©r   r   r8   r   r|   r   r   r   Útest_unexpectedSuccessesl  s   z"TodoMixin.test_unexpectedSuccessesc                 C   s˜   |   | j¡ |  | j¡ |  | j ¡ ¡ |  t| jjƒd¡ |  | jj	g ¡ |  | jj
g ¡ |  t| jjƒd¡ |  t| jjƒd¡ |  | jjd¡ dS )z|
        C{setUp} is excluded from the failure expectation defined by a C{todo}
        attribute on a test method.
        r5   r   N)r   Ú	SetUpTodor   r   ru   r   r   rX   r    r!   r"   r7   r8   r6   r#   r   r   r   Útest_expectedSetUpFailureu  s   z#TodoMixin.test_expectedSetUpFailurec                 C   s˜   |   | j¡ |  | j¡ |  | j ¡ ¡ |  t| jjƒd¡ |  | jj	g ¡ |  | jj
g ¡ |  t| jjƒd¡ |  t| jjƒd¡ |  | jjd¡ dS )z
        C{tearDown} is excluded from the failure expectation defined by a C{todo}
        attribute on a test method.
        r5   r   N)r   ÚTearDownTodor   r   ru   r   r   rX   r    r!   r"   r7   r8   r6   r#   r   r   r   Útest_expectedTearDownFailure„  s   z&TodoMixin.test_expectedTearDownFailureN)r)   r*   r+   r,   r2   rU   rY   r”   rœ   rž   r    r   r   r   r   r„   ?  s    		r„   c                   @   rk   )Ú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,   r   r…   r   rŸ   r   r   r   r   r¡   —  ó
    r¡   c                   @   rk   )Ú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¢   r   r   r   r   r¤   £  r£   r¤   c                   @   rp   )ÚClassTodoMixinzj
    Tests for the class-wide I{expected failure} features of
    L{twisted.trial.unittest.TestCase}.
    c                 C   rO   r/   )r   Ú	TodoClassr#   r   r   r   r2   µ  rQ   zClassTodoMixin.setUpc                 C   rR   )z8
        Ensure that we've got four test cases.
        rt   NrT   r#   r   r   r   rU   »  r3   zClassTodoMixin.test_countingc                 C   sˆ   |   | j¡ |  | j ¡ ¡ |  | jjg ¡ |  | jjg ¡ |  | jjg ¡ |  t| jj	ƒd¡ |  t| jj
ƒd¡ |  | jjd¡ dS )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.
        r[   r   Nr†   r#   r   r   r   rY   Á  r‡   zClassTodoMixin.test_resultsc                 C   rˆ   )r‰   Úmethodrx   c                 S   rŒ   r   r   rŽ   r   r   r   r{   Ù  r’   z8ClassTodoMixin.test_expectedFailures.<locals>.<listcomp>Nr“   r|   r   r   r   r”   Ó  r•   z$ClassTodoMixin.test_expectedFailuresc                 C   rˆ   )r–   r§   rx   c                 S   r˜   r   r   r™   r   r   r   r{   â  rš   z;ClassTodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>Nr›   r|   r   r   r   rœ   Ü  r•   z'ClassTodoMixin.test_unexpectedSuccessesN©	r)   r*   r+   r,   r2   rU   rY   r”   rœ   r   r   r   r   r¥   ¯  s    	r¥   c                   @   r   )Ú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,   r   r¦   r   r   r   r   r©   æ  r‚   r©   c                   @   r   )Ú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ª   r   r   r   r   r«   ð  r‚   r«   c                   @   rp   )ÚStrictTodoMixinz
    Tests for the I{expected failure} features of
    L{twisted.trial.unittest.TestCase} in which the exact failure which is
    expected is indicated.
    c                 C   rO   r/   )r   Ú
StrictTodor#   r   r   r   r2     rQ   zStrictTodoMixin.setUpc                 C   rR   )z3
        Assert there are seven test cases
        é   NrT   r#   r   r   r   rU     r3   zStrictTodoMixin.test_countingc                 C   s   |   | j¡ |  | j ¡ ¡ |  t| jjƒd¡ |  t| jjƒd¡ |  t| jjƒd¡ |  t| jj	ƒd¡ |  | jj
d¡ |  | jjg ¡ dS )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.
        r[   r5   rS   r   N)r   r   ru   r   r   rX   r    r!   r7   r8   r6   r"   r#   r   r   r   rY     s   zStrictTodoMixin.test_resultsc                 C   rw   )r‰   )rŠ   r‹   Útodo5c                 S   rŒ   r   r   rŽ   r   r   r   r{   "  r’   z9StrictTodoMixin.test_expectedFailures.<locals>.<listcomp>Nr“   ©r   r}   ÚreasonsGottenr   r   r   r”     r•   z%StrictTodoMixin.test_expectedFailuresc                 C   s:   |   | j¡ tgdfg}dd„ | jjD ƒ}|  ||¡ dS )r–   Útodo7c                 S   s   g | ]
\}}|j |jf‘qS r   )r    ra   r™   r   r   r   r{   +  s    ÿz<StrictTodoMixin.test_unexpectedSuccesses.<locals>.<listcomp>N)r   r   ÚRuntimeErrorr8   r   r°   r   r   r   rœ   %  s   ÿz(StrictTodoMixin.test_unexpectedSuccessesNr¨   r   r   r   r   r¬   ú  s    	r¬   c                   @   r   )Ú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,   r   r­   r   r   r   r   r´   1  ó    r´   c                   @   r   )Ú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µ   r   r   r   r   r·   <  r¶   r·   c                   @   r   )	ÚReactorCleanupTestszc
    Tests for cleanup and reporting of reactor event sources left behind by test
    methods.
    c                 C   s   t  tƒ ¡| _t ¡ | _dS r/   )r   ÚReporterr   r1   r   r   r   r#   r   r   r   r2   M  s   zReactorCleanupTests.setUpc                 C   s^   | j  d¡}| | j¡ |  | j ¡ ¡ |  | jjd¡ | jjd d }|  	| 
tj¡¡ dS )zm
        Trial reports a L{util.DirtyReactorAggregateError} if a test leaves
        sockets behind.
        z@twisted.trial.test.erroneous.SocketOpenTest.test_socketsLeftOpenr5   r   N)r   Ú
loadByNamer>   r1   ru   r   r   r6   r    r   Úcheckr
   ÚDirtyReactorAggregateError©r   r   Úfailurer   r   r   Útest_leftoverSocketsT  s   ÿz(ReactorCleanupTests.test_leftoverSocketsc                 C   s\   t  d¡}| | j¡ |  | j ¡ ¡ | jjd d }|  | jjd¡ |  	| 
tj¡¡ dS )zŠ
        Trial reports a L{util.DirtyReactorAggregateError} and fails the test
        if a test leaves a L{DelayedCall} hanging.
        Útest_leftoverPendingCallsr   r5   N)r   r¸   r>   r1   ru   r   r    r   r6   r   r»   r
   r¼   r½   r   r   r   rÀ   e  s   
z-ReactorCleanupTests.test_leftoverPendingCallsN)r)   r*   r+   r,   r2   r¿   rÀ   r   r   r   r   r¸   G  s
    r¸   c                   @   ó0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚFixtureMixinzB
    Tests for fixture helper methods (e.g. setUp, tearDown).
    c                 C   s   t  ¡ | _ t ¡ | _dS r/   )r   r¹   r   r   r   r#   r   r   r   r2   w  s   
zFixtureMixin.setUpc                 C   s`   | j  | j¡}| | j¡ |  t| jjƒdk¡ |  | jjd d j	t
j¡ |  d| jj¡ dS )zO
        When setUp fails, the error is recorded in the result object.
        r   r5   N)r   r   ÚTestFailureInSetUpr>   r   r   rX   r    ÚassertIsInstanceÚvaluer   ÚFoolishErrorr   r6   r   r   r   r   Útest_brokenSetUp~  s
   zFixtureMixin.test_brokenSetUpc                 C   s`   | j  | j¡}| | j¡ | jj}|  t|ƒdk¡ |  |d d j	t
j¡ |  d| jj¡ dS )zR
        When tearDown fails, the error is recorded in the result object.
        r   r5   N)r   r   ÚTestFailureInTearDownr>   r   r    r   rX   rÄ   rÅ   r   rÆ   r   r6   )r   r   r    r   r   r   Útest_brokenTearDownˆ  s   z FixtureMixin.test_brokenTearDownc                 C   s„   | j  | j¡}t|ƒd }|  |j¡ | | j¡ | jj}|  	t
|ƒdk¡ |  |d d jtj¡ |  d| jj¡ |  	|j¡ dS )zP
        L{SynchronousTestCase.tearDown} runs when a test method fails.
        r   r5   N)r   r   ÚTestFailureButTearDownRunsÚlistru   ÚtornDownr>   r   r    r   rX   rÄ   rÅ   r   rÆ   r   r6   )r   r   Úcaser    r   r   r   Útest_tearDownRunsOnTestFailure“  s   z+FixtureMixin.test_tearDownRunsOnTestFailureN)r)   r*   r+   r,   r2   rÇ   rÉ   rÎ   r   r   r   r   rÂ   r  s    
rÂ   c                   @   rk   )Ú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,   r   rÃ   rÈ   rÊ   r   r   r   r   rÏ   ¥  ó    ÿÿÿrÏ   c                   @   rk   )Ú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Ð   r   r   r   r   rÒ   ·  rÑ   rÒ   c                   @   s0   e Zd ZdZedƒZedƒZedƒZedƒZdS )Ú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,   r   ÚTestSetUpSuppressionÚTestTearDownSuppressionÚTestSuppressionÚTestSuppression2r   r   r   r   rÓ   É  s    ÿÿÿÿrÓ   c                   @   sB   e Zd ZdZG dd„ dejƒZdd„ Zdd„ Zdd	„ 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                   @   r   )	zGCMixin.BasicTestz#
        Mock test to run.
        c                 C   rR   )z$
            Mock setUp
            r2   N©Ú_logr#   r   r   r   r2   ê  r3   zGCMixin.BasicTest.setUpc                 C   rR   )z(
            Mock test case
            r:   NrÙ   r#   r   r   r   Útest_fooð  r3   zGCMixin.BasicTest.test_fooc                 C   rR   )z,
            Mock tear tearDown
            ÚtearDownNrÙ   r#   r   r   r   rÜ   ö  r3   zGCMixin.BasicTest.tearDownN)r)   r*   r+   r,   r2   rÛ   rÜ   r   r   r   r   Ú	BasicTestå  s
    rÝ   c                 C   s   | j  |¡ dS )z
        Log function
        N)Ú_collectCalledÚappend)r   Úmsgr   r   r   rÚ   ü  rQ   zGCMixin._logc                 C   rR   )zFake gc.collectrE   NrÙ   r#   r   r   r   rE     s   zGCMixin.collectc                 C   s$   g | _ | j| j_tj| _| jt_dS r/   )rÞ   rÚ   rÝ   rD   rE   Ú_oldCollectr#   r   r   r   r2     s   
zGCMixin.setUpc                 C   s   | j t_dS ©z$
        Tear down the test
        N)rá   rD   rE   r#   r   r   r   rÜ     s   zGCMixin.tearDownN)r)   r*   r+   r,   r	   ÚSynchronousTestCaserÝ   rÚ   rE   r2   rÜ   r   r   r   r   rØ   ß  s    	rØ   c                   @   ó   e Zd ZdZdd„ ZdS )ÚGarbageCollectionDefaultTestsz@
    By default, tests should not force garbage collection.
    c                 C   s2   |   d¡}t ¡ }| |¡ |  | jg d¢¡ dS )zH
        By default, tests should not force garbage collection.
        rÛ   )r2   r:   rÜ   N)rÝ   r   r   r>   r   rÞ   r9   r   r   r   Útest_collectNotDefault  s   

z4GarbageCollectionDefaultTests.test_collectNotDefaultN)r)   r*   r+   r,   ræ   r   r   r   r   rå     ó    rå   c                   @   rä   )ÚGarbageCollectionTestsz-
    Test that, when force GC, it works.
    c                 C   s:   t  d¡}t|ƒ}t ¡ }| |¡ |  | jg d¢¡ dS )zG
        test gc.collect is called before and after each test.
        rÛ   )rE   r2   r:   rÜ   rE   N)rè   rÝ   r   r   r   r>   r   rÞ   r9   r   r   r   Útest_collectCalled*  s   


ÿz)GarbageCollectionTests.test_collectCalledN)r)   r*   r+   r,   ré   r   r   r   r   rè   %  rç   rè   c                   @   s<   e Zd ZdZdd„ Zdd„ Ze ed¡dd„ ƒZ	d	d
„ Z
dS )ÚUnhandledDeferredTestsz\
    Test what happens when we have an unhandled deferred left around after
    a test.
    c                 C   s(   ddl m} t ¡  t| d¡ƒ| _dS )r0   r   )ÚweirdÚtest_unhandledDeferredN)Útwisted.trial.testrë   rD   Údisabler   ÚTestBleedingÚtest1)r   rë   r   r   r   r2   =  s
   
ÿzUnhandledDeferredTests.setUpc                 C   s*   t  ¡ }|  |¡ |  t|jƒdd¡ dS )zo
        Forcing garbage collection should cause unhandled Deferreds to be
        reported as errors.
        r5   z(Unhandled deferred passed without noticeN)r   r   rð   r   rX   r    )r   r1   r   r   r   Útest_isReportedI  s
   
ÿz&UnhandledDeferredTests.test_isReportedzGC works differently on PyPy.c                 C   sP   t  ¡ }|  |¡ |  ¡  ttjƒ}|  |dd¡ |  ¡ }|  t|ƒdd¡ dS )z—
        Forcing garbage collection in the test should mean that there are
        no unreachable cycles immediately after the test completes.
        r   zunreachable cycle still existedzErrors logged after gc.collectN)r   r   rð   ÚflushLoggedErrorsrX   rD   Úgarbager   )r   r1   ÚnÚxr   r   r   Útest_doesntBleedT  s   

z'UnhandledDeferredTests.test_doesntBleedc                 C   s   t  ¡  t  ¡  |  ¡  dS râ   )rD   rE   Úenablerò   r#   r   r   r   rÜ   e  s   zUnhandledDeferredTests.tearDownN)r)   r*   r+   r,   r2   rñ   r   ÚskipIfr   rö   rÜ   r   r   r   r   rê   7  s    

rê   c                       sP   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
‡  ZS )ÚAddCleanupMixinz1
    Test the addCleanup method of TestCase.
    c                    s"   t ƒ  ¡  t ¡ | _|  ¡ | _dS r/   )Úsuperr2   r   r   r1   Ú
AddCleanupr:   r#   ©r=   r   r   r2   s  s   

zAddCleanupMixin.setUpc                 C   óD   | j j| j _| j  | j jd¡ | j  | j¡ |  ddg| j j¡ dS )zQ
        Callables added with C{addCleanup} are run even if setUp fails.
        Úfoor2   N)	r:   ÚbrokenSetUpr2   Ú
addCleanuprß   r>   r1   r   Úlogr#   r   r   r   Ú!test_addCleanupCalledIfSetUpFails{  s   z1AddCleanupMixin.test_addCleanupCalledIfSetUpFailsc                 C   rý   )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þ   r2   N)	r:   ÚskippingSetUpr2   r   rß   r>   r1   r   r  r#   r   r   r   Ú!test_addCleanupCalledIfSetUpSkips„  s   z1AddCleanupMixin.test_addCleanupCalledIfSetUpSkipsc                 C   sJ   | j  | j jd¡ | j  | j jd¡ | j  | j¡ |  g d¢| j j¡ dS )z~
        Callables added with C{addCleanup} should be called before C{tearDown}
        in reverse order of addition.
        rþ   Úbar©r2   ÚrunTestr  rþ   rÜ   N©r:   r   rß   r>   r1   r   r  r#   r   r   r   Ú#test_addCleanupCalledInReverseOrder  s   z3AddCleanupMixin.test_addCleanupCalledInReverseOrderc                 C   st   | j  | j jd¡ | j  | j¡ |  | j ¡ ¡ |  dt| jj	ƒ¡ | jj	\\}}|  || j ¡ |  | 
¡ d¡ dS )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þ   r5   N)r:   r   Úfailr>   r1   ru   r   r   rX   r    ÚgetErrorMessage©r   r:   Úerrorr   r   r   Útest_errorInCleanupIsCaptured™  s   z-AddCleanupMixin.test_errorInCleanupIsCapturedc                 C   sŠ   | j  | j jd¡ | j  | j jd¡ | j  | j¡ |  g d¢| j j¡ |  dt| jj	ƒ¡ | jj	\\}}|  || j ¡ |  | 
¡ d¡ dS )zq
        If a cleanup raises an error then that does not stop the other
        cleanups from being run.
        rþ   r  )r2   r  rþ   rÜ   r5   N)r:   r   rß   r
  r>   r1   r   r  rX   r    r  r  r   r   r   Ú&test_cleanupsContinueRunningAfterError§  s   z6AddCleanupMixin.test_cleanupsContinueRunningAfterErrorc                 C   s®   | j  | j jd¡ | j  | j jd¡ | j  | j¡ |  g d¢| j j¡ |  dt| jjƒ¡ | jj\\}}\}}|  || j ¡ |  || j ¡ |  | 	¡ d¡ |  | 	¡ d¡ dS )zm
        If more than one cleanup fails, then the test should fail with more
        than one error.
        rþ   r  )r2   r  rÜ   r[   N)
r:   r   r
  r>   r1   r   r  rX   r    r  )r   rð   Úerror1Útest2Úerror2r   r   r   Útest_multipleErrorsReportedµ  s   z+AddCleanupMixin.test_multipleErrorsReported)r)   r*   r+   r,   r2   r  r  r	  r  r  r  Ú__classcell__r   r   rü   r   rù   n  s    	
rù   c                   @   r   )Ú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,   r   rû   r   r   r   r   r  Æ  r‚   r  c                   @   s    e Zd ZdZedƒZdd„ ZdS )ÚAsynchronousAddCleanupTestsz„
    Test the addCleanup method of TestCase in the asynchronous case

    See: L{twisted.trial.test.test_tests.AddCleanupMixin}
    z2twisted.trial.test.skipping.AsynchronousAddCleanupc                    sR   ‡ fdd„}ˆ j  ˆ j jd¡ ˆ j  |d¡ ˆ j  ˆ j¡ ˆ  g d¢ˆ j j¡ dS )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.
        c                    s&   t  ¡ }t d|j| ¡ | ˆ jj¡S )Nr   )r   ÚDeferredr   Ú	callLaterÚcallbackÚaddCallbackr:   rß   )rd   Údr#   r   r   Úcleanupà  s   zMAsynchronousAddCleanupTests.test_addCleanupWaitsForDeferreds.<locals>.cleanuprþ   r  r  Nr  )r   r  r   r#   r   Ú test_addCleanupWaitsForDeferredsÙ  s
   z<AsynchronousAddCleanupTests.test_addCleanupWaitsForDeferredsN)r)   r*   r+   r,   r   rû   r  r   r   r   r   r  Ð  s    r  c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )ÚSuiteClearingMixinzM
    Tests for our extension that allows us to clear out a L{TestSuite}.
    c                 C   óB   t  ¡ }| |  ¡ ¡ |  d| ¡ ¡ t|ƒ |  d| ¡ ¡ dS )z_
        Calling L{_clearSuite} on a populated L{TestSuite} removes
        all tests.
        r5   r   N)r	   Ú	TestSuiteÚaddTestÚTestCaser   r%   r   r   r   r   r   Útest_clearSuiteð  s
   z"SuiteClearingMixin.test_clearSuitec                 C   r   )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.
        r5   r   N)r   r!  r"  r#  r   r%   r   r   r   r   r   Útest_clearPyunitSuiteü  s
   z(SuiteClearingMixin.test_clearPyunitSuiteN)r)   r*   r+   r,   r$  r%  r   r   r   r   r  ë  s    r  c                   @   ó   e Zd ZdZejZdS )Ú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#  r   r   r   r   r'    ó    
r'  c                   @   ó   e Zd ZdZejZdS )Ú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#  r   r   r   r   r+    r)  r+  c                   @   sh   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚTestDecoratorMixinz1
    Tests for our test decoration features.
    c                 C   sd   |   |j|jd¡ t|ddƒ}t|ddƒ}|  ||¡ ||  u r%du r0n dS |  ||¡ dS dS )zB
        Assert that the given decorated tests are equal.
        úDifferent classÚ_originalTestN)r   r=   ÚgetattrrF   )r   ÚobservedÚexpectedÚobservedOriginalÚexpectedOriginalr   r   r   ÚassertTestsEqual'  s   ÿz#TestDecoratorMixin.assertTestsEqualc                 C   sr   |   |j|jd¡ |   t|jƒt|jƒd¡ t|j|jƒD ]\}}t|ddƒdur0|  ||¡ q|  ||¡ qdS )zS
        Assert that the given test suites with decorated tests are equal.
        r.  zDifferent number of tests.Ú_testsN)r   r=   rX   r6  Úzipr0  ÚassertSuitesEqualr5  )r   r1  r2  ÚobservedTestÚexpectedTestr   r   r   r8  2  s   ÿüz$TestDecoratorMixin.assertSuitesEqualc                 C   s@   |   ¡ }t |¡}ddlm} |ƒ }| |¡ |  |j|¡ dS )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>   r5  r:   ©r   r:   ÚdecoratedTestr<  r1   r   r   r   Útest_usesAdaptedReporterWithRun@  s   

z2TestDecoratorMixin.test_usesAdaptedReporterWithRunc                 C   s>   |   ¡ }t |¡}ddlm} |ƒ }||ƒ |  |j|¡ dS )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}.
        r   r;  N)r#  r	   r=  r>  r<  r5  r:   r?  r   r   r   Ú test_usesAdaptedReporterWithCallP  s   
z3TestDecoratorMixin.test_usesAdaptedReporterWithCallc                 C   s,   |   ¡ }t |tj¡}|  t |¡|¡ dS )z€
        Calling L{decorate} on a single test case returns the test case
        decorated with the provided decorator.
        N©r#  r	   Údecorater=  r5  )r   r:   r@  r   r   r   Útest_decorateSingleTesta  s   z*TestDecoratorMixin.test_decorateSingleTestc                 C   s@   |   ¡ }t |g¡}t |tj¡}|  |t t |¡g¡¡ dS )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!  rD  r=  r8  ©r   r:   r   r@  r   r   r   Útest_decorateTestSuitej  ó   ÿz)TestDecoratorMixin.test_decorateTestSuitec                 C   sZ   |   ¡ }t |g¡}t |tj¡}|  |t t |¡g¡¡ |  |t t |¡g¡¡ dS )zU
        Calling L{decorate} on a test suite will mutate the original suite.
        NrF  rG  r   r   r   Ú#test_decorateInPlaceMutatesOriginalv  s   ÿÿz6TestDecoratorMixin.test_decorateInPlaceMutatesOriginalc                 C   s`   t tddƒ}|du rt d¡‚|  ¡ }t |g¡}||ƒ}t |tj¡ ||ƒ}|  ||¡ dS )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)	r0  Úsysr	   ÚSkipTestr#  r!  rD  r=  r   )r   rK  r:   r   Úcount1Úcount2r   r   r   Ú test_decorateTestSuiteReferences„  s   	
z3TestDecoratorMixin.test_decorateTestSuiteReferencesc                 C   sT   |   ¡ }t t |g¡g¡}t |tj¡}t t t |¡g¡g¡}|  ||¡ dS )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.
        NrF  )r   r:   r   r@  r2  r   r   r   Útest_decorateNestedTestSuite˜  s   ÿz/TestDecoratorMixin.test_decorateNestedTestSuitec                 C   s:   |   ¡ }t |tj¡}t |tj¡}|  |t |¡¡ dS )z‰
        Calling L{decorate} on a test suite with already-decorated tests
        decorates all of the tests in the suite again.
        NrC  )r   r:   r@  ÚredecoratedTestr   r   r   Útest_decorateDecoratedSuite¦  s   z.TestDecoratorMixin.test_decorateDecoratedSuitec                 C   s@   |   ¡ }t |g¡}t |tj¡}|  |t t |¡g¡¡ dS )z‰
        Tests can be in non-standard suites. L{decorate} preserves the
        non-standard suites when it decorates the tests.
        N)r#  r   ÚDestructiveTestSuiter	   rD  r=  r8  )r   r:   r   Ú	decoratedr   r   r   Útest_decoratePreservesSuite°  rI  z.TestDecoratorMixin.test_decoratePreservesSuiteN)r)   r*   r+   r,   r5  r8  rA  rB  rE  rH  rJ  rP  rQ  rS  rV  r   r   r   r   r-  "  s    	
r-  c                   @   r&  )ÚSynchronousTestDecoratorTestsz†
    Tests for our test decoration features in the synchronous case.

    See L{twisted.trial.test.test_tests.TestDecoratorMixin}
    Nr(  r   r   r   r   rW  ½  ó    
rW  c                   @   r*  )ÚAsynchronousTestDecoratorTestsz‡
    Tests for our test decoration features in the asynchronous case.

    See L{twisted.trial.test.test_tests.TestDecoratorMixin}
    Nr,  r   r   r   r   rY  Ç  rX  rY  c                   @   r-   )ÚMonkeyPatchMixinzF
    Tests for the patch() helper method in L{unittest.TestCase}.
    c                 C   s"   d| _ d| _| j | _|  ¡ | _dS )r0   ÚoriginalÚpatchedN)ÚoriginalValueÚpatchedValueÚobjectToPatchr#  r:   r#   r   r   r   r2   Ö  s   zMonkeyPatchMixin.setUpc                 C   s&   | j  | d| j¡ |  | j| j¡ dS )zi
        Calling C{patch()} on a test monkey patches the specified object and
        attribute.
        r_  N)r:   Úpatchr^  r   r_  r#   r   r   r   Ú
test_patchß  s   zMonkeyPatchMixin.test_patchc                 C   s6   | j  | d| j¡ | j  t ¡ ¡ |  | j| j¡ dS )zw
        Any monkey patches introduced by a test using C{patch()} are reverted
        after the test has run.
        r_  N)	r:   r`  r^  r>   r   r¹   r   r_  r]  r#   r   r   r   Útest_patchRestoredAfterRunç  s   z+MonkeyPatchMixin.test_patchRestoredAfterRunc                 C   s.   | j  | d| j¡}| ¡  |  | j| j¡ dS )z˜
        C{patch()} return a L{monkey.MonkeyPatcher} object that can be used to
        restore the original values before the end of the test.
        r_  N)r:   r`  r^  Úrestorer   r_  r]  ©r   r`  r   r   r   Útest_revertDuringTestð  s   z&MonkeyPatchMixin.test_revertDuringTestc                 C   s6   | j  | d| j¡}| ¡  | ¡  |  | j| j¡ dS )zq
        The returned L{monkey.MonkeyPatcher} object can re-apply the patch
        during the test run.
        r_  N)r:   r`  r^  rc  r   r_  rd  r   r   r   Útest_revertAndRepatchù  s   z&MonkeyPatchMixin.test_revertAndRepatchc                 C   sd   | j  | d| j¡ |  | j| j¡ | j  | dd¡ |  | jd¡ | j  t ¡ ¡ |  | j| j¡ dS )zW
        Successive patches are applied and reverted just like a single patch.
        r_  zsecond valueN)	r:   r`  r^  r   r_  r>   r   r¹   r]  r#   r   r   r   Útest_successivePatches  s   z'MonkeyPatchMixin.test_successivePatchesN)
r)   r*   r+   r,   r2   ra  rb  re  rf  rg  r   r   r   r   rZ  Ñ  s    			
rZ  c                   @   r&  )ÚSynchronousMonkeyPatchTestsz
    Tests for the patch() helper method in the synchronous case.

    See L{twisted.trial.test.test_tests.MonkeyPatchMixin}
    Nr(  r   r   r   r   rh    rX  rh  c                   @   r*  )ÚAsynchronousMonkeyPatchTestsz‚
    Tests for the patch() helper method in the asynchronous case.

    See L{twisted.trial.test.test_tests.MonkeyPatchMixin}
    Nr,  r   r   r   r   ri    rX  ri  c                   @   rÁ   )ÚIterateTestsMixinz]
    L{_iterateTests} returns a list of all test cases in a test suite or test
    case.
    c                 C   s"   |   ¡ }|  |gtt|ƒƒ¡ dS )zj
        L{_iterateTests} on a single test case returns a list containing that
        test case.
        N)r#  r   rË   r   r?   r   r   r   Útest_iterateTestCase)  s   z&IterateTestsMixin.test_iterateTestCasec                 C   s.   |   ¡ }t |g¡}|  |gtt|ƒƒ¡ dS )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   ©r   r:   r   r   r   r   Útest_iterateSingletonTestSuite1  s   z0IterateTestsMixin.test_iterateSingletonTestSuitec                 C   s6   |   ¡ }t t |g¡g¡}|  |gtt|ƒƒ¡ dS )zP
        L{_iterateTests} returns tests that are in nested test suites.
        Nrl  rm  r   r   r   Útest_iterateNestedTestSuite:  s   z-IterateTestsMixin.test_iterateNestedTestSuitec                 C   s:   |   ¡ }t t |g¡| g¡}|  || gtt|ƒƒ¡ dS )zU
        L{_iterateTests} returns tests in left-to-right, depth-first order.
        Nrl  rm  r   r   r   Ú#test_iterateIsLeftToRightDepthFirstB  s   z5IterateTestsMixin.test_iterateIsLeftToRightDepthFirstN)r)   r*   r+   r,   rk  rn  ro  rp  r   r   r   r   rj  #  s    	rj  c                   @   r&  )Ú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(  r   r   r   r   rq  K  r)  rq  c                   @   r*  )Ú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,  r   r   r   r   rr  V  r)  rr  c                   @   r  )ÚTrialGeneratorFunctionTestsz=
    Tests for generator function methods in test cases.
    c                 C   ó®   G dd„ dt jƒ}|dƒ}t ¡ }| |¡ |  t|jƒd¡ |  t|jƒd¡ |  	d|jd d j
jd ¡ |  	d|jd d j
jd ¡ |  	d|jd d j
jd ¡ 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                   @   rä   )zTTrialGeneratorFunctionTests.test_errorOnGeneratorFunction.<locals>.GeneratorTestCasez?
            A fake TestCase for testing purposes.
            c                 s   ó    |   d¡ dV  dS ©zt
                A method which is also a generator function, for testing
                purposes.
                zthis should never be reachedN©r
  r#   r   r   r   Útest_generatorq  ó   €

zcTrialGeneratorFunctionTests.test_errorOnGeneratorFunction.<locals>.GeneratorTestCase.test_generatorN©r)   r*   r+   r,   rx  r   r   r   r   ÚGeneratorTestCasel  rç   r{  rx  r   r5   z GeneratorTestCase.test_generatorz+GeneratorTestCase testMethod=test_generatorú4is a generator function and therefore will never runN)r	   r#  r   r   r>   r   rX   r!   r    ÚassertInrÅ   Úargs)r   r{  ÚtestCaser1   r   r   r   Útest_errorOnGeneratorFunctionf  s"   
ÿþþz9TrialGeneratorFunctionTests.test_errorOnGeneratorFunctionc                 C   rt  )
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                   @   rä   )zrTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction.<locals>.GeneratorSynchronousTestCasezJ
            A fake SynchronousTestCase for testing purposes.
            c                 s   ru  rv  rw  r#   r   r   r   rx  •  ry  zTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction.<locals>.GeneratorSynchronousTestCase.test_generatorNrz  r   r   r   r   ÚGeneratorSynchronousTestCase  rç   r  rx  r   r5   z+GeneratorSynchronousTestCase.test_generatorz6GeneratorSynchronousTestCase testMethod=test_generatorr|  N)r	   rã   r   r   r>   r   rX   r!   r    r}  rÅ   r~  )r   r  r  r1   r   r   r   Ú0test_synchronousTestCaseErrorOnGeneratorFunctionŠ  s$   
þþþzLTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunctionN)r)   r*   r+   r,   r€  r‚  r   r   r   r   rs  a  s    $rs  )Ir,   rD   rL  r	   r   rB   Úior   Útwisted.internetr   r   Útwisted.python.compatr   Útwisted.python.reflectr   Útwisted.trialr   r   r
   Útwisted.trial._asyncrunnerr   r   r   rí   r   Ú#twisted.trial.test.test_suppressionr   r   r.   rã   rI   r#  rM   rN   rl   ro   rq   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-  rW  rY  rZ  rh  ri  rj  rq  rr  rs  r   r   r   r   Ú<module>   st    ;I3

X7

7+377X
! 

>

(