ϪfLdZddlmZddlmZmZmZddlmZddl mZm Z Gdde Z Gdd e Z Gd d ZGd d eejZGddeej"ZGddZGddeejZGddeej"ZGddZGddeejZGddeej"ZGddejZGddej"ZGd d!ejZed"d#Gd$d%ejZGd&d'ej"ZGd(d)ej"ZGd*d+ej"ZGd,d-ej"Z d.Z!Gd/d0ejZ"y1)2aJ 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. Some of these tests are also used by L{twisted.trial._dist.test}. )skipIf)deferprotocolreactor) deferLater)unittestutilc eZdZy) FoolishErrorN__name__ __module__ __qualname__>/usr/lib/python3/dist-packages/twisted/trial/test/erroneous.pyr r rr c&eZdZdZdeddfdZdZy) LargeErrorzj An exception which has a string representation of at least a specified number of characters. minSizereturnNc<tj|||_yN) Exception__init__r)selfrs rrzLargeError.__init__!s4  rc,d|jz}d|dS)NxzLargeError)r)rlarges r__str__zLargeError.__str__%sdll"$UG1--r)r rr__doc__intrr!rrrrrs .rrceZdZdZdZy)FailureInSetUpMixinctd)NzI am a broken setUp methodr rs rsetUpzFailureInSetUpMixin.setUp+s788rcyrrr(s r test_noopzFailureInSetUpMixin.test_noop. rN)r rrr)r+rrrr%r%*s 9 rr%c eZdZy)SynchronousTestFailureInSetUpNr rrrr.r.2rrr.c eZdZy)AsynchronousTestFailureInSetUpNr rrrr0r06rrr0ceZdZdZdZy)FailureInTearDownMixinctd)NzI am a broken tearDown methodr'r(s rtearDownzFailureInTearDownMixin.tearDown;s:;;rcyrrr(s rr+z FailureInTearDownMixin.test_noop>r,rN)r rrr4r+rrrr2r2:s < rr2c eZdZy) SynchronousTestFailureInTearDownNr rrrr7r7B rr7c eZdZy)!AsynchronousTestFailureInTearDownNr rrrr:r:Hrrr:c eZdZdZdZdZdZy)FailureButTearDownRunsMixinz7 A test fails, but its L{tearDown} still runs. Fcd|_yNT)tornDownr(s rr4z$FailureButTearDownRunsMixin.tearDownSs  rctd)z$ A test that fails. zI am a broken testr'r(s r test_failsz&FailureButTearDownRunsMixin.test_failsVs/00rN)r rrr"r?r4rArrrr<r<LsH1rr<c eZdZy)%SynchronousTestFailureButTearDownRunsNr rrrrCrC]r8rrCc eZdZy)&AsynchronousTestFailureButTearDownRunsNr rrrrErEcr8rrEceZdZdZdZdZy)TestRegularFailc&|jdy)NI failfailr(s r test_failzTestRegularFail.test_failjs (rc$|jyr) subroutiner(s r test_subfailzTestRegularFail.test_subfailms  rc&|jdy)Nz I fail insiderJr(s rrNzTestRegularFail.subroutineps /"rN)r rrrLrOrNrrrrGrGis#rrGcxeZdZdZdZdej dfdZdej dfdZd dZ d dZ d d Z y) TestAsynchronousFailz? Test failures for L{unittest.TestCase} based classes. rIrNc:ttd|jdS)zW A test which fails in the callback of the returned L{defer.Deferred}. rz I fail laterrrrKr(s rrLzTestAsynchronousFail.test_fail{s'1dii@@rcFttd|jdddzzS)zw A test which fails in the callback of the returned L{defer.Deferred} with a very long string. rzI fail later: rrTr(s rtest_failGreaterThan64kz,TestAsynchronousFail.test_failGreaterThan64ks# '1dii1AC%K1OPPrc,t|j)zA A test which raises an exception synchronously. )rtextr(s rtest_exceptionz#TestAsynchronousFail.test_exceptions ""rctd)zk A test which raises an exception with a long string representation synchronously. rV)rr(s rtest_exceptionGreaterThan64kz1TestAsynchronousFail.test_exceptionGreaterThan64ks rctddz)z A test which synchronously raises an exception with a long string representation including non-ascii content. u☃i)rr(s r#test_exceptionGreaterThan64kEncodedz8TestAsynchronousFail.test_exceptionGreaterThan64kEncodeds -..r)rN) r rrr"rYrDeferredrLrWrZr\r^rrrrRrRtsK DA5>>$/A Q)=Q#   /rrRceZdZdZdZdZy) 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. Fcd|_ddz y)zJ Set C{self.ran} to True and raise a C{ZeroDivisionError} TrN)ranr(s rtest_foozErrorTest.test_foos ArN)r rrr"rdrerrrraras CrraTzskipping this testc eZdZy)TestSkipTestCaseNr rrrrgrgsrrgcPeZdZdZdZdZejdege_y) DelayedCallzsomething blew upc,t|jr) RuntimeErrorhiddenExceptionMsgr(s rgozDelayedCall.gos42233rctjd|jtjd|j dy)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)r callLaterrmiteraterKr(s rtestHiddenExceptionzDelayedCall.testHiddenExceptions1 !TWW% CDrz!reactor\.iterate cannot be used.*)messagecategoryN) r rrrlrmrqr suppressDeprecationWarningrrrriris4,4E"  8CU $ rriceZdZdZy)ReactorCleanupTestsc6d}tjd|y)Nctdy)Nzfoo!)printrrr_z8ReactorCleanupTests.test_leftoverPendingCalls.._s &Mrg@)rro)rr{s rtest_leftoverPendingCallsz-ReactorCleanupTests.test_leftoverPendingCallss  '1%rN)r rrr|rrrrwrws&rrwceZdZdZy)SocketOpenTestctj}tj|_tjd|y)Nr)rFactoryProtocolr listenTCP)rfs rtest_socketsLeftOpenz#SocketOpenTest.test_socketsLeftOpens-    && !QrN)r rrrrrrr~r~s rr~ceZdZdZdZdZy)TimingOutDeferredcyrrr(s r test_alphazTimingOutDeferred.test_alphar,rc<d|_tj}|Sr>) methodCalledrr_)rds rtest_deferredThatNeverFiresz-TimingOutDeferred.test_deferredThatNeverFiress  NN rcyrrr(s r test_omegazTimingOutDeferred.test_omegar,rN)r rrrrrrrrrrs   rrcy)zci will raise an unexpected exception... ... *CAUSE THAT'S THE KINDA GUY I AM* >>> 1/0 Nrr(s runexpectedExceptionrsrc&eZdZUdZdZeed<dZy)EventuallyFailingTestCasez> A test suite that fails after it is run a few times. rncp|xjdz c_|jdk\r|jdyy)zK Run successfully a few times and then fail forever after. rczeventually failingN)rrKr(s rtest_itz!EventuallyFailingTestCase.test_its. !  66Q; II* + rN)r rrr"rr#__annotations__rrrrrrsAsJ,rrN)#r"rrtwisted.internetrrrtwisted.internet.taskr twisted.trialr rr rr%SynchronousTestCaser.TestCaser0r2r7r:r<rCrErGrRrargrirwr~rrrrrrrs 55,( 9  . .   $79U9U  %8(:K:K    H88  (>@Q@Q 11" !=!=  !2!2 #h22#*/8,,*/Z,,""# x33 $ (##:&(++& X&&   ))   , < < ,r