
    h                        S r SSKJrJrJrJrJr  SSKJr  SSK	J
r
  SSKJr  \R                  rSSKJr   " S S\R                   5      r " S	 S
\5      r " S S\R(                  5      r " S S\R(                  5      r " S S\R(                  5      r " S S\R(                  5      r " S S5      r " S S\R4                  5      r " S S\R4                  5      rg)z%
Tests for L{twisted.internet.task}.
    )defererror
interfacesreactortask)installReactor)	NoReactor)unittest)failurec                   (   ^  \ rS rSrU 4S jrSrU =r$ )TestableLoopingCall   c                 2   > [         TU ]  " U0 UD6  Xl        g N)super__init__clock)selfr   akw	__class__s       ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_task.pyr   TestableLoopingCall.__init__   s    !"r"
    )r   )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r   r      s     r   r   c                       \ rS rSrSrg)TestException    Nr   r   r   r   r   r$   r   r   r"   r"      s    r   r"   c                   r    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrg)
ClockTests   z4
Test the non-wallclock based clock implementation.
c                 n    [         R                  " 5       nU R                  UR                  5       S5        g)zF
Test that the C{seconds} method of the fake clock returns fake time.
r   N)r   ClockassertEqualsecondsr   cs     r   testSecondsClockTests.testSeconds#   s%     JJLa(r   c                 .   [         R                  " 5       nUR                  SS SSS9nU R                  [        R
                  R                  U5      5        U R                  UR                  5       S5        U R                  UR                  5       5        g)zc
Test that calls can be scheduled for later with the fake clock and
hands back an L{IDelayedCall}.
   c                     g r   r$   r   bs     r   <lambda>*ClockTests.testCallLater.<locals>.<lambda>0       4r      r5   N)
r   r*   	callLater
assertTruer   IDelayedCall
providedByr+   getTimeactiver   r.   calls      r   testCallLaterClockTests.testCallLater*   sk    
 JJL{{1/a{8
//::4@A+&r   c                     [         R                  " 5       nUR                  SS SSS9nUR                  5         U R	                  UR                  5       5        g)z#
Test that calls can be cancelled.
r2   c                     g r   r$   r4   s     r   r6   3ClockTests.testCallLaterCancelled.<locals>.<lambda>:   r8   r   r9   r:   N)r   r*   r;   cancelassertFalser@   rA   s      r   testCallLaterCancelled!ClockTests.testCallLaterCancelled5   sC     JJL{{1/a{8'r   c                     [         R                  " 5       nUR                  SS SSS9nUR                  SS SSS9nU R                  X#L 5        g	)
zC
Test that the DelayedCall returned is not one previously
created.

   c                     g r   r$   r4   s     r   r6   3ClockTests.test_callLaterOrdering.<locals>.<lambda>D   s    Tr   r2   r9   r:   c                     g r   r$   r4   s     r   r6   rO   E   s    Dr         N)r   r*   r;   rI   )r   r.   call1call2s       r   test_callLaterOrdering!ClockTests.test_callLaterOrdering>   sM    
 JJLB 11:A0!q9(r   c                 ,  ^ / m[         R                  " 5       nUR                  SU4S j5      nUR                  S5        U R	                  T/ 5        UR                  S5        U R	                  TS/5        U R                  UR                  5       5        g)z5
Test that advancing the clock will fire some calls.
r9   c                  &   > T R                  S 5      $ r   append)eventss   r   r6   (ClockTests.testAdvance.<locals>.<lambda>N   s    fmmD&9r   r2   N)r   r*   r;   advancer+   rI   r@   r   r.   rB   r[   s      @r   testAdvanceClockTests.testAdvanceH   sr     JJL{{19:			!$			!$('r   c                    ^ ^ [         R                  " 5       nUU 4S jnUR                  SU5      mUR                  S5        g)z
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.
c                  Z   > TR                  [        R                  T R                  5        g r   )assertRaisesr   AlreadyCalledrH   )rB   r   s   r   cb(ClockTests.testAdvanceCancel.<locals>.cb_   s    e114;;?r   r2   N)r   r*   r;   r]   )r   r.   re   rB   s   `  @r   testAdvanceCancelClockTests.testAdvanceCancelU   s3     JJL	@ {{1b!			!r   c                 P  ^ / m[         R                  " 5       nUR                  SU4S jSSS9nUR                  S5        U R	                  UR                  5       S5        UR                  S5        U R	                  T/ 5        UR                  S5        U R	                  TS/5        g)	z!
Test that calls can be delayed.
r2   c                 (   > TR                  X45      $ r   rY   r   r5   r[   s     r   r6   1ClockTests.testCallLaterDelayed.<locals>.<lambda>k       6==!+@r   r9   r:   g      ?      ?r2   r9   N)r   r*   r;   delayr+   r?   r]   r^   s      @r   testCallLaterDelayedClockTests.testCallLaterDelayede   s     JJL{{1@!q{I

1+			#$			#&*r   c                 r  ^ / m[         R                  " 5       nUR                  SU4S jSSS9nUR                  S5        UR	                  S5        U R                  UR                  5       S5        UR                  S5        U R                  T/ 5        UR                  S5        U R                  TS/5        g)	z<
Test that calls can have their time reset to a later time.
r9   c                 (   > TR                  X45      $ r   rY   rk   s     r   r6   4ClockTests.testCallLaterResetLater.<locals>.<lambda>y   rm   r   r2   r:   rQ   rR   ro   N)r   r*   r;   r]   resetr+   r?   r^   s      @r   testCallLaterResetLater"ClockTests.testCallLaterResetLaters   s     JJL{{1@!q{I			!

1+			!$			!&*r   c                 
  ^ / m[         R                  " 5       nUR                  SU4S jSSS9nUR                  S5        U R	                  UR                  5       S5        UR                  S5        U R	                  TS/5        g)	z?
Test that calls can have their time reset to an earlier time.
rR   c                 (   > TR                  X45      $ r   rY   rk   s     r   r6   5ClockTests.testCallLaterResetSooner.<locals>.<lambda>   rm   r   r2   r9   r:   rQ   ro   N)r   r*   r;   rv   r+   r?   r]   r^   s      @r   testCallLaterResetSooner#ClockTests.testCallLaterResetSooner   sj     JJL{{1@!q{I

1+			!&*r   c                     [         R                  " 5       nUR                  SS 5      nUR                  SS 5      nUR                  5       nU R	                  X#1[        U5      5        g)z2
Test that we can get a list of all delayed calls
r2   c                     g r   r$   xs    r   r6   1ClockTests.test_getDelayedCalls.<locals>.<lambda>       r   r9   c                     g r   r$   r   s    r   r6   r      s    r   N)r   r*   r;   getDelayedCallsr+   set)r   r.   rB   rT   callss        r   test_getDelayedCallsClockTests.test_getDelayedCalls   sS     JJL{{1n-A~.!!#$E
3r   c                 n    [         R                  " 5       nU R                  UR                  5       / 5        g)zS
Test that we get an empty list from getDelayedCalls on a newly
constructed Clock.
N)r   r*   r+   r   r-   s     r   test_getDelayedCallsEmpty$ClockTests.test_getDelayedCallsEmpty   s(    
 JJL**,b1r   c                     [         R                  " 5       nU R                  [        R                  R                  U5      S5        g )Nz#Clock does not provide IReactorTime)r   r*   r<   r   IReactorTimer>   r-   s     r   test_providesIReactorTime$ClockTests.test_providesIReactorTime   s0    JJL##..q13X	
r   c                   ^^ / mSS/n[         R                  " 5       mUU4S jnTR                  SUS5      nUR                  S5        TR                  SUS5        TR	                  S	/S
-  5        U R                  TU5        g)a  
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".
r5          @r         @c                 F   > TR                  U TR                  5       45      $ r   rZ   r,   nr   results    r   r6   <ClockTests.test_callLaterKeepsCallsOrdered.<locals>.<lambda>       FMM1emmo*>?r   rn   r   r   r   r5   r2   rQ   Nr   r*   r;   rv   pumpr+   r   expectedlogtimecall_ar   r   s       @@r   test_callLaterKeepsCallsOrdered*ClockTests.test_callLaterKeepsCallsOrdered   st     
+

?gs3SWc*

A37*r   c                   ^^ / mSS/n[         R                  " 5       mUU4S jnTR                  SUS5      nTR                  SUS5        UR                  S5        TR	                  S	/S
-  5        U R                  TU5        g)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".
r   r   c                 F   > TR                  U TR                  5       45      $ r   r   r   s    r   r6   AClockTests.test_callLaterResetKeepsCallsOrdered.<locals>.<lambda>   r   r   rn   r   r   r5   r   r2   rQ   Nr   r   s       @@r   $test_callLaterResetKeepsCallsOrdered/ClockTests.test_callLaterResetKeepsCallsOrdered   st     
+

?gs3Wc*S

A37*r   c                   ^^^ / mSS/n[         R                  " 5       mUU4S jnTR                  SUS5      mU4S jnTR                  SU5        TR                  SUS	5        TR                  S
/S-  5        U R	                  TU5        g)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}, even when that call to C{reset}
occurs within the callable scheduled by C{callLater} itself.
)r.   r   )r5   g      @c                 F   > TR                  U TR                  5       45      $ r   r   r   s    r   r6   KClockTests.test_callLaterResetInsideCallKeepsCallsOrdered.<locals>.<lambda>   r   r   r   r5   c                  (   > T R                  S5        g )Nr   )rv   )call_bs   r   r   DClockTests.test_callLaterResetInsideCallKeepsCallsOrdered.<locals>.a   s    LLr   rn   r   r.         ?rM   N)r   r*   r;   r   r+   )r   r   r   r   r   r   r   s       @@@r   .test_callLaterResetInsideCallKeepsCallsOrdered9ClockTests.test_callLaterResetInsideCallKeepsCallsOrdered   s}     
+

?gs3	 	QWc*

C52:*r   r$   N)r   r   r   r   __doc__r/   rC   rJ   rU   r_   rg   rq   rw   r|   r   r   r   r   r   r   r   r$   r   r   r'   r'      sR    )	'()( ++
+
42
+0+0+r   r'   c                       \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rSrg)	LoopTests   zO
Tests for L{task.LoopingCall} based on a fake L{IReactorTime}
implementation.
c                 r    [         R                  " S 5      nU R                  UR                  [        5        g)z7
L{LoopingCall}'s default clock should be the reactor.
c                      g r   r$   r$   r   r   r6   -LoopTests.test_defaultClock.<locals>.<lambda>   r   r   N)r   LoopingCallr+   r   r   )r   rB   s     r   test_defaultClockLoopTests.test_defaultClock   s(     -W-r   c                   ^^^ / mSm[         R                  " 5       mUUU4S jn[         R                  " U5      nTUl        SmUR	                  S5        U R                  TS/5        U R                  TR                  5       T5        TR                  S5        U R                  TS/5        SmTR                  S5        U R                  TSS/5        U R                  TR                  5       S5        TR                  S5        U R                  TSS/5        SmTR                  S5        U R                  T/ S	Q5        U R                  TR                  5       S
5        g)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.
Nc                  f   > TR                  TR                  5       5        TR                  T 5        g r   )rZ   r,   r]   )callDurationr   timess   r   	aCallback3LoopTests.test_callbackTimeSkips.<locals>.aCallback  s!    LL)MM,'r   r9   r   r   r2         @g      @)r   r   rR   rR   )r   r*   r   r   startr+   r,   r]   )r   r   rB   r   r   r   s      @@@r   test_callbackTimeSkips LoopTests.test_callbackTimeSkips   s.    

	( 	*
 

3 	$ 	,7
 	a$ cC)#. 	aC) c,!,r   c                   ^^ / m[         R                  " 5       mUU4S jn[         R                  " U5      nTUl        UR	                  S5        U R                  TS/5        TR                  S5        U R                  TSS/5        TR                  S5        U R                  T/ SQ5        TR                  S5        U R                  T/ SQ5        g)z
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.
c                  D   > TR                  T R                  5       5        g r   r   )r   r   s   r   r   2LoopTests.test_reactorTimeSkips.<locals>.aCallback;  s    LL)r   r   r   r9   r2   )r   r9   rQ   N)r   r*   r   r   r   r+   r]   )r   r   rB   r   r   s      @@r   test_reactorTimeSkipsLoopTests.test_reactorTimeSkips1  s     

	*
 	*


3 	$ 	aA' 	a	* 	a	*r   c                   ^^ / m[         R                  " 5       mUU4S jn[         R                  R                  U5      nTUl        SnSnUR                  U5        U R                  TS/5        TR                  X4-   5        U R                  TSX4-   S4/5        TR                  SU-  U-   5        U R                  TSX4-   S4SU-  SU-  -   S4/5        TR                  S	5        U R                  TSX4-   S4SU-  SU-  -   S4/5        g
)at  
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.
c                 H   > TR                  TR                  5       U 45        g r   r   )numCallsr   r   s    r   r   7LoopTests.test_reactorTimeCountSkips.<locals>.aCallback_  s    LL%--/845r   r   {Gz?r   r2   r2   rQ   rR   r9   r   N)r   r*   r   	withCountr   r   r+   r]   r   r   rB   INTERVALREALISTIC_DELAYr   r   s        @@r   test_reactorTimeCountSkips$LoopTests.test_reactorTimeCountSkipsS  s*    

	6
 )))4


8 	)
 	h01(*Da)H IJ 	q8|67+Q/h,1#67;	
 	a+Q/h,1#67;	
r   c                 X  ^^ / m[         R                  " 5       mUU4S jn[         R                  R                  U5      nTUl        SnSnUR                  U5        U R                  TR                  5       S5        TR                  X4-   5        U R                  TR                  5       X4-   S45        TR                  US-  5        U R                  TR                  5       SU-  U-   S45        TR                  US-  5        U R                  TR                  5       S	U-  U-   S45        g
)a  
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.
c                 H   > TR                  TR                  5       U 45        g r   r   )countr   r   s    r   r   <LoopTests.test_countLengthyIntervalCounts.<locals>.aCallback  s    LL%--/512r   r   r   r   r2   g      ?g      @g      ?r   N)	r   r*   r   r   r   r   r+   popr]   r   s        @@r   test_countLengthyIntervalCounts)LoopTests.test_countLengthyIntervalCounts  s     

	3
 )))4


8f- 	h01x'A1&EF 	ho&x?'JA&NO 	ho&h/'I1&MNr   c                 2   [         R                  " 5       n/ n[         R                  R                  UR                  5      nXl        SnSnXT-  nUR                  USS9  [        U5       H  nUR                  U5        M     S nXX" U/U-  5      -
  n	UR                  U	5        UR                  5       n
U R                  [        U	5      S:  U	 S35        U R                  X:  U
 SU 35        U R                  U" U5      U5        U R                  S	U5        g
)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 <task.LoopingCall.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.
rM   rn   Fnowc                 $    SnU  H  nX-  nM	     U$ )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$   )itemstotalitems      r   
sum_compatALoopTests.test_withCountFloatingPointBoundary.<locals>.sum_compat  s     E Lr   r   z should be greater than zeroz$ should be greater than or equal to r   N)r   r*   r   r   rZ   r   r   ranger]   r,   r<   absr+   assertNotIn)r   r   accumulatorrB   r   timespanintervalr   r   epsilonsecondsValues              r   #test_withCountFloatingPointBoundary-LoopTests.test_withCountFloatingPointBoundary  s    

))+*<*<=

  #

8
'uAMM(# 
	 Z
U(:;;g}} 	Gs*wi7S,TU 	$n@
K	

 	K0%8K(r   c                 (  ^^ [         R                  " 5       n/ mUU4S jn[         R                  R                  U5      mUTl        TR                  SSS9nUR                  S/S-  5        U R                  U5        U R                  S/S-  T5        g)za
L{task.LoopingCall.withCount} with interval set to 0 calls the
countCallable with a count of 1.
c                 h   > TR                  U 5        [        T5      S:  a  TR                  5         g g )NrR   rZ   lenstop)cntr   loops    r   foo1LoopTests.test_withCountIntervalZero.<locals>.foo   s,    s#;!#		 $r   r   Fr      r2   N)	r   r*   r   r   r   r   r   successResultOfr+   )r   r   r   deferredr   r   s       @@r   test_withCountIntervalZero$LoopTests.test_withCountIntervalZero  s    
 

	
 ))#.
::aU:+ 	

A37X&!q+.r   c                   ^^^ [         R                  " 5       n[        R                  " 5       m/ mUUU4S jn[         R                  R                  U5      mUTl        TR                  SSS9  UR                  S/S-  5        U R                  S/S-  T5        UR                  S/S-  5        U R                  S/S-  T5        TR                  S5        UR                  S/S-  5        U R                  S/S	-  T5        g)
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.
c                    > TR                  U 5        [        T5      S:X  a  T$ [        T5      S:  a  TR                  5         g g )Nr9   rR   r   )r   r   r   r   s    r   r   6LoopTests.test_withCountIntervalZeroDelay.<locals>.foo  s>    s#;1$;!#		 $r   r   Fr   r9   r2   NrR   r   )r   r*   r   Deferredr   r   r   r   r   r+   callback)r   r   r   r   r   r   s      @@@r   test_withCountIntervalZeroDelay)LoopTests.test_withCountIntervalZeroDelay  s     

>>#	 ))#.


1%
 

A37!q+. 	

A37!q+. 	$

A37!q+.r   c                   ^	^
^ [         R                  " 5       n[        R                  " 5       m
/ m	SmSnSnSnX$-   nXS-  nUS-  nU	U
U4S jn[         R                  R                  U5      nXl        UR                  SSS9  UR                  S/TU-   -  5        U R                  S/T-  T	5        X8l
        T
R                  S	5        UR                  U5        U R                  SSU/T	5        UR                  SU-  5        U R                  SSUS/T	5        UR                  SU-  5        U R                  SSUSS/T	5        g	)
z
L{task.LoopingCall.withCount} with interval set to 0 will still keep
the time when last called so when the interval is reset.
r9   r   	   r2   c                 J   > TR                  U 5        [        T5      T:X  a  T$ g r   rZ   r   )r   r   r   stepsBeforeDelays    r   r   ILoopTests.test_withCountIntervalZeroDelayThenNonZeroInterval.<locals>.foob  s)    s#;#33 4r   r   Fr   N)r   r*   r   r  r   r   r   r   r   r+   r   r  r]   )r   r   extraTimeAfterDelaymutatedLoopIntervaldurationOfDelayskippedTimeexpectedSkipCountr   r   r   r   r  s            @@@r   2test_withCountIntervalZeroDelayThenNonZeroInterval<LoopTests.test_withCountIntervalZeroDelayThenNonZeroInterval8  s[   
 

>># 
     
 *; (> 	Q	 
 ))#.


1%
  	

A3*-@@AB!//= ,$o&!Q 12K@a--.!Q 115{Ca--.!Q 11a8+Fr   c                 T  ^^ / SQn[         R                  " 5       n/ mSU4S jjn[        X#SSSS9nUR                  S5      n/ mU4S jnUR	                  U5        UR                  U5        U R                  [        T5      S	S
[        T5      4-  5        T HM  u  pxpU R                  US5        U R                  US5        U R                  U	5        U R                  U
S5        MO     UR                  5         U R                  TS   U5        U R                  UR                  5        g )Ng?皙?r  c                 ,   > TR                  XX#45        g r   rY   )r   r5   r.   dLs       r   r   (LoopTests.testBasicFunction.<locals>.foo  s    HHaA\"r   r   r5   r  r  r  c                 (   > TR                  U 5        g r   rY   r   	theResults    r   
saveResult/LoopTests.testBasicFunction.<locals>.saveResult      V$r   rQ   zgot %d iterations, not 3r   )NN)r   r*   r   r   addCallbackr   r+   r   assertIsNoner   assertIsrI   r   )r   timingsr   r   lcDr   r   r5   r.   r  r  r  s              @@r   testBasicFunctionLoopTests.testBasicFunction  s   
 #

	# !S#=HHSM		% 	
j!

7Q$>#a&$JKJA!Q$Q$a Q$	  		ilB' 	%r   c                   ^ / SQn[         R                  " 5       n/ n[        X#R                  S 5      nUR	                  SSS9n/ mU4S jnUR                  U5        UR                  U5        U R                  [        U5      SS[        U5      4-  5        UR                  5         U R                  TS   U5        U R                  UR                  5        g )	Nr  r  Fr   c                 (   > TR                  U 5        g r   rY   r  s    r   r   .LoopTests.testDelayedStart.<locals>.saveResult  r"  r   r9   zgot %d iterations, not 2r   )r   r*   r   rZ   r   r#  r   r+   r   r   r%  rI   r   )r   r&  r   r  r'  r  r   r  s          @r   testDelayedStartLoopTests.testDelayedStart  s    "

 $7HHSeH$		% 	
j!

7Q$>#a&$JK
	ilB'%r   c                 t    [         R                  " S 5      nU R                  [        UR                  S5        g )Nc                      g r   r$   r$   r   r   r6   (LoopTests.testBadDelay.<locals>.<lambda>  s    dr   )r   r   rc   
ValueErrorr   )r   r'  s     r   testBadDelayLoopTests.testBadDelay  s(    l+*bhh3r   c                    ^ / mU4S jn[         R                  " 5       n[        X25      nUR                  USS9  UR	                  5         U R                  T5        U R                  UR                  5        g )Nc                  (   > T R                  S 5        g r   rY   rans   r   r   $LoopTests._stoppingTest.<locals>.foo      JJtr   Fr   )r   r*   r   r   r   rI   r   )r   rp   r   r   r'  r:  s        @r   _stoppingTestLoopTests._stoppingTest  s]    	 

 ,
E"
	%r   c                 $    U R                  S5      $ )Nr   r=  r   s    r   testStopAtOnceLoopTests.testStopAtOnce  s    !!!$$r   c                 $    U R                  S5      $ )NrM   r@  rA  s    r   testStoppingBeforeDelayedStart(LoopTests.testStoppingBeforeDelayedStart  s    !!"%%r   c                 F  ^ / mU4S jn[         R                  " 5       n[        X!5      nUR                  SSS9  UR	                  S5        UR                  5         UR	                  S5        U R                  T/ 5        UR	                  S5        U R                  TS/5        g)z(
Test that L{LoopingCall} can be reset.
c                  (   > T R                  S 5        g r   rY   r9  s   r   r   !LoopTests.test_reset.<locals>.foo  r<  r   r9   Fr   r2   N)r   r*   r   r   r]   rv   r+   )r   r   r.   r'  r:  s       @r   
test_resetLoopTests.test_reset  s     	 JJL (
			!

			!b!			!tf%r   c           
      j    U R                  [        [        R                  " [        SSS95      S5        g)z?
L{LoopingCall.__repr__} includes the wrapped function's name.
r2   r9   )keyz6LoopingCall<None>(installReactor, *(1,), **{'key': 2})N)r+   reprr   r   r   rA  s    r   test_reprFunctionLoopTests.test_reprFunction  s,     	!!.!;<D	
r   c                 ~    U R                  [        [        R                  " [        R
                  5      5      S5        g)zB
L{LoopingCall.__repr__} includes the wrapped method's full name.
z:LoopingCall<None>(TestableLoopingCall.__init__, *(), **{})N)r+   rN  r   r   r   r   rA  s    r   test_reprMethodLoopTests.test_reprMethod  s/     	!!"5">">?@H	
r   c                 "   [         R                  " S 5      nUR                    SnU R                  U R                  /5      nU R                  S[        U5      5        U R                  [        US   S   5        U R                  X#S   S   5        g)z(
L{LoopingCall.deferred} is deprecated.
c                      g r   r$   r$   r   r   r6   4LoopTests.test_deferredDeprecation.<locals>.<lambda>  r   r   ztwisted.internet.task.LoopingCall.deferred was deprecated in Twisted 16.0.0; please use the deferred returned by start() insteadr2   r   categorymessageN)r   r   r   flushWarningstest_deferredDeprecationr+   r   DeprecationWarning)r   r   rX  warningss       r   rZ  "LoopTests.test_deferredDeprecation  s     -B 	
 %%t'D'D&EFCM*+Xa[-DE1+i"89r   r$   N)r   r   r   r   r   r   r   r   r   r   r   r   r  r  r)  r.  r5  r=  rB  rE  rJ  rO  rR  rZ  r   r$   r   r   r   r      sr    
.2-h +D8
t'OR@)D/4$/LGGR&&P&04
&%&&&

:r   r   c                   D    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
rg)ReactorLoopTestsi  c                     S n[         R                  " US5      nU R                  UR                  S5      [        5      $ )Nc                     [        U 5      er   r"   r   s    r   r   )ReactorLoopTests.testFailure.<locals>.foo  s    ""r   barr  r   r   assertFailurer   r"   r   r   r'  s      r   testFailureReactorLoopTests.testFailure  s6    	# c5)!!"((3-??r   c                    ^ U4S jn[         R                  " US5      mU R                  TR                  S5      [        5      $ )Nc                 :   > TR                  5         [        U 5      er   )r   r"   )r   r'  s    r   r   -ReactorLoopTests.testFailAndStop.<locals>.foo  s    GGI""r   rd  r  re  rg  s     @r   testFailAndStop ReactorLoopTests.testFailAndStop  s7    	# c5)!!"((3-??r   c                    ^ ^^ / mUU4S jn[         R                  " U5      mTR                  S5      nUU 4S jnUR                  U5      $ )Nc                  h   > TR                  S 5        [        T5      S:  a  T R                  5         g g )Nr   r   )r'  r:  s   r   r   0ReactorLoopTests.testEveryIteration.<locals>.foo&  s(    JJt3x!|	 r   r   c                 <   > TR                  [        T5      S5        g )N   )r+   r   )ignr:  r   s    r   stopped4ReactorLoopTests.testEveryIteration.<locals>.stopped.  s    SXq)r   )r   r   r   r#  )r   r   r  ru  r'  r:  s   `   @@r   testEveryIteration#ReactorLoopTests.testEveryIteration#  sB    	
 c"HHQK	* }}W%%r   c                    ^ [         R                  " 5       mU4S jn[        R                  " U5      U l        U R                  R                  SSS9  [        R                  " SU R                  T5        T$ )Nc                  P   > T R                  [        R                  " S5      5        g )Nz'This task also should never get called.)errbackr   DefaultExceptionr  s   r   r   1ReactorLoopTests.testStopAtOnceLater.<locals>.foo8  s    II(()RSr   r2   Fr   r   )	r   r  r   r   _lcr   r   r;   !_callback_for_testStopAtOnceLater)r   r   r  s     @r   testStopAtOnceLater$ReactorLoopTests.testStopAtOnceLater3  s[     NN	
 ##C(qe$!TCCQGr   c                 |    U R                   R                  5         [        R                  " SUR                  S5        g )Nr   success)r~  r   r   r;   r  )r   r  s     r   r  2ReactorLoopTests._callback_for_testStopAtOnceLaterB  s%    !QZZ3r   c                    ^^ SS/n[         R                  " 5       mUU4S jn[        TU5      mTR                  S5        TR	                  U5        U R                  TR                  5        g )N皙?g?c                     > [         R                  " 5       n U R                  U4S j5        TR                  SU R                  S 5        U $ )Nc                 $   > TR                  5       $ r   )r   )_r'  s    r   r6   @ReactorLoopTests.testWaitDeferred.<locals>.foo.<locals>.<lambda>N  s    BGGIr   r2   )r   r  r#  r;   r  )r  r   r'  s    r   r   .ReactorLoopTests.testWaitDeferred.<locals>.fooL  s5     AMM-.OOAqzz40Hr   )r   r*   r   r   r   rI   r   )r   r&  r   r   r'  s      @@r   testWaitDeferred!ReactorLoopTests.testWaitDeferredF  sU     *

	 !,


7%r   c                   ^ S/n[         R                  " 5       mU4S jn[        TU5      nUR                  S5      nU R	                  U[
        5        TR                  U5        U R                  TR                  5        U$ )N333333?c                  |   > [         R                  " 5       n TR                  SU R                  [	        5       5        U $ )Nr  )r   r  r;   r{  r"   )r  r   s    r   r   4ReactorLoopTests.testFailurePropagation.<locals>.fooa  s*     AOOCMO<Hr   r2   )	r   r*   r   r   rf  r"   r   rI   r   )r   r&  r   r'  r  r   s        @r   testFailurePropagation'ReactorLoopTests.testFailurePropagationW  sj     %

	
 !,HHQK1m,

7%r   c                   ^^ [         R                  " 5       n[        R                  " 5       m/ mUU4S jn[         R                  R                  U5      nXl        UR                  SSS9mU R                  T/ 5        UR                  SS/5        U R                  [        T5      S5        TR                  S5        UR                  S/5        U R                  [        T5      S5        U R                  TSS	/5        g)
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.
c                 J   > TR                  U 5        [        T5      S:X  a  T$ g Nr2   r  )possibleCountr  deferredCountss    r   countTracker=ReactorLoopTests.test_deferredWithCount.<locals>.countTrackerz  s&    !!-0>"a'r   r  Fr   g?r2   Nr9   rQ   )r   r*   r   r  r   r   r   r   r+   r   r   r  )r   	testClockr  r'  r  r  s       @@r   test_deferredWithCount'ReactorLoopTests.test_deferredWithCountn  s     JJL	NN	 ''5HHSeH$ 	, 	Sz"^,a0 	


4u^,a0 	!Q0r   )r~  N)r   r   r   r   rh  rm  rw  r  r  r  r  r  r   r$   r   r   r_  r_    s,    @@& 4&".*1r   r_  c                   0    \ rS rSrSrS rS rS rS rSr	g)	DeferLaterTestsi  z
Tests for L{task.deferLater}.
c                 P  ^^ / m[        5       mUU4S jn[        R                  " 5       n[        R                  " USUSSS9nUR	                  U R
                  T5        UR                  S5        U R                  T/ 5        UR                  S5        U R                  TS/5        U$ )	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                 ,   > TR                  X45        T$ r   rY   )r   rd  flagresultss     r   callable/DeferLaterTests.test_callback.<locals>.callable  s    NNC:&Kr   rQ   r   rd  )rd  r9   r2   )r   rd  )objectr   r*   
deferLaterr#  r%  r]   r+   )r   r  r   r  r  r  s       @@r   test_callbackDeferLaterTests.test_callback  s    
 x	 

OOE1h5A	dmmT*a"%a>"23r   c                     S n[         R                  " 5       n[         R                  " USU5      nUR                  S5        U R	                  U[
        5      $ )zk
The L{Deferred} returned by L{task.deferLater} is errbacked if the
supplied function raises an exception.
c                      [        5       er   rb  r$   r   r   r  .DeferLaterTests.test_errback.<locals>.callable  s
    /!r   r2   )r   r*   r  r]   rf  r"   )r   r  r   r  s       r   test_errbackDeferLaterTests.test_errback  sE    	" 

OOE1h/a!!!]33r   c                   ^ ^^ / m[         R                  " 5       m[         R                  " TSTR                  S5      nUR	                  5         UUU 4S jnT R                  U[        R                  5        UR                  U5        U$ )zt
The L{Deferred} returned by L{task.deferLater} can be
cancelled to prevent the call from actually being performed.
r2   Nc                 h   > TR                  / TR                  5       5        TR                  T5        g r   )r+   r   rI   )ignoredcalledr   r   s    r   cbCancelled0DeferLaterTests.test_cancel.<locals>.cbCancelled  s*    R!6!6!89V$r   )	r   r*   r  rZ   rH   rf  r   CancelledErrorr#  )r   r  r  r  r   s   `  @@r   test_cancelDeferLaterTests.test_cancel  sd    
 

OOE1fmmT:	
	% 	1e223	k"r   c                     [         R                  " 5       n[         R                  " US5      nU R                  U5        UR	                  S5        U R                  SU R                  U5      5        g)zh
The L{Deferred} returned by L{task.deferLater} fires with C{None}
when no callback function is passed.
r   N)r   r*   r  assertNoResultr]   r%  r   )r   r   r  s      r   test_noCallbackDeferLaterTests.test_noCallback  sR    
 

OOE3'AcdD0034r   r$   N)
r   r   r   r   r   r  r  r  r  r   r$   r   r   r  r    s    *4(
5r   r  c                   2    \ rS rSrS rS rS rS rS rSr	g)	_FakeReactori  c                 
   SU l         [        R                  " 5       U l        U R                  R                  U l        U R                  R
                  U l        U R                  R                  U l        / U l        / / S.U l        g )NFbeforeduring)	_runningr   r*   _clockr;   r,   r   _whenRunning_shutdownTriggersrA  s    r   r   _FakeReactor.__init__  s_    jjl..{{**#{{::,."!=r   c                 j    U R                   c	  U" U0 UD6  g U R                   R                  XU45        g r   )r  rZ   )r   r  argskwargss       r   callWhenRunning_FakeReactor.callWhenRunning  s4    $d%f%$$hf%=>r   c                 b    US;   d   eUS:X  d   eU R                   U   R                  X445        g )Nr  shutdown)r  rZ   )r   phaseeventr  r  s        r   addSystemEventTrigger"_FakeReactor.addSystemEventTrigger  s;    ,,,,
"""u%,,h-=>r   c                    SU l         U R                  nSU l        U H  u  p#nU" U0 UD6  M     U R                   (       ar  U R                  5       nU(       d  [        S5      eU R                  R                  US   R                  5       U R                  5       -
  5        U R                   (       a  Mr  U R                  nSU l        US   US   -    H
  u  psU" U6   M     g)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.
TNzNo DelayedCalls leftr   r  r  )	r  r  r   RuntimeErrorr  r]   r?   r,   r  )r   whenRunningr  r  r  r   shutdownTriggerstriggers           r   run_FakeReactor.run  s     '' &1"HFd%f% '2mm((*E"#9::KKa 0 0 2T\\^ CD	 mmm
  11!%-h7:J8:TTMGTN Ur   c                 ^    U R                   (       d  [        R                  " 5       eSU l         g)z
Stop the reactor.
FN)r  r   ReactorNotRunningrA  s    r   r   _FakeReactor.stop  s!     }}))++r   )r  r  r  r  r;   r   r,   N)
r   r   r   r   r   r  r  r  r   r   r$   r   r   r  r    s    >??
,r   r  c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)
ReactTestsi  z+
Tests for L{twisted.internet.task.react}.
c                   ^ / mU4S jn[        5       nU R                  [        [        R                  XS9nU R                  SUR                  5        U R                  TS/5        U R                  UR                  5       S5        g){
L{task.react} runs the reactor until the L{Deferred} returned by the
function it is passed is called back, then stops it.
c                    > [         R                  " 5       nU R                  " STR                  S5        U R                  " SUR                  S 5        U$ Nr2   Tr9   r   r  r;   rZ   r  r   finished
timePasseds     r   main4ReactTests.test_runsUntilAsyncCallback.<locals>.main$  sD    ~~'Ha!2!2D9a!2!2D9Or   _reactorr   Tr9   Nr  rc   
SystemExitr   reactr+   coder,   r   r  r	exitErrorr  s       @r   test_runsUntilAsyncCallback&ReactTests.test_runsUntilAsyncCallback  so    
 
	 N%%j$**d%O	INN+dV,a(r   c                     S n[        5       nU R                  [        [        R                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        g)
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                 .    [         R                  " S 5      $ r   r   succeedr   s    r   r  3ReactTests.test_runsUntilSyncCallback.<locals>.main7  s    ==&&r   r  r   Nr  r   r  r  r  s       r   test_runsUntilSyncCallback%ReactTests.test_runsUntilSyncCallback0  sU    	' N%%j$**d%O	INN+a(r   c                   ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  T5      nU R                  [        U5      S5        g)
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                       \ rS rSrSrg)@ReactTests.test_runsUntilAsyncErrback.<locals>.ExpectedExceptioniF  r$   Nr%   r$   r   r   ExpectedExceptionr   F      r   r  c                 x   > [         R                  " 5       nU R                  " SUR                  T" 5       5        U$ r  r   r  r;   r{  r   r  r  s     r   r  3ReactTests.test_runsUntilAsyncErrback.<locals>.mainI  s0    ~~'Ha!1!13D3FGOr   r  r2   N
	Exceptionr  rc   r  r   r  r+   r  flushLoggedErrorsr   r   r  r  r  errorsr  s        @r   test_runsUntilAsyncErrback%ReactTests.test_runsUntilAsyncErrback?  sq    		 		
 N%%j$**d%O	INN+''(9:Va(r   c                 Z  ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        U R                  T5      nU R                  [        U5      S5        g)
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                       \ rS rSrSrg)?ReactTests.test_runsUntilSyncErrback.<locals>.ExpectedExceptioni]  r$   Nr%   r$   r   r   r  r  ]  r  r   r  c                 :   > [         R                  " T" 5       5      $ r   r   failr   r  s    r   r  2ReactTests.test_runsUntilSyncErrback.<locals>.main`  s    ::/122r   r  r2   r   Nr  r  rc   r  r   r  r+   r  r,   r	  r   r
  s        @r   test_runsUntilSyncErrback$ReactTests.test_runsUntilSyncErrbackV  s    		 		3 N%%j$**d%O	INN+a(''(9:Va(r   c                     S n[        5       nU R                  [        [        R                  XS9nU R                  UR                  5       S5        U R                  SUR                  5        g)
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                     U R                   " SU R                  5        [        R                  " 5       nU R                  " SSUR
                  S 5        U$ Nr2   r  r  r;   r   r   r  r  r  r   r  s     r   r  0ReactTests.test_singleStopCallback.<locals>.mainq  sB    a.~~'H))(J@Q@QSWXOr   r  r2   r   Nr  rc   r  r   r  r+   r,   r  r  s       r   test_singleStopCallback"ReactTests.test_singleStopCallbackj  sU    	 N%%j$**d%O	a(INN+r   c                 Z  ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        U R                  T5      nU R                  [        U5      S5        g)
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                       \ rS rSrSrg)<ReactTests.test_singleStopErrback.<locals>.ExpectedExceptioni  r$   Nr%   r$   r   r   r  r'    r  r   r  c                    > U R                   " SU R                  5        [        R                  " 5       nU R                  " SSUR
                  T" 5       5        U$ r  r;   r   r   r  r  r{  r  s     r   r  /ReactTests.test_singleStopErrback.<locals>.main  sK    a.~~'H))*h&6&68I8K Or   r  r2   Nr  r
  s        @r   test_singleStopErrback!ReactTests.test_singleStopErrback}  s    		 		 N%%j$**d%O	INN+a(''(9:Va(r   c                    ^ / mU4S jn[        5       nU R                  [        [        R                  U/ SQUS9nU R                  SUR                  5        U R                  T/ SQ5        g)r
L{task.react} passes the elements of the list it is passed as
positional arguments to the function it is passed.
c                 V   > TR                  XU45        [        R                  " S 5      $ r   extendr   r  r   r   yzr  s       r   r  'ReactTests.test_arguments.<locals>.main  s"    KKq	"==&&r   r2   r9   rQ   r  r   Nr  rc   r  r   r  r+   r  r   r  r  r  r  s       @r   test_argumentsReactTests.test_arguments  sb    
 	' N%%

D)a & 
	 	INN+y)r   c                 @  ^  U 4S jn[        5       n[        5          [        U5        T R                  [        [
        R                  U/ 5      nT R                  SUR                  5        SSS5        T R                  UT R                  5        g! , (       d  f       N+= f)X
L{twisted.internet.reactor} is used if no reactor argument is passed to
L{task.react}.
c                 >   > U Tl         [        R                  " S 5      $ r   passedReactorr   r  r   r   s    r   r  ,ReactTests.test_defaultReactor.<locals>.main  s    !(D==&&r   r   Nr  r	   r   rc   r  r   r  r+   r  r%  r?  r   r  r   r  s   `   r   test_defaultReactorReactTests.test_defaultReactor  so    	' .[7#))*djj$KIQ	/  	gt112	 [   AB
Bc                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)t
L{task.react} forwards the exit code specified by the C{SystemExit}
error returned by the passed function, if any.
c                 @    [         R                  " [        S5      5      $ N   r   r  r  r  s    r   r  1ReactTests.test_exitWithDefinedCode.<locals>.main  s    ::jn--r   r  rK  Nr7  r  s       r   test_exitWithDefinedCode#ReactTests.test_exitWithDefinedCode  sD    	. N%%j$**dBQR%S	Y^^,r   c                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)_
L{task.react} handles when the reactor is stopped just before the
returned L{Deferred} fires.
c                 f   ^ ^ [         R                  " 5       mUU 4S jnT R                  " U5        T$ )Nc                  J   > TR                   " 5         T R                  S 5        g r   r   r  r  r   s   r   r   ;ReactTests.test_synchronousStop.<locals>.main.<locals>.stop      

4 r   r   r  r  r   r   r  s   ` @r   r  -ReactTests.test_synchronousStop.<locals>.main  s)     A! ##D)Hr   r  r   Nr7  r  s       r   test_synchronousStopReactTests.test_synchronousStop  sD    	 N%%j$**dBQR%S	INN+r   c                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)^
L{task.react} handles when the reactor is stopped and the
returned L{Deferred} doesn't fire.
c                 f    U R                   " SU R                  5        [        R                  " 5       $ r  r;   r   r   r  r  s    r   r  .ReactTests.test_asynchronousStop.<locals>.main  s#    a.>>##r   r  r   Nr7  r  s       r   test_asynchronousStop ReactTests.test_asynchronousStop  sD    	$ N%%j$**dBQR%S	INN+r   r?  Nr   r   r   r   r   r  r  r  r  r"  r+  r9  rD  rN  r[  rb  r   r$   r   r   r  r    >    )&)).)(,&)6*$3"-,(,r   r  c                   Z    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rSrg)ReactCoroutineFunctionTestsi  zH
Tests for L{twisted.internet.task.react} with an C{async def} argument
c                   ^ / mU4S jn[        5       nU R                  [        [        R                  XS9nU R                  SUR                  5        U R                  TS/5        U R                  UR                  5       S5        g)r  c                    >#    [         R                  " 5       nU R                  " STR                  S5        U R                  " SUR                  S 5        UI S h  vN $  N7fr  r  r  s     r   r  EReactCoroutineFunctionTests.test_runsUntilAsyncCallback.<locals>.main  sL     ~~'Ha!2!2D9a!2!2D9!>!>s   AA!AA!r  r   Tr9   Nr  r  s       @r   r  7ReactCoroutineFunctionTests.test_runsUntilAsyncCallback  so    
 
	" N%%j$**d%O	INN+dV,a(r   c                     S n[        5       nU R                  [        [        R                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        g)r  c                 J   #    [         R                  " S 5      I S h  vN $  N7fr   r  r  s    r   r  DReactCoroutineFunctionTests.test_runsUntilSyncCallback.<locals>.main
  s     t,,,,s   #!#r  r   Nr  r  s       r   r  6ReactCoroutineFunctionTests.test_runsUntilSyncCallback  sU    	- N%%j$**d%O	INN+a(r   c                   ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  T5      nU R                  [        U5      S5        g)r  c                       \ rS rSrSrg)QReactCoroutineFunctionTests.test_runsUntilAsyncErrback.<locals>.ExpectedExceptioni  r$   Nr%   r$   r   r   r  rs    r  r   r  c                    >#    [         R                  " 5       nU R                  " SUR                  T" 5       5        UI S h  vN $  N7fr  r  r  s     r   r  DReactCoroutineFunctionTests.test_runsUntilAsyncErrback.<locals>.main  s8     ~~'Ha!1!13D3FG!>!>s   >AAAr  r2   Nr  r
  s        @r   r  6ReactCoroutineFunctionTests.test_runsUntilAsyncErrback  sq    		 		"
 N%%j$**d%O	INN+''(9:Va(r   c                 Z  ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        U R                  T5      nU R                  [        U5      S5        g)r  c                       \ rS rSrSrg)PReactCoroutineFunctionTests.test_runsUntilSyncErrback.<locals>.ExpectedExceptioni0  r$   Nr%   r$   r   r   r  ry  0  r  r   r  c                 V   >#    [         R                  " T" 5       5      I S h  vN $  N7fr   r  r  s    r   r  CReactCoroutineFunctionTests.test_runsUntilSyncErrback.<locals>.main3  s     $5$78888s   )')r  r2   r   Nr  r
  s        @r   r  5ReactCoroutineFunctionTests.test_runsUntilSyncErrback)  s    		 		9 N%%j$**d%O	INN+a(''(9:Va(r   c                     S n[        5       nU R                  [        [        R                  XS9nU R                  UR                  5       S5        U R                  SUR                  5        g)r  c                    #    U R                   " SU R                  5        [        R                  " 5       nU R                  " SSUR
                  S 5        UI S h  vN $  N7fr  r  r  s     r   r  AReactCoroutineFunctionTests.test_singleStopCallback.<locals>.mainD  sJ     a.~~'H))(J@Q@QSWX!>!>s   AA AA r  r2   r   Nr!  r  s       r   r"  3ReactCoroutineFunctionTests.test_singleStopCallback=  sU    	" N%%j$**d%O	a(INN+r   c                 Z  ^  " S S[         5      mU4S jn[        5       nU R                  [        [        R
                  XS9nU R                  SUR                  5        U R                  UR                  5       S5        U R                  T5      nU R                  [        U5      S5        g)r%  c                       \ rS rSrSrg)MReactCoroutineFunctionTests.test_singleStopErrback.<locals>.ExpectedExceptioniW  r$   Nr%   r$   r   r   r  r  W  r  r   r  c                    >#    U R                   " SU R                  5        [        R                  " 5       nU R                  " SSUR
                  T" 5       5        UI S h  vN $  N7fr  r)  r  s     r   r  @ReactCoroutineFunctionTests.test_singleStopErrback.<locals>.mainZ  sS     a.~~'H))*h&6&68I8K ">!>s   AA&A$ A&r  r2   Nr  r
  s        @r   r+  2ReactCoroutineFunctionTests.test_singleStopErrbackP  s    		 		" N%%j$**d%O	INN+a(''(9:Va(r   c                    ^ / mU4S jn[        5       nU R                  [        [        R                  U/ SQUS9nU R                  SUR                  5        U R                  T/ SQ5        g)r.  c                 r   >#    TR                  XU45        [        R                  " S 5      I S h  vN $  N7fr   r0  r2  s       r   r  8ReactCoroutineFunctionTests.test_arguments.<locals>.mainr  s+     KKq	"t,,,,s   -757r6  r  r   Nr7  r8  s       @r   r9  *ReactCoroutineFunctionTests.test_argumentsk  sb    
 	- N%%

D)a & 
	 	INN+y)r   c                 @  ^  U 4S jn[        5       n[        5          [        U5        T R                  [        [
        R                  U/ 5      nT R                  SUR                  5        SSS5        T R                  UT R                  5        g! , (       d  f       N+= f)r<  c                 Z   >#    U Tl         [        R                  " S 5      I S h  vN $  N7fr   r>  r@  s    r   r  =ReactCoroutineFunctionTests.test_defaultReactor.<locals>.main  s#     !(Dt,,,,s   !+)+r   NrB  rC  s   `   r   rD  /ReactCoroutineFunctionTests.test_defaultReactor}  so    	- .[7#))*djj$KIQ	/  	gt112	 [rF  c                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)rH  c                 \   #    [         R                  " [        S5      5      I S h  vN $  N7frJ  rL  r  s    r   r  BReactCoroutineFunctionTests.test_exitWithDefinedCode.<locals>.main  s     JrN3333s   #,*,r  rK  Nr7  r  s       r   rN  4ReactCoroutineFunctionTests.test_exitWithDefinedCode  sD    	4 N%%j$**dBQR%S	Y^^,r   c                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)rQ  c                    ^ ^#    [         R                  " 5       mUU 4S jnT R                  " U5        TI S h  vN $  N7f)Nc                  J   > TR                   " 5         T R                  S 5        g r   rT  rU  s   r   r   LReactCoroutineFunctionTests.test_synchronousStop.<locals>.main.<locals>.stop  rW  r   rX  rY  s   ` @r   r  >ReactCoroutineFunctionTests.test_synchronousStop.<locals>.main  s0      A! ##D)7N7s   4?=?r  r   Nr7  r  s       r   r[  0ReactCoroutineFunctionTests.test_synchronousStop  sD    	 N%%j$**dBQR%S	INN+r   c                     S n[        5       nU R                  [        [        R                  U/ US9nU R                  SUR                  5        g)r^  c                    #    U R                   " SU R                  5        [        R                  " 5       I S h  vN $  N7fr  r`  r  s    r   r  ?ReactCoroutineFunctionTests.test_asynchronousStop.<locals>.main  s,     a.))))s   6?=?r  r   Nr7  r  s       r   rb  1ReactCoroutineFunctionTests.test_asynchronousStop  sD    	* N%%j$**dBQR%S	INN+r   rd  Nre  r$   r   r   rh  rh    rf  r   rh  N)r   twisted.internetr   r   r   r   r   twisted.internet.mainr   #twisted.internet.test.modulehelpersr	   twisted.trialr
   r*   twisted.pythonr   r   r   r  r"   TestCaser'   r   r_  r  r  SynchronousTestCaser  rh  r$   r   r   <module>r     s   
 E D 0 9 " 	

 "$** 	I 	O+"" O+d^:!! ^:BG1x(( G1TF5h'' F5R1 1hP,-- P,fP,(">"> P,r   