ϪfdZddlmZmZmZmZmZddlmZddl m Z ddl m Z ejZ ddlmZGddej ZGd d eZGd d e j(ZGd de j(ZGdde j(ZGdde j(ZGddZGdde j4ZGdde j4Zy)z% Tests for L{twisted.internet.task}. )defererror interfacesreactortask)installReactor) NoReactor)unittest)failureceZdZfdZxZS)TestableLoopingCallc2t||i|||_yN)super__init__clock)selfrakw __class__s 8/usr/lib/python3/dist-packages/twisted/test/test_task.pyrzTestableLoopingCall.__init__s !"r" )__name__ __module__ __qualname__r __classcell__)rs@rr r s rr c eZdZy) TestExceptionNrrrrrrrsrrcjeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZy) ClockTestsz< Test the non-wallclock based clock implementation. cltj}|j|jdy)zV Test that the C{seconds} method of the fake clock returns fake time. rN)rClock assertEqualsecondsrcs r testSecondszClockTests.testSeconds#s% JJL a(rc2tj}|jdddd}|jtj j ||j|jd|j|jy)z{ Test that calls can be scheduled for later with the fake clock and hands back an L{IDelayedCall}. cyrr rbs rz*ClockTests.testCallLater..0rr.N) rr$ callLater assertTruer IDelayedCall providedByr%getTimeactiverr(calls r testCallLaterzClockTests.testCallLater*sk JJL{{1/a{8  //::4@A +  &rctj}|jdddd}|j|j |j y)z3 Test that calls can be cancelled. r+cyrr r-s rr/z3ClockTests.testCallLaterCancelled..:r0rr1r2N)rr$r3cancel assertFalser8r9s rtestCallLaterCancelledz!ClockTests.testCallLaterCancelled5sC JJL{{1/a{8  'rctj}|jdddd}|jdddd}|j||uy ) z[ Test that the DelayedCall returned is not one previously created. cyrr r-s rr/z3ClockTests.test_callLaterOrdering..Dr0rr+r1r2cyrr r-s rr/z3ClockTests.test_callLaterOrdering..Er0rN)rr$r3r?)rr(call1call2s rtest_callLaterOrderingz!ClockTests.test_callLaterOrdering>sO JJL B 11 : A0!q 9 %(rc(gtj}|jdfd}|jd|j g|jd|j dg|j |j y)zE Test that advancing the clock will fire some calls. r1c&jdSrappend)eventssrr/z(ClockTests.testAdvance..NsfmmD&9rr+N)rr$r3advancer%r?r8rr(r:rNs @r testAdvancezClockTests.testAdvanceHsr JJL{{19: !  $ !  $( 'rctj}fd}|jd||jdy)a Test attempting to cancel the call in a callback. AlreadyCalled should be raised, not for example a ValueError from removing the call from Clock.calls. This requires call.called to be set before the callback is called. cZjtjjyr) assertRaisesr AlreadyCalledr>)r:rsrcbz(ClockTests.testAdvanceCancel..cb_s   e114;; ?rr+N)rr$r3rO)rr(rVr:s` @rtestAdvanceCancelzClockTests.testAdvanceCancelUs3 JJL @{{1b! ! rcRgtj}|jdfddd}|jd|j |j d|j d|j g|j d|j dgy) z1 Test that calls can be delayed. r+c*j||fSrrLrr.rNs rr/z1ClockTests.testCallLaterDelayed..k6==!Q+@rr1r2g??r+r1N)rr$r3delayr%r7rOrPs @rtestCallLaterDelayedzClockTests.testCallLaterDelayedes JJL{{1@!q{I 1  + # $ # &*rctgtj}|jdfddd}|jd|j d|j |j d|jd|j g|jd|j dgy) zL Test that calls can have their time reset to a later time. r1c*j||fSrrLrZs rr/z4ClockTests.testCallLaterResetLater..yr[rr+r2rErFr]N)rr$r3rOresetr%r7rPs @rtestCallLaterResetLaterz"ClockTests.testCallLaterResetLaterss JJL{{1@!q{I !  1  + !  $ !  &*rc gtj}|jdfddd}|jd|j |j d|j d|j dgy) zO Test that calls can have their time reset to an earlier time. rFc*j||fSrrLrZs rr/z5ClockTests.testCallLaterResetSooner..r[rr+r1r2rEr]N)rr$r3rbr%r7rOrPs @rtestCallLaterResetSoonerz#ClockTests.testCallLaterResetSoonersj JJL{{1@!q{I 1  + !  &*rctj}|jdd}|jdd}|j}|j ||ht |y)zB Test that we can get a list of all delayed calls r+cyrr xs rr/z1ClockTests.test_getDelayedCalls..r0rr1cyrr ris rr/z1ClockTests.test_getDelayedCalls..r0rN)rr$r3getDelayedCallsr%set)rr(r:rHcallss rtest_getDelayedCallszClockTests.test_getDelayedCallssU JJL{{1n- A~.!!# $E 3rcltj}|j|jgy)zk Test that we get an empty list from getDelayedCalls on a newly constructed Clock. N)rr$r%rlr's rtest_getDelayedCallsEmptyz$ClockTests.test_getDelayedCallsEmptys( JJL **,b1rctj}|jtjj |dy)Nz#Clock does not provide IReactorTime)rr$r4r IReactorTimer6r's rtest_providesIReactorTimez$ClockTests.test_providesIReactorTimes0 JJL   # # . .q 13X rcgddg}tjfd}jd|d}|jdjd|dj d gd z|j |y ) a4 The order of calls scheduled by L{task.Clock.callLater} is honored when adding a new call via calling L{task.Clock.callLater} again. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then the L{IDelayedCall} which results from that is C{reset} to a later time t2 which is greater than t0, and I{then} L{task.Clock.callLater} is invoked again with a callable "B", and time t1 which is less than t2 but greater than t0, "B" will be invoked before "A". r.@r@cFj|jfSrrMr&nrresults rr/z.FMM1emmo*>?rr\rryrwr.r+rENrr$r3rbpumpr%rexpectedlogtimecall_arr~s @@rtest_callLaterKeepsCallsOrderedz*ClockTests.test_callLaterKeepsCallsOrderedst + ?gs3 S Wc* A37 *rcgddg}tjfd}jd|d}jd|d|jdj d gd z|j |y ) a: The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}. For example, if L{task.Clock.callLater} is invoked with a callable "A" and a time t0, and then L{task.Clock.callLater} is invoked again with a callable "B", and time t1 greater than t0, and finally the L{IDelayedCall} for "A" is C{reset} to a later time, t2, which is greater than t1, "B" will be invoked before "A". rvrxcFj|jfSrr{r|s rr/zAClockTests.test_callLaterResetKeepsCallsOrdered..rrr\rrwr.ryr+rENrrs @@r$test_callLaterResetKeepsCallsOrderedz/ClockTests.test_callLaterResetKeepsCallsOrderedst + ?gs3 Wc* S A37 *rcgddg}tjfd}jd|dfd}jd|jd|d jd gd z|j |y ) a9 The order of calls scheduled by L{task.Clock.callLater} is honored when re-scheduling an existing call via L{IDelayedCall.reset} on the result of a previous call to C{callLater}, even when that call to C{reset} occurs within the callable scheduled by C{callLater} itself. )r(ry)r.g@cFj|jfSrr{r|s rr/zKClockTests.test_callLaterResetInsideCallKeepsCallsOrdered..rrrwr.c(jdy)Nry)rb)call_bsrrzDClockTests.test_callLaterResetInsideCallKeepsCallsOrdered..as LL rr\ryr(?rBN)rr$r3rr%)rrrrrrr~s @@@r.test_callLaterResetInsideCallKeepsCallsOrderedz9ClockTests.test_callLaterResetInsideCallKeepsCallsOrdereds} + ?gs3  Q Wc* C52: *rN)rrr__doc__r)r;r@rIrQrWr_rcrfrorqrtrrrr rrr"r"sR) '() ( + + + 42 +0+0+rr"ceZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZy) LoopTestsz[ Tests for L{task.LoopingCall} based on a fake L{IReactorTime} implementation. cptjd}|j|jty)zG L{LoopingCall}'s default clock should be the reactor. cyrr r rrr/z-LoopTests.test_defaultClock..r0rN)r LoopingCallr%rr)rr:s rtest_defaultClockzLoopTests.test_defaultClocks( - W-rcgdtjfd}tj|}|_d|j d|j dg|j j jd|j dgdjd|j ddg|j j djd|j ddgdjd|j gd |j j d y) z When more time than the defined interval passes during the execution of a callback, L{LoopingCall} should schedule the next call for the next interval which is still in the future. Ncfjjjyr)rMr&rO) callDurationrtimessr aCallbackz3LoopTests.test_callbackTimeSkips..aCallbacks! LL ) MM, 'rr1rrr+@g @)rrrFrF)rr$rrstartr%r&rO)rrr:rrrs @@@rtest_callbackTimeSkipsz LoopTests.test_callbackTimeSkipss.    ( *   3 $ ,7  a $  c C) #.  a C)  c  , !,rcgtjfd}tj|}|_|j d|j dgj d|j ddgj d|j gdj d|j gdy)a  When more time than the defined interval passes between when L{LoopingCall} schedules itself to run again and when it actually runs again, it should schedule the next call for the next interval which is still in the future. cDjjyrr{)rrsrrz2LoopTests.test_reactorTimeSkips..aCallback;s LL )rrrr1r+)rr1rEN)rr$rrrr%rO)rrr:rrs @@rtest_reactorTimeSkipszLoopTests.test_reactorTimeSkips1s  *  *  3 $  a A'  a  *  a  *rcgtjfd}tjj|}|_d}d}|j ||j dgj||z|j d||zdfgjd|z|z|j d||zdfd|zd|zzdfgjd |j d||zdfd|zd|zzdfgy ) a When L{LoopingCall} schedules itself to run again, if more than the specified interval has passed, it should schedule the next call for the next interval which is still in the future. If it was created using L{LoopingCall.withCount}, a positional argument will be inserted at the beginning of the argument list, indicating the number of calls that should have been made. cHjj|fyrr{)numCallsrrs rrz7LoopTests.test_reactorTimeCountSkips..aCallback_s LL%--/84 5rr{Gz?rr+r+rErFr1rN)rr$r withCountrrr%rOrrr:INTERVALREALISTIC_DELAYrrs @@rtest_reactorTimeCountSkipsz$LoopTests.test_reactorTimeCountSkipsSs2  6 )))4  8 )  h01 (_*Da)H IJ  q8|67  O+Q/h,1#67;    a  O+Q/h,1#67;  rcXgtjfd}tjj|}|_d}d}|j ||j jdj||z|j j||zdfj|dz|j jd|z|zdfj|dz|j jd |z|zdfy ) a1 L{LoopingCall.withCount} counts only calls that were expected to be made. So, if more than one, but less than two intervals pass between invocations, it won't increase the count above 1. For example, a L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc. However, the reactor takes some time to get around to calling it, so in practice it will be called at T+something, 2T+something, 3T+something; and due to other things going on in the reactor, "something" is variable. It won't increase the count unless "something" is greater than T. So if the L{LoopingCall} is invoked at T, 2.75T, and 3T, the count has not increased, even though the distance between invocation 1 and invocation 2 is 1.75T. cHjj|fyrr{)countrrs rrz.aCallbacks LL%--/51 2rrrrr+g?g@g?ryN) rr$rrrrr%poprOrs @@rtest_countLengthyIntervalCountsz)LoopTests.test_countLengthyIntervalCountss  3 )))4  8 f-  h01 x/'A1&EF  ho& x?'JA&NO  ho& h/'I1&MNrc:tj}g}tjj|j}||_d}d}||z }|j |dt|D]}|j|d}|||g|zz } |j| |j} |jt| dkD| d|j| |k\| d||j||||jd |y ) a L{task.LoopingCall.withCount} should never invoke its callable with a zero. Specifically, if a L{task.LoopingCall} created with C{withCount} has its L{start } method invoked with a floating-point number which introduces decimal inaccuracy when multiplied or divided, such as "0.1", L{task.LoopingCall} will never invoke its callable with 0. Also, the sum of all the values passed to its callable as the "count" will be an integer, the number of intervals that have elapsed. This is a regression test for a particularly tricky case to implement. rBr\Fnowc"d}|D]}||z } |S)z Make sure the result is more precise. On Python 3.11 or older this can be a float with ~ 0.00001 in precision difference. See: https://github.com/python/cpython/issues/100425 r )itemstotalitems r sum_compatzALoopTests.test_withCountFloatingPointBoundary..sum_compats&E   Lrrz should be greater than zeroz$ should be greater than or equal to rN)rr$rrrMrrrangerOr&r4absr% assertNotIn) rr accumulatorr:rtimespanintervalrjrepsilon secondsValues r#test_withCountFloatingPointBoundaryz-LoopTests.test_withCountFloatingPointBoundarys  ))+*<*<= e# 8 'u $A MM( # $ Z U(:;; g}} G s*wi7S,TU  H $n@ K K0%8 K(rc*tj}gfd}tjj||_j dd}|j dgdz|j||jdgdzy)zy L{task.LoopingCall.withCount} with interval set to 0 calls the countCallable with a count of 1. cfj|tdkDrjyy)NrFrMlenstop)cntrloops rfooz1LoopTests.test_withCountIntervalZero..foos,   s #;!# $rrFrr+N) rr$rrrrrsuccessResultOfr%)rrrdeferredrrs @@rtest_withCountIntervalZeroz$LoopTests.test_withCountIntervalZeros     ))#. ::aU:+  A37 X& !q+.rctj}tjgfd}tjj ||_jdd|jdgdz|jdgdz|jdgdz|jdgdzjd|jdgdz|jdgd zy) z L{task.LoopingCall.withCount} with interval set to 0 and a delayed call during the loop run will still call the countCallable 1 as if no delay occurred. cj|tdk(rStdkDrjyy)Nr1rFr)rrrrs rrz6LoopTests.test_withCountIntervalZeroDelay..foos>   s #;1$;!# $rrFrr1r+NrFr) rr$rDeferredrrrrrr%callback)rrrrrrs @@@rtest_withCountIntervalZeroDelayz)LoopTests.test_withCountIntervalZeroDelays  >>#  ))#.  1%   A37 !q+.  A37 !q+. $ A37 !q+.rc tj}tj g d d}d}d}||z}||z}|dz } fd}tjj |}||_|jdd|jdg |zz|jdg z ||_ jd |j||jdd|g |jd|z|jdd|dg |jd|z|jdd|ddg y ) z L{task.LoopingCall.withCount} with interval set to 0 will still keep the time when last called so when the interval is reset. r1r r+cHj|tk(rSyrrMr)rrrstepsBeforeDelays rrzILoopTests.test_withCountIntervalZeroDelayThenNonZeroInterval..foobs)   s #;#334rrFrN) rr$rrrrrrrr%rrrO) rrextraTimeAfterDelaymutatedLoopIntervaldurationOfDelay skippedTimeexpectedSkipCountrrrrrs @@@r2test_withCountIntervalZeroDelayThenNonZeroIntervalz>#     *O; (+>> Q ))#.  1%   A3*-@@AB !//=, $ o& !Q 12K@ a--. !Q 115{C a--. !Q 11a8+FrcT gd}tj}g d fd }t||ddd}|jd}g fd}|j ||j ||j t d d t fz D]N\}}} } |j |d|j |d|j| |j | dP|j|j d ||j|jy) Ng?皙?rc0j||||fyrrL)rr.r(dLs rrz(LoopTests.testBasicFunction..foos HHaAq\ "rrr.rrrc(j|yrrLr~ theResults r saveResultz/LoopTests.testBasicFunction..saveResult   V $rrEzgot %d iterations, not 3r)NN) rr$r r addCallbackrr%r assertIsNonerassertIsr?rn) rtimingsrrlcDrrr.r(rrrs @@rtestBasicFunctionzLoopTests.testBasicFunctions  #   #!S# = HHSM  % j! 7 Q$>#a&$JK %JAq!Q   Q $   Q $   a   Q $  %   ilB' %rcgd}tj}g}t||jd}|j dd}gfd}|j ||j ||jt|ddt|fz|j|jd||j|jy) NrrFrc(j|yrrLrs rrz.LoopTests.testDelayedStart..saveResultrrr1zgot %d iterations, not 2r) rr$r rMrrrr%rrrr?rn)rrrrrrrrs @rtestDelayedStartzLoopTests.testDelayedStarts"   $ 7 HHSeH $  % j! 7 Q$>#a&$JK   ilB' %rcrtjd}|jt|jdy)Ncyrr r rrr/z(LoopTests.testBadDelay..r0r)rrrT ValueErrorr)rrs r testBadDelayzLoopTests.testBadDelays(   l + *bhh3rcgfd}tj}t||}|j|d|j |j |j |j y)Nc(jdyrrLransrrz$LoopTests._stoppingTest..foo JJt rFr)rr$r rrr?rn)rr^rrrrs @r _stoppingTestzLoopTests._stoppingTests_    , E"    %rc$|jdS)Nrrrs rtestStopAtOncezLoopTests.testStopAtOnces!!!$$rc$|jdS)NrBrrs rtestStoppingBeforeDelayedStartz(LoopTests.testStoppingBeforeDelayedStarts!!"%%rcJgfd}tj}t||}|jdd|j d|j |j d|j g|j d|j dgy)z8 Test that L{LoopingCall} can be reset. c(jdyrrLrsrrz!LoopTests.test_reset..foorrr1Frr+N)rr$r rrOrbr%)rrr(rrs @r test_resetzLoopTests.test_resets  JJL C (  !    !  b! !  tf%rc n|jttjtdddy)zO L{LoopingCall.__repr__} includes the wrapped function's name. r+r1)keyz6LoopingCall(installReactor, *(1,), **{'key': 2})N)r%reprrrrrs rtest_reprFunctionzLoopTests.test_reprFunctions,  !!.!; < D rc||jttjtj dy)zR L{LoopingCall.__repr__} includes the wrapped method's full name. z:LoopingCall(TestableLoopingCall.__init__, *(), **{})N)r%r rrr rrs rtest_reprMethodzLoopTests.test_reprMethods/  !!"5">">? @ H rc"tjd}|jd}|j|jg}|j dt ||j t|dd|j ||ddy)z8 L{LoopingCall.deferred} is deprecated. cyrr r rrr/z4LoopTests.test_deferredDeprecation..r0rztwisted.internet.task.LoopingCall.deferred was deprecated in Twisted 16.0.0; please use the deferred returned by start() insteadr+rcategorymessageN)rrr flushWarningstest_deferredDeprecationr%rDeprecationWarning)rrrwarningss rrz"LoopTests.test_deferredDeprecations -  B  %%t'D'D&EF CM* +Xa[-DE (1+i"89rN)rrrrrrrrrrrrrrrrrrrrr rrr rrrrsr .2-h +D8 t'OR@)D/4$/LGGR&&P&04 &%&&&  :rrc<eZdZdZdZdZdZdZdZdZ dZ y ) ReactorLoopTestsc~d}tj|d}|j|jdtS)Nct|rrris rrz)ReactorLoopTests.testFailure..foos " "rbarrrr assertFailurerrrrrs r testFailurezReactorLoopTests.testFailures6 #  c5 )!!"((3-??rcfd}tj|d|jjdtS)Nc:jt|r)rr)rjrs rrz-ReactorLoopTests.testFailAndStop..foos GGI" "rrrrrs @rtestFailAndStopz ReactorLoopTests.testFailAndStops7 #  c5 )!!"((3-??rcgfd}tj|jd}fd}|j|S)NcfjdtdkDrjyy)Nrr)rrsrrz0ReactorLoopTests.testEveryIteration..foo&s( JJt 3x!| rrc<jtdy)N)r%r)ignrrs rstoppedz4ReactorLoopTests.testEveryIteration..stopped.s   SXq )r)rrrr)rrrr)rrs` @@rtestEveryIterationz#ReactorLoopTests.testEveryIteration#sB    c " HHQK *}}W%%rctjfd}tj||_|jj ddt jd|jS)NcNjtjdy)Nz'This task also should never get called.)errbackr DefaultExceptionrsrrz1ReactorLoopTests.testStopAtOnceLater..foo8s II(()RS rr+Frr) rrrr_lcrrr3!_callback_for_testStopAtOnceLater)rrrs @rtestStopAtOnceLaterz$ReactorLoopTests.testStopAtOnceLater3s[ NN   ##C( qe$!TCCQGrcz|jjtjd|jdy)Nrsuccess)r/rrr3r)rrs rr0z2ReactorLoopTests._callback_for_testStopAtOnceLaterBs%  !QZZ3rcddg}tjfd}t|jdj ||j j y)N皙?g?ctj}|jfdjd|jd|S)Nc$jSr)r)_rs rr/z@ReactorLoopTests.testWaitDeferred..foo..Ns BGGIrr+)rrrr3r)rrrs rrz.ReactorLoopTests.testWaitDeferred..fooLs5 A MM- . OOAqzz4 0Hr)rr$r rrr?rn)rrrrrs @@rtestWaitDeferredz!ReactorLoopTests.testWaitDeferredFsU*   ! ,   7 %rcdg}tjfd}t|}|jd}|j |t j ||jj|S)N333333?cztj}jd|jt |S)Nr;)rrr3r-r)rrs rrz4ReactorLoopTests.testFailurePropagation..fooas* A OOCMO <Hrr+) rr$r rrrrr?rn)rrrrrrs @rtestFailurePropagationz'ReactorLoopTests.testFailurePropagationWsj%   ! , HHQK 1m, 7 %rctj}tjgfd}tjj |}||_|jdd|jg|jddg|jtdjd|jdg|jtd|jdd gy) a? In the case that the function passed to L{LoopingCall.withCount} returns a deferred, which does not fire before the next interval elapses, the function should not be run again. And if a function call is skipped in this fashion, the appropriate count should be provided. cHj|tdk(rSyNr+r) possibleCountrdeferredCountss r countTrackerz=ReactorLoopTests.test_deferredWithCount..countTrackerzs&  ! !- 0>"a'rr5Frg?r+Nr1rE) rr$rrrrrrr%rrr)r testClockrCrrrBs @@rtest_deferredWithCountz'ReactorLoopTests.test_deferredWithCountnsJJL NN     ' ' 5 HHSeH $ , Sz" ^,a0 4u ^,a0 !Q0rN) rrrr r#r*r1r0r9r=rEr rrrrs,@@& 4&".*1rrc(eZdZdZdZdZdZdZy)DeferLaterTestsz' Tests for L{task.deferLater}. cPgtfd}tj}tj|d|dd}|j |j |j d|jg|j d|jdg|S) z The L{Deferred} returned by L{task.deferLater} is called back after the specified delay with the result of the function passed in. c.j||fSrrL)rrflagresultss rcallablez/DeferLaterTests.test_callback..callables NNC: &KrrErr)rr1r+)rr)objectrr$ deferLaterrrrOr%)rrLrrrJrKs @@r test_callbackzDeferLaterTests.test_callbacks x   OOE1h5 A dmmT* a "% a >"23rcd}tj}tj|d|}|jd|j |t S)z The L{Deferred} returned by L{task.deferLater} is errbacked if the supplied function raises an exception. ctrrr rrrLz.DeferLaterTests.test_errback..callables / !rr+)rr$rNrOrr)rrLrrs r test_errbackzDeferLaterTests.test_errbacksE  "  OOE1h / a!!!]33rc gtjtjdjd}|j fd}j |t j|j||S)z The L{Deferred} returned by L{task.deferLater} can be cancelled to prevent the call from actually being performed. r+Nchjgjjyr)r%rlr?)ignoredcalledrrs r cbCancelledz0DeferLaterTests.test_cancel..cbCancelleds*   R!6!6!8 9   V $r) rr$rNrMr>rrCancelledErrorr)rrrWrVrs` @@r test_cancelzDeferLaterTests.test_cancelsd   OOE1fmmT :   % 1e223 k"rctj}tj|d}|j||j d|j d|j |y)z The L{Deferred} returned by L{task.deferLater} fires with C{None} when no callback function is passed. rwN)rr$rNassertNoResultrOrr)rrrs rtest_noCallbackzDeferLaterTests.test_noCallbacksR   OOE3 ' A c dD0034rN)rrrrrOrRrYr\r rrrGrGs* 4( 5rrGc*eZdZdZdZdZdZdZy) _FakeReactorcd|_tj|_|jj|_|jj |_|jj |_g|_ggd|_y)NFbeforeduring) _runningrr$_clockr3r&rl _whenRunning_shutdownTriggersrs rrz_FakeReactor.__init__s_ jjl ..{{** #{{::,."!=rcj|j ||i|y|jj|||fyr)rerM)rrLargskwargss rcallWhenRunningz_FakeReactor.callWhenRunnings6    $ d %f %    $ $hf%= >rc^|dvsJ|dk(sJ|j|j||fy)Nr`shutdown)rfrM)rphaseeventrLrhs raddSystemEventTriggerz"_FakeReactor.addSystemEventTriggers=,,,, """ u%,,h-=>rcd|_|j}d|_|D]\}}}||i||jrg|j}|s td|jj |dj |jz |jrg|j}d|_|d|dzD] \}}|| y)z Call timed events until there are no more or the reactor is stopped. @raise RuntimeError: When no timed events are left and the reactor is still running. TNzNo DelayedCalls leftrrarb) rcrerl RuntimeErrorrdrOr7r&rf)r whenRunningrLrhrirnshutdownTriggerstriggers rrunz_FakeReactor.runs ''  &1 & "HdF d %f % &mm((*E"#9:: KK  a 0 0 2T\\^ C D mm  11!%-h7:J8:TT MGT TN rcR|jstjd|_y)z# Stop the reactor. FN)rcrReactorNotRunningrs rrz_FakeReactor.stops!}}))+ + rN)rrrrrjrorurr rrr^r^s>? ? ,rr^cReZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy ) ReactTestsz3 Tests for L{twisted.internet.task.react}. cgfd}t}|jttj||}|j d|j |j dg|j |jdy) L{task.react} runs the reactor until the L{Deferred} returned by the function it is passed is called back, then stops it. ctj}|jdjd|jd|jd|SNr+Tr1rrr3rMrrfinished timePasseds rmainz4ReactTests.test_runsUntilAsyncCallback..main$sH~~'H G  a!2!2D 9 G  a!2!2D 9Or_reactorrTr1Nr^rT SystemExitrreactr%coder&rrr exitErrorrs @rtest_runsUntilAsyncCallbackz&ReactTests.test_runsUntilAsyncCallbacksq    N%%j$**dQ%O  INN+ dV, a(rcd}t}|jttj||}|j d|j |j |jdy) L{task.react} returns quickly if the L{Deferred} returned by the function it is passed has already been called back at the time it is returned. c,tjdSrrsucceedrs rrz3ReactTests.test_runsUntilSyncCallback..main7s==& &rrrNrrrrrs rtest_runsUntilSyncCallbackz%ReactTests.test_runsUntilSyncCallback0sW ' N%%j$**dQ%O  INN+ a(rc Gddtfd}t}|jttj ||}|j d|j|j}|j t|dy) L{task.react} runs the reactor until the L{defer.Deferred} returned by the function it is passed is errbacked, then it stops the reactor and reports the error. c eZdZy)@ReactTests.test_runsUntilAsyncErrback..ExpectedExceptionNrr rrExpectedExceptionrF rrcvtj}|jd|j|Sr@rrr3r-rrrs rrz3ReactTests.test_runsUntilAsyncErrback..mainIs2~~'H G  a!1!13D3F GOrrr+N Exceptionr^rTrrrr%rflushLoggedErrorsrrrrrerrorsrs @rtest_runsUntilAsyncErrbackz%ReactTests.test_runsUntilAsyncErrback?ss     N%%j$**dQ%O  INN+''(9: Va(rc`Gddtfd}t}|jttj ||}|j d|j|j |jd|j}|j t|dy) L{task.react} returns quickly if the L{defer.Deferred} returned by the function it is passed has already been errbacked at the time it is returned. c eZdZy)?ReactTests.test_runsUntilSyncErrback..ExpectedExceptionNrr rrrr]rrrc8tjSrrfailrrs rrz2ReactTests.test_runsUntilSyncErrback..main`s::/12 2rrr+rN rr^rTrrrr%rr&rrrs @rtest_runsUntilSyncErrbackz$ReactTests.test_runsUntilSyncErrbackVs    3 N%%j$**dQ%O  INN+ a(''(9: Va(rcd}t}|jttj||}|j |j d|j d|jy) L{task.react} doesn't try to stop the reactor if the L{defer.Deferred} the function it is passed is called back after the reactor has already been stopped. c|jd|jtj}|jdd|j d|SNr+rbrlr3rrrrorrrs rrz0ReactTests.test_singleStopCallback..mainqsF G  a .~~'H )G ) )(J@Q@QSW XOrrr+rNr^rTrrrr%r&rrs rtest_singleStopCallbackz"ReactTests.test_singleStopCallbackjsW  N%%j$**dQ%O  a( INN+rc`Gddtfd}t}|jttj ||}|j d|j|j |jd|j}|j t|dy) L{task.react} doesn't try to stop the reactor if the L{defer.Deferred} the function it is passed is errbacked after the reactor has already been stopped. c eZdZy).ExpectedExceptionNrr rrrrrrrc|jd|jtj}|jdd|j |Srr3rrrror-rs rrz/ReactTests.test_singleStopErrback..mainsO G  a .~~'H )G ) )*h&6&68I8K Orrr+Nrrs @rtest_singleStopErrbackz!ReactTests.test_singleStopErrback}s     N%%j$**dQ%O  INN+ a(''(9: Va(rcgfd}t}|jttj|gd|}|j d|j |j gdy) L{task.react} passes the elements of the list it is passed as positional arguments to the function it is passed. cVj|||ftjdSrextendrrrrjyzrhs rrz'ReactTests.test_arguments..mains$ KKAq "==& &rr+r1rErrNr^rTrrrr%rrrrrrhs @rtest_argumentszReactTests.test_argumentssb  ' N%%  D)a&  INN+ y)rc4fd}t}t5t|jtt j |g}jd|jdddj|jy#1swY&xYw)p L{twisted.internet.reactor} is used if no reactor argument is passed to L{task.react}. c<|_tjdSr passedReactorrrrrs rrz,ReactTests.test_defaultReactor..mains!(D ==& &rrN r^r rrTrrrr%rrrrrrrs` rtest_defaultReactorzReactTests.test_defaultReactorsw  '. [ 0 7 #))*djj$KI   Q  / 0 gt112  0 0 ABBcd}t}|jttj|g|}|j d|j y) L{task.react} forwards the exit code specified by the C{SystemExit} error returned by the passed function, if any. c>tjtdSNrrrrs rrz1ReactTests.test_exitWithDefinedCode..mains::jn- -rrrNrrs rtest_exitWithDefinedCodez#ReactTests.test_exitWithDefinedCodesD  . N%%j$**dBQR%S  Y^^,rcd}t}|jttj|g|}|j d|j y)w L{task.react} handles when the reactor is stopped just before the returned L{Deferred} fires. cbtjfd}j|S)NcJjjdyrrrrrsrrz;ReactTests.test_synchronousStop..main..stop  4 rrrrjrrrs` @rrz-ReactTests.test_synchronousStop..mains+ A ! $G # #D )HrrrNrrs rtest_synchronousStopzReactTests.test_synchronousStopsD   N%%j$**dBQR%S  INN+rcd}t}|jttj|g|}|j d|j y)v L{task.react} handles when the reactor is stopped and the returned L{Deferred} doesn't fire. cd|jd|jtjSr@r3rrrrs rrz.ReactTests.test_asynchronousStop..mains% G  a .>># #rrrNrrs rtest_asynchronousStopz ReactTests.test_asynchronousStopsD  $ N%%j$**dBQR%S  INN+rNrrrrrrrrrrrrrrrr rrryry>)& )).)(,&)6*$3" -,( ,rrycReZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy )ReactCoroutineFunctionTestszP Tests for L{twisted.internet.task.react} with an C{async def} argument cgfd}t}|jttj||}|j d|j |j dg|j |jdy)r{cKtj}|jdjd|jd|jd|d{S7wr}r~rs rrzEReactCoroutineFunctionTests.test_runsUntilAsyncCallback..mainsQ~~'H G  a!2!2D 9 G  a!2!2D 9!> !>sAA AA rrTr1Nrrs @rrz7ReactCoroutineFunctionTests.test_runsUntilAsyncCallbacksq   " N%%j$**dQ%O  INN+ dV, a(rcd}t}|jttj||}|j d|j |j |jdy)rcHKtjdd{S7wrrrs rrzDReactCoroutineFunctionTests.test_runsUntilSyncCallback..main st,, ,,s " "rrNrrs rrz6ReactCoroutineFunctionTests.test_runsUntilSyncCallbacksW - N%%j$**dQ%O  INN+ a(rc Gddtfd}t}|jttj ||}|j d|j|j}|j t|dy)rc eZdZy)QReactCoroutineFunctionTests.test_runsUntilAsyncErrback..ExpectedExceptionNrr rrrrrrrcKtj}|jd|j|d{S7wr@rrs rrzDReactCoroutineFunctionTests.test_runsUntilAsyncErrback..mains;~~'H G  a!1!13D3F G!> !>s=AAArr+Nrrs @rrz6ReactCoroutineFunctionTests.test_runsUntilAsyncErrbackss    " N%%j$**dQ%O  INN+''(9: Va(rc`Gddtfd}t}|jttj ||}|j d|j|j |jd|j}|j t|dy)rc eZdZy)PReactCoroutineFunctionTests.test_runsUntilSyncErrback..ExpectedExceptionNrr rrrr0rrrcTKtjd{S7wrrrs rrzCReactCoroutineFunctionTests.test_runsUntilSyncErrback..main3s $5$788 88s (&(rr+rNrrs @rrz5ReactCoroutineFunctionTests.test_runsUntilSyncErrback)s    9 N%%j$**dQ%O  INN+ a(''(9: Va(rcd}t}|jttj||}|j |j d|j d|jy)rcK|jd|jtj}|jdd|j d|d{S7wrrrs rrzAReactCoroutineFunctionTests.test_singleStopCallback..mainDsO G  a .~~'H )G ) )(J@Q@QSW X!> !>sAAAArr+rNrrs rrz3ReactCoroutineFunctionTests.test_singleStopCallback=sW " N%%j$**dQ%O  a( INN+rc`Gddtfd}t}|jttj ||}|j d|j|j |jd|j}|j t|dy)rc eZdZy)MReactCoroutineFunctionTests.test_singleStopErrback..ExpectedExceptionNrr rrrrWrrrcK|jd|jtj}|jdd|j |d{S7wrrrs rrz@ReactCoroutineFunctionTests.test_singleStopErrback..mainZsX G  a .~~'H )G ) )*h&6&68I8K "> !>sAA%A#A%rr+Nrrs @rrz2ReactCoroutineFunctionTests.test_singleStopErrbackPs    " N%%j$**dQ%O  INN+ a(''(9: Va(rcgfd}t}|jttj|gd|}|j d|j |j gdy)rcrKj|||ftjdd{S7wrrrs rrz8ReactCoroutineFunctionTests.test_arguments..mainrs. KKAq "t,, ,,s -757rrrNrrs @rrz*ReactCoroutineFunctionTests.test_argumentsksb  - N%%  D)a&  INN+ y)rc4fd}t}t5t|jtt j |g}jd|jdddj|jy#1swY&xYw)rcXK|_tjdd{S7wrrrs rrz=ReactCoroutineFunctionTests.test_defaultReactor..mains$!(D t,, ,,s *(*rNrrs` rrz/ReactCoroutineFunctionTests.test_defaultReactor}sw  -. [ 0 7 #))*djj$KI   Q  / 0 gt112  0 0rcd}t}|jttj|g|}|j d|j y)rcZKtjtdd{S7wrrrs rrzBReactCoroutineFunctionTests.test_exitWithDefinedCode..mainsJrN33 33s "+)+rrNrrs rrz4ReactCoroutineFunctionTests.test_exitWithDefinedCodesD  4 N%%j$**dBQR%S  Y^^,rcd}t}|jttj|g|}|j d|j y)rc~Ktjfd}j|d{S7w)NcJjjdyrrrsrrzLReactCoroutineFunctionTests.test_synchronousStop..main..stoprrrrs` @rrz>ReactCoroutineFunctionTests.test_synchronousStop..mains3 A ! $G # #D )7N7s 2=;=rrNrrs rrz0ReactCoroutineFunctionTests.test_synchronousStopsD   N%%j$**dBQR%S  INN+rcd}t}|jttj|g|}|j d|j y)rcK|jd|jtjd{S7wr@rrs rrz?ReactCoroutineFunctionTests.test_asynchronousStop..mains/ G  a .)) ))s 5><>rrNrrs rrz1ReactCoroutineFunctionTests.test_asynchronousStopsD  * N%%j$**dBQR%S  INN+rNrr rrrrrrrN)rtwisted.internetrrrrrtwisted.internet.mainr#twisted.internet.test.modulehelpersr twisted.trialr r$twisted.pythonr rr rrTestCaser"rrrGr^SynchronousTestCaseryrr rrrs ED09" "$**  I O+""O+d^:!!^:BG1x((G1TF5h''F5R11hP,--P,fP,(">">P,r