ϪfMdZddlZddlZddlZddlZddlmZddlm Z m Z ddl m Z ddl mZddlmZmZmZmZddlmZmZmZdd lmZdd lmZGd d ZGd dZGddeej:ZGddeej>Z GddeZ!Gdde!ej:Z"Gdde!ej>Z#GddeZ$Gdde$ej:Z%Gdde$ej>Z&Gdd eZ'Gd!d"e'ej:Z(Gd#d$e'ej>Z)Gd%d&eZ*Gd'd(e*ej:Z+Gd)d*e*ej>Z,Gd+d,eZ-Gd-d.e-ej:Z.Gd/d0e-ej>Z/Gd1d2ej:Z0Gd3d4Z1Gd5d6e1ej:Z2Gd7d8e1ej>Z3Gd9d:eej>Z4Gd;d<Z5Gd=d>e5ej:Z6Gd?d@e5ej:Z7GdAdBej:Z8GdCdDZ9GdEdFe9ej:Z:GdGdHe9ej>Z;GdIdJZ<GdKdLeZ>GdOdPZ?GdQdRe?ej:Z@GdSdTe?ej>ZAGdUdVZBGdWdXeBej:ZCGdYdZeBej>ZDGd[d\ZEGd]d^eEej:ZFGd_d`eEej>ZGGdadbej:ZHy)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)deferreactor)_PYPY)namedAny)reporterrunnerunittestutil) _clearSuite _ForceGarbageCollectionDecorator _iterateTests) erroneous)SuppressionMixinc"eZdZdZdZdZdZy)ResultsTestMixinzG Provide useful APIs for test cases that are about test cases. ctj|_|jj||_t j |_y)zt Load tests from the given test case class and create a new reporter to use for running it. N)pyunit TestLoaderloaderloadTestsFromTestCasesuiter TestResultselfrs ?/usr/lib/python3/dist-packages/twisted/trial/test/test_tests.py loadSuitezResultsTestMixin.loadSuite1s: '') [[66u=  ++- c:|j|jj|j|jjg|j|jj g|j|jj gy)z test the setup N) assertTruer wasSuccessful assertEqualerrorsfailuresskipsrs r test_setUpzResultsTestMixin.test_setUp:sk  3356 --r2 //4 ,,b1rc|j|jj||j|j|j|jj|y)z: Asserts that the test count is plausible N)r"rcountTestCasesrtestsRun)rnumTestss r assertCountzResultsTestMixin.assertCountCsK 224h? 4==! //:rN)__name__ __module__ __qualname____doc__rr'r,rrrr,s.2;rrc4eZdZdZdZdZdZdZdZdZ y) SuccessMixinz\ Tests for the reporting of successful tests in L{twisted.trial.unittest.TestCase}. c6tj|_y% Setup our test case N)rrresultr&s rsetUpzSuccessMixin.setUpQs))+ rcy)z9 A successful test, used by other tests. Nr1r&s rtest_successfulzSuccessMixin.test_successfulWsrcT|j|jd|j|jg|j|jg|j|jg|j|j g|j|j gy)zd Utility function -- assert there is one success and the state is plausible N)r" successesr$r#expectedFailuresunexpectedSuccessesr%rtestr7s rassertSuccessfulzSuccessMixin.assertSuccessful\s ))1- "- + 00"5 33R8 r*rc|jd}|j|j|j||jy)z Test that when a successful test is run, it is reported as a success, and not as any other kind of result. r:N __class__runr7rBrrAs rtest_successfulIsReportedz&SuccessMixin.test_successfulIsReportedhs7 ~~/0  dDKK0rc|j}|j|j|j||jy)zz The test case type can be instantiated with no arguments, run, and reported as being successful. NrDrGs rtest_defaultIsSuccessfulz%SuccessMixin.test_defaultIsSuccessfulqs4 ~~  dDKK0rc|jd}tj|}|j|j|j ||j~t j|j|dy)zF Test that no reference is kept on a successful test. r:N) rEweakrefrefrFr7rBgccollectassertIdentical)rrArMs rtest_noReferencezSuccessMixin.test_noReferencezsc~~/0kk$  dDKK0   SUD)rN) r-r.r/r0r8r:rBrHrJrQr1rrr3r3Ls%,  +11 *rr3ceZdZdZy)SynchronousSuccessTestsN Tests for the reporting of successful tests in the synchronous case. Nr-r.r/r0r1rrrSrSrrSceZdZdZy)AsynchronousSuccessTestsrTNrUr1rrrXrXrVrrXc4eZdZdZdZdZdZdZdZdZ y) SkipMethodsMixinzZ Tests for the reporting of skipping tests in L{twisted.trial.unittest.TestCase}. c:|j|jyr5)rSkippingr&s rr8zSkipMethodsMixin.setUps t}}%rc&|jdy)z4 Assert that there are three tests. Nr,r&s r test_countingzSkipMethodsMixin.test_counting rc|j|j|j|jj|j |jj g|j |jj g|j t|jjd|j |jjdy)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. r^rN rrr r!r"r#r$lenr%r=r&s r test_resultszSkipMethodsMixin.test_results 4==!  3356 --r2 //4 T]]00115 00!4rc|j|j|j|j|j |jj |j |jjg|j |jjg|j t|jjd|j |jjdy)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 SkippingSetUprrr r!r"r#r$rdr%r=r&s rr'zSkipMethodsMixin.test_setUps t))* 4==!  3356 --r2 //4 T]]00115 00!4rc|j|jd}|jjD]:\}}|j|j t |dt |<y)z( Test that reasons work test_N)rrr%r"shortDescriptionrdstr)rprefixrAreasons r test_reasonszSkipMethodsMixin.test_reasonss` 4==! MM// RLD&   T224S[]CS[ Q RrcZ|j|j|j|j|j |jj g}|j dt||j t|dd|j d|ddy)zo If a test method raises L{SkipTest} with no reason, a deprecation warning is emitted. r<rcategoryzSDo not raise unittest.SkipTest with no arguments! Give a reason for skipping tests!messageN) rDeprecatedReasonlessSkiprr flushWarningstest_1r"rdDeprecationWarning)rwarningss r test_deprecatedSkipWithoutReasonz1SkipMethodsMixin.test_deprecatedSkipWithoutReasons t445 4==!%%t'D'D'K'K&LM CM* +Xa[-DE  " QK " rN) r-r.r/r0r8r`rer'rpryr1rrrZrZs&&  5 5R rrZc@eZdZdZedZedZedZy)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.SynchronousDeprecatedReasonlessSkipNr-r.r/r0rr\rirtr1rrr{r{s- IJHSTM'I rr{c@eZdZdZedZedZedZy)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|r1rrr~r~s- JKHTUM'J rr~c.eZdZdZdZdZdZdZdZy)SkipClassesMixinzQ Test the class skipping features of L{twisted.trial.unittest.TestCase}. c\|j|jd|j_y)r6FN)r SkippedClass _setUpRanr&s rr8zSkipClassesMixin.setUps$ t(()&+#rc&|jdy)zP Skipped test methods still contribute to the total test count. Nr_r&s rr`zSkipClassesMixin.test_countingrarc|j|j|j|jjy)zP The C{setUp} method is not called if the class is set to skip. N)rr assertFalserrr&s r test_setUpRanzSkipClassesMixin.test_setUpRan s. 4==! **445rc|j|j|j|jj|j |jj g|j |jj g|j t|jjd|j |jjdy)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. rrNrcr&s rrezSkipClassesMixin.test_resultsrfrc|j|jgd}|jjDcgc]\}}| }}}|j||ycc}}w)z Test methods which raise L{unittest.SkipTest} or have their C{skip} attribute set to something are skipped. )classskip2rrN)rrr%r")rexpectedReasonsrAro reasonsGivens rrpzSkipClassesMixin.test_reasonssP 4==!>37==3F3FG<4G G ,7Hs AN) r-r.r/r0r8r`rrerpr1rrrrs , 6 5 8rrc eZdZdZedZy)SynchronousSkipClassTestsz Test the class skipping features in the synchronous case. See: L{twisted.trial.test.test_tests.SkipClassesMixin} z3twisted.trial.test.skipping.SynchronousSkippedClassNr-r.r/r0rrr1rrrr+s QRLrrc eZdZdZedZy)AsynchronousSkipClassTestsz Test the class skipping features in the asynchronous case. See: L{twisted.trial.test.test_tests.SkipClassesMixin} z4twisted.trial.test.skipping.AsynchronousSkippedClassNrr1rrrr5s RSLrrc:eZdZdZdZdZdZdZdZdZ dZ y ) TodoMixinzv Tests for the individual test method I{expected failure} features of L{twisted.trial.unittest.TestCase}. c:|j|jyr5)rTodor&s rr8zTodoMixin.setUpEs tyy!rc&|jdy)z9 Ensure that we've got three test cases. r^Nr_r&s rr`zTodoMixin.test_countingKrarcx|j|j|j|jj|j |jj g|j |jj g|j |jjg|j t|jjd|j t|jjd|j |jjdy)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. rhr<rN rrr r!r"r#r$r%rdr>r?r=r&s rrezTodoMixin.test_resultsQ 4==!  3356 --r2 //4 ,,b1 T]];;>?C 00!4rc|j|jddg}|jjDcgc]\}}}|j}}}}|j ||ycc}}}w)E Ensure that expected failures are handled properly. todo1todo2Nrrr>ror"rrterrs rtest_expectedFailureszTodoMixin.test_expectedFailurescs^ 4==!"G,04 0N0NOOWQ1O O ,7PA(c|j|jdg}|jjDcgc]\}}|j}}}|j ||ycc}}w)> Ensure that unexpected successes are caught. todo3Nrrr?ror"rrrrrs rtest_unexpectedSuccessesz"TodoMixin.test_unexpectedSuccesseslsV 4==!")-1]]-N-NOTQO O ,7PsA$c|j|j|j|j|j |jj |j t|jjd|j |jjg|j |jjg|j t|jjd|j t|jjd|j |jjdy)z| C{setUp} is excluded from the failure expectation defined by a C{todo} attribute on a test method. r<rN)r SetUpTodorrrr!r"rdr#r$r%r>r?r=r&s rtest_expectedSetUpFailurez#TodoMixin.test_expectedSetUpFailureus t~~& 4==! 4467 T]]112A6 //4 ,,b1 T]];;>?C 00!4rc|j|j|j|j|j |jj |j t|jjd|j |jjg|j |jjg|j t|jjd|j t|jjd|j |jjdy)z C{tearDown} is excluded from the failure expectation defined by a C{todo} attribute on a test method. r<rN)r TearDownTodorrrr!r"rdr#r$r%r>r?r=r&s rtest_expectedTearDownFailurez&TodoMixin.test_expectedTearDownFailures t(() 4==! 4467 T]]112A6 //4 ,,b1 T]];;>?C 00!4rN) r-r.r/r0r8r`rerrrrr1rrrr?s* "  5$88 55rrc@eZdZdZedZedZedZy)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.SynchronousTearDownTodoNr-r.r/r0rrrrr1rrrrs* A BDKLIQRLrrc@eZdZdZedZedZedZy)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.AsynchronousTearDownTodoNrr1rrrrs* B CDLMIRSLrrc.eZdZdZdZdZdZdZdZy)ClassTodoMixinzj Tests for the class-wide I{expected failure} features of L{twisted.trial.unittest.TestCase}. c:|j|jyr5)r TodoClassr&s rr8zClassTodoMixin.setUps t~~&rc&|jdy)z8 Ensure that we've got four test cases. rNr_r&s rr`zClassTodoMixin.test_countingrarcx|j|j|j|jj|j |jj g|j |jj g|j |jjg|j t|jjd|j t|jjd|j |jjdy)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. rhrNrr&s rrezClassTodoMixin.test_resultsrrc|j|jddg}|jjDcgc]\}}}|j}}}}|j ||ycc}}}w)rmethodrNrrs rrz$ClassTodoMixin.test_expectedFailuress^ 4==!#W-04 0N0NOOWQ1O O ,7Prc|j|jddg}|jjDcgc]\}}|j}}}|j ||ycc}}w)rrrNrrs rrz'ClassTodoMixin.test_unexpectedSuccessessY 4==!#W--1]]-N-NOTQO O ,7PsA%N r-r.r/r0r8r`rerrr1rrrrs  '  5$88rrc eZdZdZedZy)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.SynchronousTodoClassNr-r.r/r0rrr1rrrrs KLIrrc eZdZdZedZy)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.AsynchronousTodoClassNrr1rrrrs LMIrrc.eZdZdZdZdZdZdZdZy)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:|j|jyr5)r StrictTodor&s rr8zStrictTodoMixin.setUps t'rc&|jdy)z3 Assert there are seven test cases Nr_r&s rr`zStrictTodoMixin.test_countingrarc|j|j|j|jj|j t |jj d|j t |jjd|j t |jjd|j t |jjd|j |jjd|j |jjgy)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. rhr<r^rN) rrrr!r"rdr#r$r>r?r=r%r&s rrezStrictTodoMixin.test_results s 4==! 4467 T]]112A6 T]]334a8 T]];;>?C 00!4 ,,b1rc|j|jgd}|jjDcgc]\}}}|j}}}}|j ||ycc}}}w)r)rrtodo5Nr)rrrrr reasonsGottens rrz%StrictTodoMixin.test_expectedFailuressY 4==!5151O1OPPgaAP P -8Qrc|j|jtgdfg}|jjDcgc]\}}|j|j f}}}|j ||ycc}}w)rtodo7N)rr RuntimeErrorr?r#ror")rrrrrs rrz(StrictTodoMixin.test_unexpectedSuccesses%so 4==!)NG45-1]]-N-N %)QQXXqxx    -8 s"A7Nrr1rrrrs  (  29 9rrc eZdZdZedZy)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.SynchronousStrictTodoNr-r.r/r0rrr1rrrr1sMNJrrc eZdZdZedZy)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.AsynchronousStrictTodoNrr1rrrr<sNOJrrc"eZdZdZdZdZdZy)ReactorCleanupTestszc Tests for cleanup and reporting of reactor event sources left behind by test methods. cztjt|_t j |_yr5)rReporterrr7r rrr&s rr8zReactorCleanupTests.setUpMs('' 3 '') rc|jjd}|j|j|j |jj |j |jjd|jjdd}|j|jtjy)zm Trial reports a L{util.DirtyReactorAggregateError} if a test leaves sockets behind. z@twisted.trial.test.erroneous.SocketOpenTest.test_socketsLeftOpenr<rN) r loadByNamerFr7rr!r"r=r#r checkr DirtyReactorAggregateErrorrrfailures rtest_leftoverSocketsz(ReactorCleanupTests.test_leftoverSocketsTs  && N   $++ 2245 ..2++$$Q'*  d&E&EFGrctjd}|j|j|j |jj |jj dd}|j|jjd|j|jtjy)z Trial reports a L{util.DirtyReactorAggregateError} and fails the test if a test leaves a L{DelayedCall} hanging. test_leftoverPendingCallsrr<N) rrrFr7rr!r#r"r=r rr rrs rrz-ReactorCleanupTests.test_leftoverPendingCallses --.IJ $++ 2245++$$Q'* ..2  d&E&EFGrN)r-r.r/r0r8rrr1rrrrGs *H" Hrrc(eZdZdZdZdZdZdZy) FixtureMixinzB Tests for fixture helper methods (e.g. setUp, tearDown). chtj|_tj|_yr5)rrrrrr&s rr8zFixtureMixin.setUpws$!))+ '') rc|jj|j}|j|j|j t |jjdkD|j|jjddjtj|jd|jjy)zO When setUp fails, the error is recorded in the result object. rr<N)rrTestFailureInSetUprFrr rdr#assertIsInstancevaluer FoolishErrorr"r=rs rtest_brokenSetUpzFixtureMixin.test_brokenSetUp~s 11$2I2IJ $--  DMM001A56 dmm2215a8>> @V@VW DMM334rc|jj|j}|j|j|jj }|j t|dkD|j|ddjtj|jd|jjy)zR When tearDown fails, the error is recorded in the result object. rr<N)rrTestFailureInTearDownrFrr#r rdrrrrr"r=)rrr#s rtest_brokenTearDownz FixtureMixin.test_brokenTearDowns 11$2L2LM $-- %% F a( fQil00)2H2HI DMM334rc|jj|j}t|d}|j |j |j |j|jj}|jt|dkD|j|ddjtj|jd|jj |j|j y)zP L{SynchronousTestCase.tearDown} runs when a test method fails. rr<N)rrTestFailureButTearDownRunslistrtornDownrFrr#r rdrrrrr"r=)rrcaser#s rtest_tearDownRunsOnTestFailurez+FixtureMixin.test_tearDownRunsOnTestFailures 11$2Q2QRE{1~ ' $-- %% F a( fQil00)2H2HI DMM334  &rN)r-r.r/r0r8rrrr1rrrrrs*5 5'rrc@eZdZdZedZedZedZy)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.SynchronousTestFailureButTearDownRunsNr-r.r/r0rrrrr1rrrrs7 "D%G"*L"rrc@eZdZdZedZedZedZy)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.AsynchronousTestFailureButTearDownRunsNrr1rrrrs7 "E%H"*M"rrcPeZdZdZedZedZedZedZy)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/r0rTestSetUpSuppressionTestTearDownSuppressionTestSuppressionTestSuppression2r1rrrrsF$I'LDO ErrcReZdZdZGddej ZdZdZdZ dZ y) 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"eZdZdZdZdZdZy)GCMixin.BasicTestz# Mock test to run. c&|jdy)z$ Mock setUp r8N_logr&s rr8zGCMixin.BasicTest.setUps IIg rc&|jdy)z( Mock test case rANrr&s rtest_foozGCMixin.BasicTest.test_foos IIf rc&|jdy)z, Mock tear tearDown tearDownNrr&s rr zGCMixin.BasicTest.tearDowns IIj !rN)r-r.r/r0r8r r r1rr BasicTestrs      "rrc:|jj|y)z Log function N)_collectCalledappend)rmsgs rr z GCMixin._logs ""3'rc&|jdy)zFake gc.collectrONrr&s rrOzGCMixin.collects )rcg|_|j|j_tj|_|jt_yr5)rr rrNrO _oldCollectr&s rr8z GCMixin.setUps3!"ii::\\ rc.|jt_yz$ Tear down the test N)rrNrOr&s rr zGCMixin.tearDowns%% rN) r-r.r/r0r SynchronousTestCaserr rOr8r r1rrrrs- "H00".( "&rrceZdZdZdZy)GarbageCollectionDefaultTestsz@ By default, tests should not force garbage collection. c|jd}tj}|j||j |j gdy)zH By default, tests should not force garbage collection. r )r8rAr N)rrrrFr"rr@s rtest_collectNotDefaultz4GarbageCollectionDefaultTests.test_collectNotDefaultsC~~j)$$&  ,,.KLrN)r-r.r/r0rr1rrrrs MrrceZdZdZdZy)GarbageCollectionTestsz- Test that, when force GC, it works. ctjd}t|}tj}|j ||j |jgdy)zG test gc.collect is called before and after each test. r )rOr8rAr rON)rrr rrrFr"rr@s rtest_collectCalledz)GarbageCollectionTests.test_collectCalled*sR&// ;/5$$&     !T rN)r-r.r/r0r r1rrrr%s   rrcTeZdZdZdZdZejeddZ dZ y)UnhandledDeferredTestsz\ Test what happens when we have an unhandled deferred left around after a test. cvddlm}tjt |j d|_y)r6r)weirdtest_unhandledDeferredN)twisted.trial.testr$rNdisabler TestBleedingtest1)rr$s rr8zUnhandledDeferredTests.setUp=s- - 5   7 8  rctj}|j||jt |j ddy)zo Forcing garbage collection should cause unhandled Deferreds to be reported as errors. r<z(Unhandled deferred passed without noticeN)rrr)r"rdr#)rr7s rtest_isReportedz&UnhandledDeferredTests.test_isReportedIs= $$& 6   #M rzGC works differently on PyPy.ctj}|j||jt t j }|j|dd|j}|jt |ddy)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)rrr)flushLoggedErrorsrdrNgarbager")rr7nxs rtest_doesntBleedz'UnhandledDeferredTests.test_doesntBleedTsq $$& 6    O A@A  " " $ Q$DErcttjtj|jyr)rNrOenabler-r&s rr zUnhandledDeferredTests.tearDownes"    rN) r-r.r/r0r8r+rskipIfrr1r r1rrr"r"7s:    V]]59:F;F !rr"cLeZdZdZfdZdZdZdZdZdZ dZ d Z xZ S) AddCleanupMixinz1 Test the addCleanup method of TestCase. c~t|tj|_|j |_yr5)superr8rrr7 AddCleanuprA)rrEs rr8zAddCleanupMixin.setUpss,  ))+ OO% rcH|jj|j_|jj|jjd|jj |j |jddg|jjy)zQ Callables added with C{addCleanup} are run even if setUp fails. foor8N) rA brokenSetUpr8 addCleanuprrFr7r"logr&s r!test_addCleanupCalledIfSetUpFailsz1AddCleanupMixin.test_addCleanupCalledIfSetUpFails{sh))//  TYY--u5 dkk" '5)499==9rcH|jj|j_|jj|jjd|jj |j |jddg|jjy)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;r8N) rA skippingSetUpr8r=rrFr7r"r>r&s r!test_addCleanupCalledIfSetUpSkipsz1AddCleanupMixin.test_addCleanupCalledIfSetUpSkipssh ))11  TYY--u5 dkk" '5)499==9rc^|jj|jjd|jj|jjd|jj|j|j gd|jj y)z~ Callables added with C{addCleanup} should be called before C{tearDown} in reverse order of addition. r;barr8runTestrDr;r NrAr=rrFr7r"r>r&s r#test_addCleanupCalledInReverseOrderz3AddCleanupMixin.test_addCleanupCalledInReverseOrdersm TYY--u5 TYY--u5 dkk" GWrc |jj|jjd|jj|j|j |jj |jdt|jj|jj\\}}|j||j|j|jdy)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;r<N) rAr=failrFr7rr!r"rdr#getErrorMessagerrAerrors rtest_errorInCleanupIsCapturedz-AddCleanupMixin.test_errorInCleanupIsCaptureds TYY^^U3 dkk" 2245 C 2 234++,,$ tyy) ..0%8rcj|jj|jjd|jj|jjd|jj |j |j gd|jj|j dt|j j|j j\\}}|j ||j|j |jdy)zq If a cleanup raises an error then that does not stop the other cleanups from being run. r;rD)r8rFr;r r<N) rAr=rrJrFr7r"r>rdr#rKrLs r&test_cleanupsContinueRunningAfterErrorz6AddCleanupMixin.test_cleanupsContinueRunningAfterErrors TYY--u5 TYY^^U3 dkk" @$))--P C 2 234++,,$ tyy) ..0%8rc|jj|jjd|jj|jjd|jj|j|j gd|jj |j dt|jj|jj\\}}\}}|j ||j|j ||j|j |jd|j |jdy)zm If more than one cleanup fails, then the test should fail with more than one error. r;rD)r8rFr rhN) rAr=rJrFr7r"r>rdr#rK)rr)error1test2error2s rtest_multipleErrorsReportedz+AddCleanupMixin.test_multipleErrorsReporteds TYY^^U3 TYY^^U3 dkk" 9499==I C 2 234-1[[-?-?*%/5&  *  * //159 //159rc g|jjfdd|jj|jd|jj|j|j dgy)zA A function registered as a cleanup is run once. c&jS)N)r)cleanupsstagesrz6AddCleanupMixin.test_cleanupRunsOnce..sX__U%;rfirstsecondN)rAr=rFr7r")rrXrYs @@rtest_cleanupRunsOncez$AddCleanupMixin.test_cleanupRunsOncesc ;< dkk" dkk" G9-r) r-r.r/r0r8r?rBrHrNrPrUr] __classcell__)rEs@rr6r6ns1&: :X 9 9: .rr6c eZdZdZedZy)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/r0rr9r1rrr`r`s MNJrr`c&eZdZdZedZdZy)AsynchronousAddCleanupTestsz Test the addCleanup method of TestCase in the asynchronous case See: L{twisted.trial.test.test_tests.AddCleanupMixin} z2twisted.trial.test.skipping.AsynchronousAddCleanupcBfd}jjjjdjj|djjjj gdjj y)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. ctj}tjd|j||j j jS)Nr)rDeferredr callLatercallback addCallbackrAr)rsdrs rcleanupzMAsynchronousAddCleanupTests.test_addCleanupWaitsForDeferreds..cleanups> A   aW 5==!1!12 2rr;rDrENrG)rrjs` r test_addCleanupWaitsForDeferredsz#?@ ))%1G1GH %%   !7!7!= > ? @  }h7rc|j}tj|tj}tj|tj}|j |tj|y)z Calling L{decorate} on a test suite with already-decorated tests decorates all of the tests in the suite again. Nr)rrArredecoratedTests rtest_decorateDecoratedSuitez.TestDecoratorMixin.test_decorateDecoratedSuitesZ }} ))$0F0FG "++M8;Q;QR ox/E/Em/TUrc |j}tj|g}tj|tj }|j |tjtj |gy)z Tests can be in non-standard suites. L{decorate} preserves the non-standard suites when it decorates the tests. N)rqr DestructiveTestSuiter rrr)rrAr decorateds rtest_decoratePreservesSuitez.TestDecoratorMixin.test_decoratePreservesSuitese }}++TF3%%eX-C-CD   v22H4J4J44P3QR rN)r-r.r/r0rrrrrrrrrrrr1rrr~r~1sA 5 B: :"K    )( 8V  rr~c(eZdZdZej Zy)SynchronousTestDecoratorTestsz Tests for our test decoration features in the synchronous case. See L{twisted.trial.test.test_tests.TestDecoratorMixin} Nrwr1rrrr ++Hrrc(eZdZdZej Zy)AsynchronousTestDecoratorTestsz Tests for our test decoration features in the asynchronous case. See L{twisted.trial.test.test_tests.TestDecoratorMixin} Nr{r1rrrr   Hrrc4eZdZdZdZdZdZdZdZdZ y) MonkeyPatchMixinzF Tests for the patch() helper method in L{unittest.TestCase}. cld|_d|_|j|_|j|_y)r6originalpatchedN) originalValue patchedValue objectToPatchrqrAr&s rr8zMonkeyPatchMixin.setUps/(%!//MMO rc|jj|d|j|j|j|jy)zi Calling C{patch()} on a test monkey patches the specified object and attribute. rN)rApatchrr"rr&s r test_patchzMonkeyPatchMixin.test_patchs: ot/@/@A ++T->->?rc|jj|d|j|jjt j |j |j|jy)zw Any monkey patches introduced by a test using C{patch()} are reverted after the test has run. rN) rArrrFrrr"rrr&s rtest_patchRestoredAfterRunz+MonkeyPatchMixin.test_patchRestoredAfterRunsS ot/@/@A h'')* ++T-?-?@rc|jj|d|j}|j|j |j |j y)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)rArrrestorer"rrrrs rtest_revertDuringTestz&MonkeyPatchMixin.test_revertDuringTestsE  ot7H7HI  ++T-?-?@rc|jj|d|j}|j|j|j |j |jy)zq The returned L{monkey.MonkeyPatcher} object can re-apply the patch during the test run. rN)rArrrr"rrs rtest_revertAndRepatchz&MonkeyPatchMixin.test_revertAndRepatchsN  ot7H7HI   ++T->->?rc|jj|d|j|j|j|j|jj|dd|j|jd|jj t j|j|j|jy)zW Successive patches are applied and reverted just like a single patch. rz second valueN) rArrr"rrFrrrr&s rtest_successivePatchesz'MonkeyPatchMixin.test_successivePatchess ot/@/@A ++T->->? o~> ++^< h'')* ++T-?-?@rN) r-r.r/r0r8rrrrrr1rrrrs*$@AA@ Arrc(eZdZdZej Zy)SynchronousMonkeyPatchTestsz Tests for the patch() helper method in the synchronous case. See L{twisted.trial.test.test_tests.MonkeyPatchMixin} Nrwr1rrrrrrrc(eZdZdZej Zy)AsynchronousMonkeyPatchTestsz Tests for the patch() helper method in the asynchronous case. See L{twisted.trial.test.test_tests.MonkeyPatchMixin} Nr{r1rrrr(rrrc(eZdZdZdZdZdZdZy)IterateTestsMixinz] L{_iterateTests} returns a list of all test cases in a test suite or test case. cn|j}|j|gtt|y)zj L{_iterateTests} on a single test case returns a list containing that test case. N)rqr"rrrGs rtest_iterateTestCasez&IterateTestsMixin.test_iterateTestCase8s+ }} $mD&9!:;rc|j}tj|g}|j|gt t |y)z L{_iterateTests} on a test suite that contains a single test case returns a list containing that test case. Nrqr ror"rrrrArs rtest_iterateSingletonTestSuitez0IterateTestsMixin.test_iterateSingletonTestSuite@s= }}  $( $mE&:!;.GeneratorTestCasez? A fake TestCase for testing purposes. c36K|jddywzt A method which is also a generator function, for testing purposes. zthis should never be reachedNrJr&s rtest_generatorzcTrialGeneratorFunctionTests.test_errorOnGeneratorFunction..GeneratorTestCase.test_generator  89Nr-r.r/r0rr1rrGeneratorTestCaser{   rrrrr<z GeneratorTestCase.test_generatorz+GeneratorTestCase testMethod=test_generator4is a generator function and therefore will never runN) r rqrrrFr"rdr$r#assertInrargs)rrtestCaser7s rtest_errorOnGeneratorFunctionz9TrialGeneratorFunctionTests.test_errorOnGeneratorFunctionus  1 1 %%56$$& V V__-q1 V]]+Q/ . a0@0C0I0I0N0Nq0Q  9 MM! Q  % % * *1 -  B MM! Q  % % * *1 - rczGddtj}|d}tj}|j ||j t |jd|j t |jd|jd|jddjjd|jd|jddjjd|jd|jddjjdy ) 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. ceZdZdZdZy)rTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction..GeneratorSynchronousTestCasezJ A fake SynchronousTestCase for testing purposes. c36K|jddywrrr&s rrzTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunction..GeneratorSynchronousTestCase.test_generatorrrNrr1rrGeneratorSynchronousTestCaserrrrrrr<z+GeneratorSynchronousTestCase.test_generatorz6GeneratorSynchronousTestCase testMethod=test_generatorrN) r rrrrFr"rdr$r#rrr)rrrr7s r0test_synchronousTestCaseErrorOnGeneratorFunctionzLTrialGeneratorFunctionTests.test_synchronousTestCaseErrorOnGeneratorFunctions 8+G+G 00@A$$& V V__-q1 V]]+Q/ 9 MM! Q  % % * *1 -  D MM! Q  % % * *1 -  B MM! Q  % % * *1 - rN)r-r.r/r0rrr1rrrrps" H# rr)Ir0rNrr rrLiortwisted.internetrrtwisted.python.compatrtwisted.python.reflectr twisted.trialrr r twisted.trial._asyncrunnerr r rr&r#twisted.trial.test.test_suppressionrrr3rrSrqrXrZr{r~rrrrrrrrrrrrrrrrrrrrr"r6r`rbrmrvrzr~rrrrrrrrrr1rrrsl* +'+:: )@;;@8*8*vlH,H,H |X->-> F 'F R !183O3O  "2H4E4E 08'08fS 0(2N2NST!183D3DTU5 U5p S9h&B&B S TIx'8'8 T48%48nM0L0LMN1B1BN49&49nO(2N2NOP/83D3DP(H(66(HV0'0'flH,H,H$|X->->$#3X5F5F,4&4&n MGX-I-I M Wh&B&B $4!X994!nd.d.NO(2N2NOX/83D3DX644B,$68T8T,!%79J9J!X X v,$68T8T,!%79J9J!;A;A|,"2H4P4P,!#3X5F5F!%C%CP,#4h6R6R,!$5x7H7H!L (">">L r