o b@sdZddlmZddlmZmZmZddlmZmZGddde Z GdddZ Gd d d e ej Z Gd d d e ejZGd ddZGdddeej ZGdddeejZGdddZGdddeej ZGdddeejZGdddej ZGdddejZGdddej Zedd Gd!d"d"ej ZGd#d$d$ejZGd%d&d&ejZGd'd(d(ejZGd)d*d*ejZd+d,Zd-S).a Definitions of test cases with various interesting error-related behaviors, to be used by test modules to exercise different features of trial's test runner. See the L{twisted.trial.test.test_tests} module docstring for details about how this code is arranged. )skipIf)deferprotocolreactor)unittestutilc@ eZdZdS) FoolishErrorN__name__ __module__ __qualname__rr>/usr/lib/python3/dist-packages/twisted/trial/test/erroneous.pyr r c@eZdZddZddZdS)FailureInSetUpMixincCtd)NzI am a broken setUp methodr selfrrrsetUpzFailureInSetUpMixin.setUpcCdSNrrrrr test_noopzFailureInSetUpMixin.test_noopN)r r r rrrrrrr rc@r)SynchronousTestFailureInSetUpNr rrrrr rrc@r)AsynchronousTestFailureInSetUpNr rrrrr$rrc@r)FailureInTearDownMixincCr)NzI am a broken tearDown methodrrrrrtearDown)rzFailureInTearDownMixin.tearDowncCrrrrrrrr,rz FailureInTearDownMixin.test_noopN)r r r r!rrrrrr (rr c@r) SynchronousTestFailureInTearDownNr rrrrr"0r"c@r)!AsynchronousTestFailureInTearDownNr rrrrr$6rr$c@s$eZdZdZdZddZddZdS)FailureButTearDownRunsMixinz7 A test fails, but its L{tearDown} still runs. FcCs d|_dSNT)tornDownrrrrr!A z$FailureButTearDownRunsMixin.tearDowncCr)z$ A test that fails. zI am a broken testrrrrr test_failsDz&FailureButTearDownRunsMixin.test_failsN)r r r __doc__r'r!r)rrrrr%:s  r%c@r)%SynchronousTestFailureButTearDownRunsNr rrrrr,Kr#r,c@r)&AsynchronousTestFailureButTearDownRunsNr rrrrr-Qr#r-c@$eZdZddZddZddZdS)TestRegularFailcC|ddS)NI failfailrrrr test_failXzTestRegularFail.test_failcCs |dSr) subroutinerrrr test_subfail[ zTestRegularFail.test_subfailcCr0)Nz I fail insider2rrrrr6^r5zTestRegularFail.subroutineN)r r r r4r7r6rrrrr/Ws r/c@s(eZdZdZddZddZddZdS) TestAsynchronousFailz? Test failures for L{unittest.TestCase} based classes. cCs(t}||jtd|jd|S)zW A test which fails in the callback of the returned L{defer.Deferred}. rN)rDeferred addCallback_laterr callLatercallbackrdrrrr4gs zTestAsynchronousFail.test_failcCr0)Nz I fail laterr2)rresrrrr<pr5zTestAsynchronousFail._latercCr)zA A test which raises an exception synchronously. r1) Exceptionrrrrtest_exceptionsr*z#TestAsynchronousFail.test_exceptionN)r r r r+r4r<rCrrrrr9bs  r9c@seZdZdZdZddZdS) ErrorTestz A test case which has a L{test_foo} which will raise an error. @ivar ran: boolean indicating whether L{test_foo} has been run. FcCsd|_dddS)zJ Set C{self.ran} to True and raise a C{ZeroDivisionError} TrN)ranrrrrtest_foos zErrorTest.test_fooN)r r r r+rFrGrrrrrDzs rDTzskipping this testc@r)TestSkipTestCaseNr rrrrrHsrHc@s2eZdZdZddZddZejdedge_dS) DelayedCallzsomething blew upcCs t|jr) RuntimeErrorhiddenExceptionMsgrrrrgor(zDelayedCall.gocCs&td|jtd|ddS)a What happens if an error is raised in a DelayedCall and an error is also raised in the test? L{test_reporter.ErrorReportingTests.testHiddenException} checks that both errors get reported. Note that this behaviour is deprecated. A B{real} test would return a Deferred that got triggered by the callLater. This would guarantee the delayed call error gets reported. rg{Gz?z/Deliberate failure to mask the hidden exceptionN)rr=rLiterater3rrrrtestHiddenExceptions zDelayedCall.testHiddenExceptionz!reactor\.iterate cannot be used.*)messagecategoryN) r r r rKrLrNrsuppressDeprecationWarningrrrrrIs rIc@eZdZddZdS)ReactorCleanupTestscCsdd}td|dS)NcSs tddS)Nzfoo!)printrrrr_r8z8ReactorCleanupTests.test_leftoverPendingCalls.._g@)rr=)rrVrrrtest_leftoverPendingCallssz-ReactorCleanupTests.test_leftoverPendingCallsN)r r r rWrrrrrT rTc@rS)SocketOpenTestcCs t}tj|_td|dS)Nr)rFactoryProtocolr listenTCP)rfrrrtest_socketsLeftOpensz#SocketOpenTest.test_socketsLeftOpenN)r r r r^rrrrrYrXrYc@r.)TimingOutDeferredcCrrrrrrr test_alpharzTimingOutDeferred.test_alphacCsd|_t}|Sr&) methodCalledrr:r?rrrtest_deferredThatNeverFiressz-TimingOutDeferred.test_deferredThatNeverFirescCrrrrrrr test_omegarzTimingOutDeferred.test_omegaN)r r r r`rbrcrrrrr_s r_cCsdS)zci will raise an unexpected exception... ... *CAUSE THAT'S THE KINDA GUY I AM* >>> 1/0 NrrrrrunexpectedExceptionsrdN)r+rrtwisted.internetrrr twisted.trialrrBr rSynchronousTestCaserTestCaserr r"r$r%r,r-r/r9rDrHrIrTrYr_rdrrrrs<