
    \dP                        d Z ddlmZmZmZmZmZ ddlmZ ddl	m
Z
 ddlmZ ej        ZddlmZ  G d dej                  Z G d	 d
e          Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d d          Z G d dej                  Z G d dej                  ZdS )z%
Tests for L{twisted.internet.task}.
    )defererror
interfacesreactortask)installReactor)	NoReactor)unittest)failurec                        e Zd Z fdZ xZS )TestableLoopingCallc                 H     t                      j        |i | || _        d S N)super__init__clock)selfr   akw	__class__s       6lib/python3.11/site-packages/twisted/test/test_task.pyr   zTestableLoopingCall.__init__   s*    !"r"""


    )__name__
__module____qualname__r   __classcell__)r   s   @r   r   r      s8                r   r   c                       e Zd ZdS )TestExceptionNr   r   r    r   r   r   r      s        Dr   r   c                   l    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd ZdS )
ClockTestsz<
    Test the non-wallclock based clock implementation.
    c                 |    t          j                    }|                     |                                d           dS )zV
        Test that the C{seconds} method of the fake clock returns fake time.
        r   N)r   ClockassertEqualsecondsr   cs     r   testSecondszClockTests.testSeconds#   s3     JLLa(((((r   c                 b   t          j                    }|                    dd dd          }|                     t          j                            |                     |                     |                                d           |                     |	                                           dS )z{
        Test that calls can be scheduled for later with the fake clock and
        hands back an L{IDelayedCall}.
           c                     d S r   r    r   bs     r   <lambda>z*ClockTests.testCallLater.<locals>.<lambda>0       4 r      r.   N)
r   r$   	callLater
assertTruer   IDelayedCall
providedByr%   getTimeactiver   r(   calls      r   testCallLaterzClockTests.testCallLater*   s    
 JLL{{1//a{88
/::4@@AAA+++&&&&&r   c                     t          j                    }|                    dd dd          }|                                 |                     |                                           dS )z3
        Test that calls can be cancelled.
        r+   c                     d S r   r    r-   s     r   r/   z3ClockTests.testCallLaterCancelled.<locals>.<lambda>:   r0   r   r1   r2   N)r   r$   r3   cancelassertFalser8   r9   s      r   testCallLaterCancelledz!ClockTests.testCallLaterCancelled5   s[     JLL{{1//a{88'''''r   c                     t          j                    }|                    dd dd          }|                    dd dd          }|                     ||u            d	S )
z[
        Test that the DelayedCall returned is not one previously
        created.
        
   c                     d S r   r    r-   s     r   r/   z3ClockTests.test_callLaterOrdering.<locals>.<lambda>D   s    T r   r+   r1   r2   c                     d S r   r    r-   s     r   r/   z3ClockTests.test_callLaterOrdering.<locals>.<lambda>E   s    D r         N)r   r$   r3   r?   )r   r(   call1call2s       r   test_callLaterOrderingz!ClockTests.test_callLaterOrdering>   sg    
 JLLB 1 11::A00!q99%(((((r   c                 `   g t          j                    }|                    dfd          }|                    d           |                     g            |                    d           |                     dg           |                     |                                           dS )zE
        Test that advancing the clock will fire some calls.
        r1   c                  .                          d           S r   append)eventss   r   r/   z(ClockTests.testAdvance.<locals>.<lambda>N   s    fmmD&9&9 r   r+   N)r   r$   r3   advancer%   r?   r8   r   r(   r:   rN   s      @r   testAdvancezClockTests.testAdvanceH   s     JLL{{19999::			!$$$			!$((('''''r   c                      t          j                    } fd}|                    d|          |                    d           dS )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.
        c                  R                         t          j         j                   d S r   )assertRaisesr   AlreadyCalledr>   )r:   r   s   r   cbz(ClockTests.testAdvanceCancel.<locals>.cb_   s$    e14;?????r   r+   N)r   r$   r3   rO   )r   r(   rV   r:   s   `  @r   testAdvanceCancelzClockTests.testAdvanceCancelU   s]     JLL	@ 	@ 	@ 	@ 	@ 	@ {{1b!!			!r   c                    g t          j                    }|                    dfddd          }|                    d           |                     |                                d           |                    d           |                     g            |                    d           |                     dg           dS )	z1
        Test that calls can be delayed.
        r+   c                 2                         | |f          S r   rL   r   r.   rN   s     r   r/   z1ClockTests.testCallLaterDelayed.<locals>.<lambda>k       6==!Q+@+@ r   r1   r2   g      ?      ?r+   r1   N)r   r$   r3   delayr%   r7   rO   rP   s      @r   testCallLaterDelayedzClockTests.testCallLaterDelayede   s     JLL{{1@@@@!q{II

1+++			#$$$			#&*****r   c                    g t          j                    }|                    dfddd          }|                    d           |                    d           |                     |                                d           |                    d           |                     g            |                    d           |                     dg           dS )	zL
        Test that calls can have their time reset to a later time.
        r1   c                 2                         | |f          S r   rL   rZ   s     r   r/   z4ClockTests.testCallLaterResetLater.<locals>.<lambda>y   r[   r   r+   r2   rE   rF   r]   N)r   r$   r3   rO   resetr%   r7   rP   s      @r   testCallLaterResetLaterz"ClockTests.testCallLaterResetLaters   s     JLL{{1@@@@!q{II			!

1+++			!$$$			!&*****r   c                 <   g t          j                    }|                    dfddd          }|                    d           |                     |                                d           |                    d           |                     dg           dS )	zO
        Test that calls can have their time reset to an earlier time.
        rF   c                 2                         | |f          S r   rL   rZ   s     r   r/   z5ClockTests.testCallLaterResetSooner.<locals>.<lambda>   r[   r   r+   r1   r2   rE   r]   N)r   r$   r3   rb   r%   r7   rO   rP   s      @r   testCallLaterResetSoonerz#ClockTests.testCallLaterResetSooner   s     JLL{{1@@@@!q{II

1+++			!&*****r   c                     t          j                    }|                    dd           }|                    dd           }|                                }|                     ||ht          |                     dS )zB
        Test that we can get a list of all delayed calls
        r+   c                     d S r   r    xs    r   r/   z1ClockTests.test_getDelayedCalls.<locals>.<lambda>        r   r1   c                     d S r   r    ri   s    r   r/   z1ClockTests.test_getDelayedCalls.<locals>.<lambda>   s     r   N)r   r$   r3   getDelayedCallsr%   set)r   r(   r:   rH   callss        r   test_getDelayedCallszClockTests.test_getDelayedCalls   sp     JLL{{1nn--A~~..!!##$E

33333r   c                 |    t          j                    }|                     |                                g            dS )zk
        Test that we get an empty list from getDelayedCalls on a newly
        constructed Clock.
        N)r   r$   r%   rm   r'   s     r   test_getDelayedCallsEmptyz$ClockTests.test_getDelayedCallsEmpty   s7    
 JLL**,,b11111r   c                     t          j                    }|                     t          j                            |          d           d S )Nz#Clock does not provide IReactorTime)r   r$   r4   r   IReactorTimer6   r'   s     r   test_providesIReactorTimez$ClockTests.test_providesIReactorTime   sD    JLL#..q113X	
 	
 	
 	
 	
r   c                 ,   g ddg}t          j                    fd}                    d|d          }|                    d                               d|d                               d	gd
z             |                     |           dS )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         @c                 V                         |                                 f          S r   rM   r&   nr   results    r   r/   z<ClockTests.test_callLaterKeepsCallsOrdered.<locals>.<lambda>        FMM1emmoo*>?? r   r\   r   rz   rx   r.   r+   rE   Nr   r$   r3   rb   pumpr%   r   expectedlogtimecall_ar   r   s       @@r   test_callLaterKeepsCallsOrderedz*ClockTests.test_callLaterKeepsCallsOrdered   s     
+
?????gs33SWc***

A37*****r   c                 ,   g ddg}t          j                    fd}                    d|d          }                    d|d           |                    d                               d	gd
z             |                     |           dS )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".
        rw   ry   c                 V                         |                                 f          S r   r|   r}   s    r   r/   zAClockTests.test_callLaterResetKeepsCallsOrdered.<locals>.<lambda>   r   r   r\   r   rx   r.   rz   r+   rE   Nr   r   s       @@r   $test_callLaterResetKeepsCallsOrderedz/ClockTests.test_callLaterResetKeepsCallsOrdered   s     
+
?????gs33Wc***S

A37*****r   c                 :   g ddg}t          j                    fd}                    d|d          fd}                    d|                               d|d	                               d
gdz             |                     |           dS )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(   rz   )r.   g      @c                 V                         |                                 f          S r   r|   r}   s    r   r/   zKClockTests.test_callLaterResetInsideCallKeepsCallsOrdered.<locals>.<lambda>   r   r   rx   r.   c                  2                          d           d S )Nrz   )rb   )call_bs   r   r   zDClockTests.test_callLaterResetInsideCallKeepsCallsOrdered.<locals>.a   s    LLr   r\   rz   r(         ?rB   N)r   r$   r3   r   r%   )r   r   r   r   r   r   r   s       @@@r   .test_callLaterResetInsideCallKeepsCallsOrderedz9ClockTests.test_callLaterResetInsideCallKeepsCallsOrdered   s     
+
?????gs33	 	 	 	 	 	QWc***

C52:*****r   N)r   r   r   __doc__r)   r;   r@   rI   rQ   rW   r_   rc   rf   rp   rr   ru   r   r   r   r    r   r   r"   r"      s         ) ) )	' 	' 	'( ( () ) )( ( (   + + ++ + +
+ 
+ 
+
4 
4 
42 2 2
 
 
+ + +0+ + +0+ + + + +r   r"   c                       e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )	LoopTestsz[
    Tests for L{task.LoopingCall} based on a fake L{IReactorTime}
    implementation.
    c                 p    t          j        d           }|                     |j        t                     dS )zG
        L{LoopingCall}'s default clock should be the reactor.
        c                      d S r   r    r    r   r   r/   z-LoopTests.test_defaultClock.<locals>.<lambda>   rk   r   N)r   LoopingCallr%   r   r   )r   r:   s     r   test_defaultClockzLoopTests.test_defaultClock   s4     --W-----r   c                 8   g dt          j                    fd}t          j        |          }|_        d|                    d           |                     dg           |                                                                                    d           |                     dg           d                    d           |                     ddg           |                                                     d                               d           |                     ddg           d                    d           |                     g d	           |                                                     d
           dS )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                                                                                                                      d S r   )rM   r&   rO   )callDurationr   timess   r   	aCallbackz3LoopTests.test_callbackTimeSkips.<locals>.aCallback  s5    LL)))MM,'''''r   r1   r   r   r+         @g      @)r   r   rF   rF   )r   r$   r   r   startr%   r&   rO   )r   r   r:   r   r   r   s      @@@r   test_callbackTimeSkipsz LoopTests.test_callbackTimeSkips   s    
	( 	( 	( 	( 	( 	( 	( 	**
 

3 	$$$ 	,777
 	a$$$ cC)))#... 	aC))) c,,,!,,,,,r   c                    g t          j                    fd}t          j        |          }|_        |                    d           |                     dg                               d           |                     ddg                               d           |                     g d                               d           |                     g d           dS )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.
        c                  V                                                                     d S r   r|   )r   r   s   r   r   z2LoopTests.test_reactorTimeSkips.<locals>.aCallback;  s#    LL)))))r   r   r   r1   r+   )r   r1   rE   N)r   r$   r   r   r   r%   rO   )r   r   r:   r   r   s      @@r   test_reactorTimeSkipszLoopTests.test_reactorTimeSkips1  s    
	* 	* 	* 	* 	* 	*
 	**


3 	$$$ 	aA''' 	a			*** 	a			*****r   c                 Z   g t          j                    fd}t           j                            |          }|_        d}d}|                    |           |                     dg                               ||z              |                     d||z   dfg                               d|z  |z              |                     d||z   dfd|z  d|z  z   dfg                               d	           |                     d||z   dfd|z  d|z  z   dfg           d
S )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.
        c                 Z                                                         | f           d S r   r|   )numCallsr   r   s    r   r   z7LoopTests.test_reactorTimeCountSkips.<locals>.aCallback_  s(    LL%--//8455555r   r   {Gz?r   r+   r+   rE   rF   r1   r   N)r   r$   r   	withCountr   r   r%   rO   r   r   r:   INTERVALREALISTIC_DELAYr   r   s        @@r   test_reactorTimeCountSkipsz$LoopTests.test_reactorTimeCountSkipsS  s    
	6 	6 	6 	6 	6 	6
 )))44


8 	)))
 	h0111(_*Da)H IJJJ 	q8|6777O+Q/h,1#67;	
 	
 	
 	aO+Q/h,1#67;	
 	
 	
 	
 	
r   c                    g t          j                    fd}t           j                            |          }|_        d}d}|                    |           |                                                     d                               ||z              |                                                     ||z   df                               |dz             |                                                     d|z  |z   df                               |dz             |                                                     d	|z  |z   df           d
S )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.
        c                 Z                                                         | f           d S r   r|   )countr   r   s    r   r   z<LoopTests.test_countLengthyIntervalCounts.<locals>.aCallback  s(    LL%--//5122222r   r   r   r   r+   g      ?g      @g      ?rz   N)	r   r$   r   r   r   r   r%   poprO   r   s        @@r   test_countLengthyIntervalCountsz)LoopTests.test_countLengthyIntervalCounts  s\    
	3 	3 	3 	3 	3 	3
 )))44


8f--- 	h0111x/'A1&EFFF 	ho&&&x?'JA&NOOO 	ho&&&h/'I1&MNNNNNr   c                    t          j                    }g }t           j                            |j                  }||_        d}d}||z  }|                    |d           t          |          D ]}|                    |           |t          |g|z            z
  }|                    |           |
                                }	|                     t          |          dk    | d           |                     |	|k    |	 d|            |                     t          |          |           |                     d|           d	S )
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.
        rB   r\   Fnowg        z should be greater than zeroz$ should be greater than or equal to r   N)r   r$   r   r   rM   r   r   rangerO   sumr&   r4   absr%   assertNotIn)
r   r   accumulatorr:   r   timespanintervalrj   epsilonsecondsValues
             r   #test_withCountFloatingPointBoundaryz-LoopTests.test_withCountFloatingPointBoundary  s]    
))+*<==

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

8
'''u 	$ 	$AMM(####
 S(e!3444g}} 	Gs*w,T,T,TUUU 	H$KKKK	
 	
 	

 	[))5111K(((((r   c                 J   t          j                    }g fd}t           j                            |          |_                            dd          }|                    dgdz             |                     |           |                     dgdz             dS )zy
        L{task.LoopingCall.withCount} with interval set to 0 calls the
        countCallable with a count of 1.
        c                                          |            t                    dk    r                                 d S d S )NrF   rM   lenstop)cntr   loops    r   fooz1LoopTests.test_withCountIntervalZero.<locals>.foo  sC    s###;!##		 $#r   r   Fr      r+   N)	r   r$   r   r   r   r   r   successResultOfr%   )r   r   r   deferredr   r   s       @@r   test_withCountIntervalZeroz$LoopTests.test_withCountIntervalZero  s    
 
	 	 	 	 	 	
 ))#..
::aU:++ 	

A37X&&&!q+.....r   c                 @   t          j                    }t          j                    g fd}t           j                            |          |_                            dd           |                    dgdz             | 	                    dgdz             |                    dgdz             | 	                    dgdz             
                    d           |                    dgdz             | 	                    dgd	z             dS )
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                    dk    rS t                    dk    r                                 d S d S )Nr1   rF   r   )r   r   r   r   s    r   r   z6LoopTests.test_withCountIntervalZeroDelay.<locals>.foo  s[    s###;1$$;!##		 $#r   r   Fr   r1   r+   NrF   r   )r   r$   r   Deferredr   r   r   r   r   r%   callback)r   r   r   r   r   r   s      @@@r   test_withCountIntervalZeroDelayz)LoopTests.test_withCountIntervalZeroDelay  s6    
>##	 	 	 	 	 	 	 ))#..


1%
   

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

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

A37!q+.....r   c                   	
 t          j                    }t          j                    
g 	dd}d}d}||z   }||z  }|dz  }	
fd}t           j                            |          }||_        |                    dd           |                    dg|z   z             | 	                    dgz  	           ||_
        
                    d	           |                    |           | 	                    dd|g	           |                    d|z             | 	                    dd|dg	           |                    d|z             | 	                    dd|ddg	           d	S )
z
        L{task.LoopingCall.withCount} with interval set to 0 will still keep
        the time when last called so when the interval is reset.
        r1   r   	   r+   c                 \                         |            t                    k    rS d S r   rM   r   )r   r   r   stepsBeforeDelays    r   r   zILoopTests.test_withCountIntervalZeroDelayThenNonZeroInterval.<locals>.fooV  s8    s###;#333 43r   r   Fr   N)r   r$   r   r   r   r   r   r   r   r%   r   r   rO   )r   r   extraTimeAfterDelaymutatedLoopIntervaldurationOfDelayskippedTimeexpectedSkipCountr   r   r   r   r   s            @@@r   2test_withCountIntervalZeroDelayThenNonZeroIntervalz<LoopTests.test_withCountIntervalZeroDelayThenNonZeroInterval,  s   
 
>## 
     
 *O; (+>> 	Q	  	  	  	  	  	  	 
 ))#..


1%
    	

A3*-@@ABBB!//=== ,$o&&&!Q 12K@@@a--...!Q 115{CCCa--...!Q 11a8+FFFFFr   c                    g d}t          j                    }g dfd	}t          ||ddd          }|                    d          }g fd}|                    |           |                    |           |                     t                    d	d
t                    fz             D ]^\  }}}	}
|                     |d           |                     |d           |                     |	           |                     |
d           _|	                                 | 
                    d         |           |                     |j                   d S )Ng?皙?r   c                 :                         | |||f           d S r   rL   )r   r.   r(   dLs       r   r   z(LoopTests.testBasicFunction.<locals>.foo  s#    HHaAq\"""""r   r   r.   r   r   r   c                 2                         |            d S r   rL   r   	theResults    r   
saveResultz/LoopTests.testBasicFunction.<locals>.saveResult      V$$$$$r   rE   zgot %d iterations, not 3r   )NN)r   r$   r   r   addCallbackr   r%   r   assertIsNoner   assertIsr?   ro   )r   timingsr   r   lcDr   r   r.   r(   r   r   r   s              @@r   testBasicFunctionzLoopTests.testBasicFunctionu  s   
 #""
	# 	# 	# 	# 	# 	# !S#===HHSMM		% 	% 	% 	% 	% 	
j!!!

7Q$>#a&&$JKKK 	% 	%LQ1aQ$$$Q$$$a   Q$$$$
			ilB''' 	%%%%%r   c                    g d}t          j                    }g }t          ||j        d           }|                    dd          }g fd}|                    |           |                    |           |                     t          |          ddt          |          fz             |	                                 | 
                    d         |           |                     |j                   d S )	Nr   r   Fr   c                 2                         |            d S r   rL   r   s    r   r   z.LoopTests.testDelayedStart.<locals>.saveResult  r   r   r1   zgot %d iterations, not 2r   )r   r$   r   rM   r   r   r   r%   r   r   r   r?   ro   )r   r   r   r   r   r   r   r   s          @r   testDelayedStartzLoopTests.testDelayedStart  s    """
 $77HHSeH$$		% 	% 	% 	% 	% 	
j!!!

7Q$>#a&&$JKKK
			ilB'''%%%%%r   c                 r    t          j        d           }|                     t          |j        d           d S )Nc                      d S r   r    r    r   r   r/   z(LoopTests.testBadDelay.<locals>.<lambda>  s    d r   )r   r   rT   
ValueErrorr   )r   r   s     r   testBadDelayzLoopTests.testBadDelay  s4    ll++*bh33333r   c                    g fd}t          j                    }t          ||          }|                    |d           |                                 |                                |                     |j                   d S )Nc                  2                          d            d S r   rL   rans   r   r   z$LoopTests._stoppingTest.<locals>.foo      JJtr   Fr   )r   r$   r   r   r   r?   ro   )r   r^   r   r   r   r   s        @r   _stoppingTestzLoopTests._stoppingTest  s    	 	 	 	 	 
 ,,
E"""
			%%%%%r   c                 ,    |                      d          S )Nr   r   r   s    r   testStopAtOncezLoopTests.testStopAtOnce  s    !!!$$$r   c                 ,    |                      d          S )NrB   r   r   s    r   testStoppingBeforeDelayedStartz(LoopTests.testStoppingBeforeDelayedStart  s    !!"%%%r   c                    g fd}t          j                    }t          ||          }|                    dd           |                    d           |                                 |                    d           |                     g            |                    d           |                     dg           dS )z8
        Test that L{LoopingCall} can be reset.
        c                  2                          d            d S r   rL   r   s   r   r   z!LoopTests.test_reset.<locals>.foo  r   r   r1   Fr   r+   N)r   r$   r   r   rO   rb   r%   )r   r   r(   r   r   s       @r   
test_resetzLoopTests.test_reset  s     	 	 	 	 	 JLL C((
			!



			!b!!!			!tf%%%%%r   c           	          |                      t          t          j        t          dd                    d           dS )zO
        L{LoopingCall.__repr__} includes the wrapped function's name.
        r+   r1   )keyz6LoopingCall<None>(installReactor, *(1,), **{'key': 2})N)r%   reprr   r   r   r   s    r   test_reprFunctionzLoopTests.test_reprFunction  sF     	!.!;;;<<D	
 	
 	
 	
 	
r   c                     |                      t          t          j        t          j                            d           dS )zR
        L{LoopingCall.__repr__} includes the wrapped method's full name.
        z:LoopingCall<None>(TestableLoopingCall.__init__, *(), **{})N)r%   r  r   r   r   r   r   s    r   test_reprMethodzLoopTests.test_reprMethod  sC     	!"5">??@@H	
 	
 	
 	
 	
r   c                 P   t          j        d           }|j         d}|                     | j        g          }|                     dt          |                     |                     t          |d         d                    |                     ||d         d                    dS )z8
        L{LoopingCall.deferred} is deprecated.
        c                      d S r   r    r    r   r   r/   z4LoopTests.test_deferredDeprecation.<locals>.<lambda>  rk   r   ztwisted.internet.task.LoopingCall.deferred was deprecated in Twisted 16.0.0; please use the deferred returned by start() insteadr+   r   categorymessageN)r   r   r   flushWarningstest_deferredDeprecationr%   r   DeprecationWarning)r   r   r  warningss       r   r  z"LoopTests.test_deferredDeprecation  s     --B 	
 %%t'D&EFFCMM***+Xa[-DEEE(1+i"899999r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r
  r  r    r   r   r   r      sL        
. . .2- 2- 2-h +  +  +D8
 8
 8
t'O 'O 'OR4) 4) 4)l/ / /4$/ $/ $/LGG GG GGR&& && &&P& & &04 4 4
& & &% % %& & && & &&
 
 

 
 
: : : : :r   r   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
ReactorLoopTestsc                     d }t          j        |d          }|                     |                    d          t                    S )Nc                      t          |           r   r   ri   s    r   r   z)ReactorLoopTests.testFailure.<locals>.foo	  s    """r   barr   r   r   assertFailurer   r   r   r   r   s      r   testFailurezReactorLoopTests.testFailure  sE    	# 	# 	# c5))!!"((3--???r   c                     fd}t          j        |d          |                                         d          t                    S )Nc                 J                                      t          |           r   )r   r   )rj   r   s    r   r   z-ReactorLoopTests.testFailAndStop.<locals>.foo  s    GGIII"""r   r  r   r  r  s     @r   testFailAndStopz ReactorLoopTests.testFailAndStop  sP    	# 	# 	# 	# 	# c5))!!"((3--???r   c                      g fd}t          j        |                              d          } fd}|                    |          S )Nc                                           d            t                    dk    r                                  d S d S )Nr   r   )r   r   s   r   r   z0ReactorLoopTests.testEveryIteration.<locals>.foo  s<    JJt3xx!||					 |r   r   c                 N                         t                    d           d S )N   )r%   r   )ignr   r   s    r   stoppedz4ReactorLoopTests.testEveryIteration.<locals>.stopped"  s%    SXXq)))))r   )r   r   r   r   )r   r   r   r%  r   r   s   `   @@r   testEveryIterationz#ReactorLoopTests.testEveryIteration  s{    	 	 	 	 	 	
 c""HHQKK	* 	* 	* 	* 	* 	* }}W%%%r   c                     t          j                    fd}t          j        |          | _        | j                            dd           t          j        d| j                   S )Nc                  V                          t          j        d                     d S )Nz'This task also should never get called.)errbackr   DefaultExceptionr   s   r   r   z1ReactorLoopTests.testStopAtOnceLater.<locals>.foo,  s2    II()RSS    r   r+   Fr   r   )	r   r   r   r   _lcr   r   r3   !_callback_for_testStopAtOnceLater)r   r   r   s     @r   testStopAtOnceLaterz$ReactorLoopTests.testStopAtOnceLater'  st     N	 	 	 	 	
 #C((qe$$$!TCQGGGr   c                 n    | j                                          t          j        d|j        d           d S )Nr   success)r+  r   r   r3   r   )r   r   s     r   r,  z2ReactorLoopTests._callback_for_testStopAtOnceLater6  s.    !QZ33333r   c                     ddg}t          j                    fd}t          |                              d                               |           |                     j                   d S )N皙?g?c                      t          j                    } |                     fd                               d| j        d            | S )Nc                 ,                                     S r   )r   )_r   s    r   r/   z@ReactorLoopTests.testWaitDeferred.<locals>.foo.<locals>.<lambda>B  s    BGGII r   r+   )r   r   r   r3   r   )r   r   r   s    r   r   z.ReactorLoopTests.testWaitDeferred.<locals>.foo@  sI      AMM----...OOAqz4000Hr   )r   r$   r   r   r   r?   ro   )r   r   r   r   r   s      @@r   testWaitDeferredz!ReactorLoopTests.testWaitDeferred:  s     *
	 	 	 	 	 	 !,,


7%%%%%r   c                    dg}t          j                    fd}t          |          }|                    d          }|                     |t
                                         |           |                     j                   |S )N333333?c                  ~    t          j                    }                     d| j        t	                                 | S )Nr7  )r   r   r3   r)  r   )r   r   s    r   r   z4ReactorLoopTests.testFailurePropagation.<locals>.fooU  s1      AOOCMOO<<<Hr   r+   )	r   r$   r   r   r  r   r   r?   ro   )r   r   r   r   r   r   s        @r   testFailurePropagationz'ReactorLoopTests.testFailurePropagationK  s     %
	 	 	 	 	
 !,,HHQKK1m,,,

7%%%r   c                 L   t          j                    }t          j                    g fd}t           j                            |          }||_        |                    dd          |                     g            |	                    ddg           |                     t                    d                               d           |	                    dg           |                     t                    d           |                     dd	g           dS )
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                 \                         |            t                    dk    rS d S Nr+   r   )possibleCountr   deferredCountss    r   countTrackerz=ReactorLoopTests.test_deferredWithCount.<locals>.countTrackern  s4    !!-000>""a''tr   r1  Fr   g?r+   Nr1   rE   )r   r$   r   r   r   r   r   r   r%   r   r   r   )r   	testClockr?  r   r   r>  s       @@r   test_deferredWithCountz'ReactorLoopTests.test_deferredWithCountb  s+    JLL	N	 	 	 	 	 	 ''55HHSeH$$ 	,,, 	Sz"""^,,a000 	


4u^,,a000 	!Q00000r   N)r   r   r   r  r  r&  r-  r,  r5  r9  rA  r    r   r   r  r    s        @ @ @@ @ @& & &   4 4 4& & &"  .*1 *1 *1 *1 *1r   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )DeferLaterTestsz'
    Tests for L{task.deferLater}.
    c                 r   g t                      fd}t          j                    }t          j        |d|dd          }|                    | j                   |                    d           |                     g            |                    d           |                     dg           |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                 6                         | |f           S r   rL   )r   r  flagresultss     r   callablez/DeferLaterTests.test_callback.<locals>.callable  s    NNC:&&&Kr   rE   r   r  )r  r1   r+   )r   r  )objectr   r$   
deferLaterr   r   rO   r%   )r   rH  r   r   rF  rG  s       @@r   test_callbackzDeferLaterTests.test_callback  s    
 xx	 	 	 	 	 	 
OE1h5AAA	dmT***a"%%%a>"2333r   c                     d }t          j                    }t          j        |d|          }|                    d           |                     |t
                    S )z
        The L{Deferred} returned by L{task.deferLater} is errbacked if the
        supplied function raises an exception.
        c                      t                      r   r  r    r   r   rH  z.DeferLaterTests.test_errback.<locals>.callable  s    //!r   r+   )r   r$   rJ  rO   r  r   )r   rH  r   r   s       r   test_errbackzDeferLaterTests.test_errback  sY    	" 	" 	" 
OE1h//a!!!]333r   c                     g t          j                    t          j        dj        d          }|                                  fd}                     |t          j                   |                    |           |S )z
        The L{Deferred} returned by L{task.deferLater} can be
        cancelled to prevent the call from actually being performed.
        r+   Nc                                          g                                                                           d S r   )r%   rm   r?   )ignoredcalledr   r   s    r   cbCancelledz0DeferLaterTests.test_cancel.<locals>.cbCancelled  s?    R!6!6!8!8999V$$$$$r   )	r   r$   rJ  rM   r>   r  r   CancelledErrorr   )r   r   rS  rR  r   s   `  @@r   test_cancelzDeferLaterTests.test_cancel  s    
 
OE1fmT::	


	% 	% 	% 	% 	% 	% 	% 	1e2333	k"""r   c                     t          j                    }t          j        |d          }|                     |           |                    d           |                     d|                     |                     dS )z
        The L{Deferred} returned by L{task.deferLater} fires with C{None}
        when no callback function is passed.
        rx   N)r   r$   rJ  assertNoResultrO   r   r   )r   r   r   s      r   test_noCallbackzDeferLaterTests.test_noCallback  sn    
 
OE3''AcdD003344444r   N)r   r   r   r   rK  rN  rU  rX  r    r   r   rC  rC    sZ           *4 4 4  (
5 
5 
5 
5 
5r   rC  c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )_FakeReactorc                     d| _         t          j                    | _        | j        j        | _        | j        j        | _        | j        j        | _        g | _        g g d| _        d S )NFbeforeduring)	_runningr   r$   _clockr3   r&   rm   _whenRunning_shutdownTriggersr   s    r   r   z_FakeReactor.__init__  sY    jll.{*#{:,."!=!=r   c                 b    | j         
 ||i | d S | j                             |||f           d S r   )ra  rM   )r   rH  argskwargss       r   callWhenRunningz_FakeReactor.callWhenRunning  sJ    $Hd%f%%%%%$$hf%=>>>>>r   c                 f    |dv sJ |dk    sJ | j         |                             ||f           d S )Nr\  shutdown)rb  rM   )r   phaseeventrH  rd  s        r   addSystemEventTriggerz"_FakeReactor.addSystemEventTrigger  sL    ,,,,,
""""u%,,h-=>>>>>r   c                    d| _         | j        }d| _        |D ]\  }}} ||i | | j         rs|                                 }|st          d          | j                            |d                                         |                                 z
             | j         s| j        }d| _        |d         |d         z   D ]
\  }} ||  dS )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_  ra  rm   RuntimeErrorr`  rO   r7   r&   rb  )r   whenRunningrH  rd  re  ro   shutdownTriggerstriggers           r   runz_FakeReactor.run  s	    ' &1 	& 	&"HdFHd%f%%%%m 	E((**E ;"#9:::Ka 0 0 2 2T\\^^ CDDD	 m 	E
  1!%/9<LX<VV 	 	OWdGTNNN	 	r   c                 H    | j         st          j                    d| _         dS )z#
        Stop the reactor.
        FN)r_  r   ReactorNotRunningr   s    r   r   z_FakeReactor.stop  s(     } 	,)+++r   N)r   r   r   r   rf  rk  rq  r   r    r   r   rZ  rZ    s_        > > >? ? ?? ? ?
  ,    r   rZ  c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )
ReactTestsz3
    Tests for L{twisted.internet.task.react}.
    c                 6   g fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     dg           |                     |                                d           dS )
        L{task.react} runs the reactor until the L{Deferred} returned by the
        function it is passed is called back, then stops it.
        c                     t          j                    } | j        dj        d            | j        d|j        d            |S Nr+   Tr1   r   r   r3   rM   r   r   finished
timePasseds     r   mainz4ReactTests.test_runsUntilAsyncCallback.<locals>.main  sI    ~''HGa!2D999Ga!2D999Or   _reactorr   Tr1   NrZ  rT   
SystemExitr   reactr%   coder&   r   r~  r	exitErrorr}  s       @r   test_runsUntilAsyncCallbackz&ReactTests.test_runsUntilAsyncCallback  s    
 
	 	 	 	 	 NN%%j$*dQ%OO	IN+++dV,,,a(((((r   c                     d }t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           dS )
        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                 *    t          j        d           S r   r   succeedr   s    r   r~  z3ReactTests.test_runsUntilSyncCallback.<locals>.main+  s    =&&&r   r  r   Nr  r   r~  r  r  s       r   test_runsUntilSyncCallbackz%ReactTests.test_runsUntilSyncCallback$  sv    	' 	' 	' NN%%j$*dQ%OO	IN+++a(((((r   c                 J    G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                               }|                     t          |          d           dS )
        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                       e Zd ZdS )@ReactTests.test_runsUntilAsyncErrback.<locals>.ExpectedExceptionNr   r    r   r   ExpectedExceptionr  :          Dr   r  c                 l    t          j                    } | j        d|j                                |S r<  r   r   r3   r)  r   r|  r  s     r   r~  z3ReactTests.test_runsUntilAsyncErrback.<locals>.main=  s9    ~''HGa!13D3D3F3FGGGOr   r  r+   N
	ExceptionrZ  rT   r  r   r  r%   r  flushLoggedErrorsr   r   r~  r  r  errorsr  s        @r   test_runsUntilAsyncErrbackz%ReactTests.test_runsUntilAsyncErrback3  s    	 	 	 	 		 	 	 		 	 	 	 	
 NN%%j$*dQ%OO	IN+++''(9::Va(((((r   c                     G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           | 	                              }|                     t          |          d           dS )
        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                       e Zd ZdS )?ReactTests.test_runsUntilSyncErrback.<locals>.ExpectedExceptionNr   r    r   r   r  r  Q  r  r   r  c                 <    t          j                               S r   r   failr   r  s    r   r~  z2ReactTests.test_runsUntilSyncErrback.<locals>.mainT  s    ://11222r   r  r+   r   Nr  rZ  rT   r  r   r  r%   r  r&   r  r   r  s        @r   test_runsUntilSyncErrbackz$ReactTests.test_runsUntilSyncErrbackJ  s    	 	 	 	 		 	 	 		3 	3 	3 	3 	3 NN%%j$*dQ%OO	IN+++a(((''(9::Va(((((r   c                     d }t                      }|                     t          t          j        ||          }|                     |                                d           |                     d|j                   dS )
        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                      | j         d| j                   t          j                    } | j        dd|j        d            |S Nr+   r^  rh  r3   r   r   r   rk  r   r   r|  s     r   r~  z0ReactTests.test_singleStopCallback.<locals>.maine  sH    Ga...~''H)G)(J@QSWXXXOr   r  r+   r   NrZ  rT   r  r   r  r%   r&   r  r  s       r   test_singleStopCallbackz"ReactTests.test_singleStopCallback^  sv    	 	 	 NN%%j$*dQ%OO	a(((IN+++++r   c                     G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           | 	                              }|                     t          |          d           dS )
        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                       e Zd ZdS )<ReactTests.test_singleStopErrback.<locals>.ExpectedExceptionNr   r    r   r   r  r  x  r  r   r  c                      | j         d| j                   t          j                    } | j        dd|j                                |S r  r3   r   r   r   rk  r)  r  s     r   r~  z/ReactTests.test_singleStopErrback.<locals>.main{  s[    Ga...~''H)G)*h&68I8I8K8K   Or   r  r+   Nr  r  s        @r   test_singleStopErrbackz!ReactTests.test_singleStopErrbackq  s    	 	 	 	 		 	 	 		 	 	 	 	 NN%%j$*dQ%OO	IN+++a(((''(9::Va(((((r   c                     g fd}t                      }|                     t          t          j        |g d|          }|                     d|j                   |                     g d           dS )
        L{task.react} passes the elements of the list it is passed as
        positional arguments to the function it is passed.
        c                 \                         |||f           t          j        d           S r   extendr   r  r   rj   yzrd  s       r   r~  z'ReactTests.test_arguments.<locals>.main  s+    KKAq	"""=&&&r   r+   r1   rE   r  r   NrZ  rT   r  r   r  r%   r  r   r~  r  r  rd  s       @r   test_argumentszReactTests.test_arguments  s    
 	' 	' 	' 	' 	' NN%%
D)))a & 
 
	 	IN+++yyy)))))r   c                 R     fd}t                      }t                      5  t          |                                t          t
          j        |g           }                     d|j                   ddd           n# 1 swxY w Y    	                    | j
                   dS )p
        L{twisted.internet.reactor} is used if no reactor argument is passed to
        L{task.react}.
        c                 :    | _         t          j        d           S r   passedReactorr   r  r   r   s    r   r~  z,ReactTests.test_defaultReactor.<locals>.main  s    !(D=&&&r   r   NrZ  r	   r   rT   r  r   r  r%   r  r   r  r   r~  r   r  s   `   r   test_defaultReactorzReactTests.test_defaultReactor  s    	' 	' 	' 	' 	' ..[[ 	0 	07###))*dj$KKIQ	///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	gt122222   ABBBc                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )
        L{task.react} forwards the exit code specified by the C{SystemExit}
        error returned by the passed function, if any.
        c                 D    t          j        t          d                    S N   r   r  r  r  s    r   r~  z1ReactTests.test_exitWithDefinedCode.<locals>.main  s    :jnn---r   r  r  Nr  r  s       r   test_exitWithDefinedCodez#ReactTests.test_exitWithDefinedCode  s[    	. 	. 	. NN%%j$*dBQR%SS	Y^,,,,,r   c                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )w
        L{task.react} handles when the reactor is stopped just before the
        returned L{Deferred} fires.
        c                 \     t          j                     fd}  j        |           S )Nc                  P     j                                           d            d S r   r   r   r   r   s   r   r   z;ReactTests.test_synchronousStop.<locals>.main.<locals>.stop  (    

4     r   r   r   rf  r   r   r   s   ` @r   r~  z-ReactTests.test_synchronousStop.<locals>.main  sI      A! ! ! ! ! ! $G#D)))Hr   r  r   Nr  r  s       r   test_synchronousStopzReactTests.test_synchronousStop  s[    	 	 	 NN%%j$*dBQR%SS	IN+++++r   c                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )v
        L{task.react} handles when the reactor is stopped and the
        returned L{Deferred} doesn't fire.
        c                 T     | j         d| j                   t          j                    S r<  r3   r   r   r   r  s    r   r~  z.ReactTests.test_asynchronousStop.<locals>.main  s'    Ga...>###r   r  r   Nr  r  s       r   test_asynchronousStopz ReactTests.test_asynchronousStop  s[    	$ 	$ 	$ NN%%j$*dBQR%SS	IN+++++r   Nr   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r    r   r   ru  ru             ) ) )&) ) )) ) ).) ) )(, , ,&) ) )6* * *$3 3 3"- - -, , ,(, , , , ,r   ru  c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )ReactCoroutineFunctionTestszP
    Tests for L{twisted.internet.task.react} with an C{async def} argument
    c                 6   g fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     dg           |                     |                                d           dS )rw  c                    K   t          j                    } | j        dj        d            | j        d|j        d            | d {V S ry  rz  r{  s     r   r~  zEReactCoroutineFunctionTests.test_runsUntilAsyncCallback.<locals>.main  sZ      ~''HGa!2D999Ga!2D999!>>>>>>!r   r  r   Tr1   Nr  r  s       @r   r  z7ReactCoroutineFunctionTests.test_runsUntilAsyncCallback  s    
 
	" 	" 	" 	" 	" NN%%j$*dQ%OO	IN+++dV,,,a(((((r   c                     d }t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           dS )r  c                 :   K   t          j        d            d {V S r   r  r  s    r   r~  zDReactCoroutineFunctionTests.test_runsUntilSyncCallback.<locals>.main  s(      t,,,,,,,,,r   r  r   Nr  r  s       r   r  z6ReactCoroutineFunctionTests.test_runsUntilSyncCallback  sv    	- 	- 	- NN%%j$*dQ%OO	IN+++a(((((r   c                 J    G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                               }|                     t          |          d           dS )r  c                       e Zd ZdS )QReactCoroutineFunctionTests.test_runsUntilAsyncErrback.<locals>.ExpectedExceptionNr   r    r   r   r  r    r  r   r  c                 |   K   t          j                    } | j        d|j                                | d {V S r<  r  r  s     r   r~  zDReactCoroutineFunctionTests.test_runsUntilAsyncErrback.<locals>.main  sJ      ~''HGa!13D3D3F3FGGG!>>>>>>!r   r  r+   Nr  r  s        @r   r  z6ReactCoroutineFunctionTests.test_runsUntilAsyncErrback  s    	 	 	 	 		 	 	 		" 	" 	" 	" 	"
 NN%%j$*dQ%OO	IN+++''(9::Va(((((r   c                     G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           | 	                              }|                     t          |          d           dS )r  c                       e Zd ZdS )PReactCoroutineFunctionTests.test_runsUntilSyncErrback.<locals>.ExpectedExceptionNr   r    r   r   r  r  $  r  r   r  c                 L   K   t          j                                d {V S r   r  r  s    r   r~  zCReactCoroutineFunctionTests.test_runsUntilSyncErrback.<locals>.main'  s3      $5$5$7$7888888888r   r  r+   r   Nr  r  s        @r   r  z5ReactCoroutineFunctionTests.test_runsUntilSyncErrback  s    	 	 	 	 		 	 	 		9 	9 	9 	9 	9 NN%%j$*dQ%OO	IN+++a(((''(9::Va(((((r   c                     d }t                      }|                     t          t          j        ||          }|                     |                                d           |                     d|j                   dS )r  c                    K    | j         d| j                   t          j                    } | j        dd|j        d            | d {V S r  r  r  s     r   r~  zAReactCoroutineFunctionTests.test_singleStopCallback.<locals>.main8  sY      Ga...~''H)G)(J@QSWXXX!>>>>>>!r   r  r+   r   Nr  r  s       r   r  z3ReactCoroutineFunctionTests.test_singleStopCallback1  sv    	" 	" 	" NN%%j$*dQ%OO	a(((IN+++++r   c                     G d dt                     fd}t                      }|                     t          t          j        ||          }|                     d|j                   |                     |                                d           | 	                              }|                     t          |          d           dS )r  c                       e Zd ZdS )MReactCoroutineFunctionTests.test_singleStopErrback.<locals>.ExpectedExceptionNr   r    r   r   r  r  K  r  r   r  c                    K    | j         d| j                   t          j                    } | j        dd|j                                | d {V S r  r  r  s     r   r~  z@ReactCoroutineFunctionTests.test_singleStopErrback.<locals>.mainN  sl      Ga...~''H)G)*h&68I8I8K8K   ">>>>>>!r   r  r+   Nr  r  s        @r   r  z2ReactCoroutineFunctionTests.test_singleStopErrbackD  s    	 	 	 	 		 	 	 		" 	" 	" 	" 	" NN%%j$*dQ%OO	IN+++a(((''(9::Va(((((r   c                     g fd}t                      }|                     t          t          j        |g d|          }|                     d|j                   |                     g d           dS )r  c                 l   K                        |||f           t          j        d            d {V S r   r  r  s       r   r~  z8ReactCoroutineFunctionTests.test_arguments.<locals>.mainf  sA      KKAq	"""t,,,,,,,,,r   r  r  r   Nr  r  s       @r   r  z*ReactCoroutineFunctionTests.test_arguments_  s    
 	- 	- 	- 	- 	- NN%%
D)))a & 
 
	 	IN+++yyy)))))r   c                 R     fd}t                      }t                      5  t          |                                t          t
          j        |g           }                     d|j                   ddd           n# 1 swxY w Y    	                    | j
                   dS )r  c                 J   K   | _         t          j        d            d {V S r   r  r  s    r   r~  z=ReactCoroutineFunctionTests.test_defaultReactor.<locals>.mainw  s1      !(Dt,,,,,,,,,r   r   Nr  r  s   `   r   r  z/ReactCoroutineFunctionTests.test_defaultReactorq  s    	- 	- 	- 	- 	- ..[[ 	0 	07###))*dj$KKIQ	///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	gt122222r  c                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )r  c                 T   K   t          j        t          d                     d {V S r  r  r  s    r   r~  zBReactCoroutineFunctionTests.test_exitWithDefinedCode.<locals>.main  s.      JrNN333333333r   r  r  Nr  r  s       r   r  z4ReactCoroutineFunctionTests.test_exitWithDefinedCode  s[    	4 	4 	4 NN%%j$*dBQR%SS	Y^,,,,,r   c                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )r  c                 l    K   t          j                     fd}  j        |            d {V S )Nc                  P     j                                           d            d S r   r  r  s   r   r   zLReactCoroutineFunctionTests.test_synchronousStop.<locals>.main.<locals>.stop  r  r   r  r  s   ` @r   r~  z>ReactCoroutineFunctionTests.test_synchronousStop.<locals>.main  sY        A! ! ! ! ! ! $G#D)))777777Nr   r  r   Nr  r  s       r   r  z0ReactCoroutineFunctionTests.test_synchronousStop  s[    	 	 	 NN%%j$*dBQR%SS	IN+++++r   c                     d }t                      }|                     t          t          j        |g |          }|                     d|j                   dS )r  c                 d   K    | j         d| j                   t          j                     d {V S r<  r  r  s    r   r~  z?ReactCoroutineFunctionTests.test_asynchronousStop.<locals>.main  s=      Ga...)))))))))r   r  r   Nr  r  s       r   r  z1ReactCoroutineFunctionTests.test_asynchronousStop  s[    	* 	* 	* NN%%j$*dBQR%SS	IN+++++r   Nr  r    r   r   r  r    r  r   r  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  rC  rZ  SynchronousTestCaseru  r  r    r   r   <module>r     s\   
 E D D D D D D D D D D D D D 0 0 0 0 0 0 9 9 9 9 9 9 " " " " " " 	
 " " " " " "    $*   	 	 	 	 	I 	 	 	O+ O+ O+ O+ O+" O+ O+ O+dR: R: R: R: R:! R: R: R:jG1 G1 G1 G1 G1x( G1 G1 G1TF5 F5 F5 F5 F5h' F5 F5 F5R1 1 1 1 1 1 1 1hP, P, P, P, P,- P, P, P,fP, P, P, P, P,("> P, P, P, P, P,r   