+
    Dfj[S                         R t ^ RIHtHtHt ^ RIHt  ! R R4      t ! R R4      t ! R R]P                  4      t
 ! R	 R
]4      t ! R R]P                  4      t ! R R]P                  4      tR# )z_
This module contains tests for L{twisted.internet.task.Cooperator} and
related functionality.
)deferreactortask)unittestc                   0   a  ] tR t^t o RtR tR tRtV tR# )FakeDelayedCallz9
Fake delayed call which lets us simulate the scheduler.
c                     Wn         RV n        R# )z
A function to run, later.
FN)func	cancelledselfr	   s   &&>/usr/lib/python3/dist-packages/twisted/test/test_cooperator.py__init__FakeDelayedCall.__init__   s     	    c                    RV n         R# )z
Don't run my function later.
TN)r
   r   s   &r   cancelFakeDelayedCall.cancel   s     r   )r
   r	   N)	__name__
__module____qualname____firstlineno____doc__r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s      r   r   c                   6   a  ] tR t^!t o RtR tR tR tRtV t	R# )FakeSchedulerz'
A fake scheduler for testing against.
c                    . V n         R# )z4
Create a fake scheduler with a list of work to do.
Nworkr   s   &r   r   FakeScheduler.__init__&   s     	r   c                R    \        V4      pV P                  P                  V4       V# )z+
Schedule a unit of work to be done later.
)r   r"   append)r   thunkunits   && r   __call__FakeScheduler.__call__,   s%     u%		r   c                    V P                   . uqn         V F'  pVP                  '       d   K  VP                  4        K)  	  R# )z<
Do all of the work that is currently available to be done.
N)r"   r
   r	   )r   r"   r'   s   &  r   pumpFakeScheduler.pump4   s/     ))RiD>>>		 r   r!   N)
r   r   r   r   r   r   r(   r+   r   r   r   s   @r   r   r   !   s      r   r   c                      a  ] tR t^>t o RtR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tRtV tR# )CooperatorTestsdonec                X    VP                  \        P                  4       V P                  # N)trapr   SchedulerStoppedRESULT)r   errs   &&r   ebIterCooperatorTests.ebIterA   s    &&'{{r   c                &    V P                  4        R # r1   )fail)r   igns   &&r   cbIterCooperatorTests.cbIterE   s    		r   c                H   a a V 3R loS! R4      P                  V3R l4      # )zE
Test that Cooperators refuse new tasks when they have been stopped.
c                   < \         P                  ! 4       pVP                  4        VP                  \	        R4      V 4      pVP                  SP                  4       VP                  SP                  4       VP                  V3R  l4      # )c                 <   < SP                  V SP                  4      # r1   assertEqualr4   resultr   s   &r   <lambda>NCooperatorTests.testStoppedRejectsNewTasks.<locals>.testwith.<locals>.<lambda>S   s    0@0@0Ur    )	r   
Cooperatorstop	coiterateiteraddCallbackr;   
addErrbackr6   )stuffcdr   s   &  r   testwith<CooperatorTests.testStoppedRejectsNewTasks.<locals>.testwithM   s\    !AFFHDHe,AMM$++&LL%==!UVVr   Nc                 :   < S! \         P                  ! 4       4      # r1   )r   Deferred)r:   rP   s   &r   rD   <CooperatorTests.testStoppedRejectsNewTasks.<locals>.<lambda>U   s    hu~~?O6Pr   )rK   )r   rP   s   f@r   testStoppedRejectsNewTasks*CooperatorTests.testStoppedRejectsNewTasksH   s!    
	W ~))*PQQr   c                0  a a \         P                  ! 4       pR oRSn        VP                  S! 4       4      pVP	                  S P
                  4       VP                  S P                  4       VP                  4        VV 3R lpVP	                  V4       V# )zY
Test that a running iterator will not run to completion when the
cooperator is stopped.
c               3   8   "   \        ^4       Rj  xL
  R#  L5i)   N)rangerF   r   r   myiter/CooperatorTests.testStopRunning.<locals>.myiter^   s     Qxs   c                 x   < SP                  V SP                  4       SP                  SP                  R4       R# )   N)rA   r4   value)rC   r[   r   s   &r   	doasserts2CooperatorTests.testStopRunning.<locals>.doassertsg   s+    VT[[1V\\2.r   r_   )	r   rG   r`   rI   rK   r;   rL   r6   rH   )r   rN   rO   ra   r[   s   f   @r   testStopRunningCooperatorTests.testStopRunningW   sp    
 OO	  KK!	dkk"	T[[!		/ 	
i r   c                  a aaa \         P                  ! 4       o\         P                  ! 4       oVV V3R lp\        P                  ! 4       oSP	                  V! 4       4      pVV3R lpSP                  V4       VP                  S P                  4       VP                  S P                  4       VP                  V 3R l4      # )z
An iterator run with L{Cooperator.coiterate} paused on a L{Deferred}
yielded by that iterator will fire its own L{Deferred} (the one
returned by C{coiterate}) when L{Cooperator.stop} is called.
c               3   |   <"   \         P                  ! ^ SP                  R4       S x  SP                  4        R# 5i    N)r   	callLatercallbackr9   )outstandingDr   testControlDs   r   r[   3CooperatorTests.testStopOutstanding.<locals>.myiterw   s-     a!6!6=IIKs   9<c                 J   < SP                  4        SP                  R 4       R# )arglebargleN)rH   rj   )r:   rN   rk   s   &r   	stopAndGo6CooperatorTests.testStopOutstanding.<locals>.stopAndGo   s    FFH!!-0r   c                 <   < SP                  V SP                  4      # r1   r@   rB   s   &r   rD   5CooperatorTests.testStopOutstanding.<locals>.<lambda>   s    D,<,<VT[[,Qr   )	r   rS   r   rG   rI   rK   r;   rL   r6   )r   r[   rO   rp   rN   rk   rl   s   f   @@@r   testStopOutstanding#CooperatorTests.testStopOutstandingn   s     ~~'~~'	
 OOKK!	1 	  +	dkk"	T[[!}}QRRr   c                    \         P                  ! 4       pR  pVP                  V! 4       4      pV P                  V\        4      # )c               3       "    \        4       h5i)F)RuntimeErrorrF   r   r   r[   3CooperatorTests.testUnexpectedError.<locals>.myiter   s      #n$s   r   rG   rI   assertFailurerx   )r   rN   r[   rO   s   &   r   testUnexpectedError#CooperatorTests.testUnexpectedError   s8    OO	% KK!!!!\22r   c                    R  p\         P                  ! 4       pVP                  V! 4       4      pV P                  V\        4      # )c               3      "   \         P                  ! 4       p \        P                  ! ^ V P                  \        4       4       V x  R# 5irg   )r   rS   r   ri   errbackrx   )Ds    r   r[   @CooperatorTests.testUnexpectedErrorActuallyLater.<locals>.myiter   s.      AaLN;Gs   AArz   r   r[   rN   rO   s   &   r    testUnexpectedErrorActuallyLater0CooperatorTests.testUnexpectedErrorActuallyLater   s8    	
 OOKK!!!!\22r   c                    R  p\         P                  ! 4       pVP                  V! 4       4      pV P                  V\        4      # )c               3   N   "   \         P                  ! \        4       4      x  R # 5ir1   )r   r9   rx   rF   r   r   r[   CCooperatorTests.testUnexpectedErrorNotActuallyLater.<locals>.myiter   s     **\^,,s   #%rz   r   s   &   r   #testUnexpectedErrorNotActuallyLater3CooperatorTests.testUnexpectedErrorNotActuallyLater   s8    	- OOKK!!!!\22r   c                  a aa . oV3R  lp. ROo\         P                  ! 4       p. pS F)  pVP                  VP                  V! V4      4      4       K+  	  \        P
                  ! V4      P                  VVV 3R l4      # )c              3   L   <"   V  F  pSP                  V4       R x  K  	  R # 5ir1   r%   )thingsthLs   & r   r[   /CooperatorTests.testCooperation.<locals>.myiter   s      
 s   !$c           	      \   < SP                  \        S4      \        \        S!  R4      4      # NrF   )rA   tuplesumzip)r:   r   groupsOfThingsr   s   &r   rD   1CooperatorTests.testCooperation.<locals>.<lambda>   s"    ((q3sN7KR3PQr   )abcr^      rY   def)         )r   rG   r%   rI   r   DeferredListrK   )r   r[   rN   tasksrM   r   r   s   f    @@r   testCooperationCooperatorTests.testCooperation   sk    	
 >OO#ELLVE]34 $ !!%(44Q
 	
r   c                  aa . oVV3R  lp ! R R4      o\         P                  ! SR7      pVP                  V! 4       4      P                  V P                  4       VP
                  P                  4        VP                  4        VP                  4        V P                  SP                  4       V P                  S\        \        ^
4      4      4       R# )c               3   z   <"   \        ^d4       F&  p SP                  V 4       V ^	8X  d   RSn        V x  K(  	  R# 5i)d   TN)rZ   r%   stopped)i_TPFoutputs    r   r[   6CooperatorTests.testResourceExhaustion.<locals>.myiter   s3     3Za 6#'DL	  s   8;c                   *   a  ] tR t^t o RtR tRtV tR# )4CooperatorTests.testResourceExhaustion.<locals>._TPFFc                    V P                   # r1   )r   r   s   &r   r(   =CooperatorTests.testResourceExhaustion.<locals>._TPF.__call__   s    ||#r   rF   N)r   r   r   r   r   r(   r   r   r   s   @r   r   r      s     G$ $r   r   )terminationPredicateFactoryN)r   rG   rI   rL   r6   _delayedCallr   _tickrH   
assertTruer   rA   listrZ   )r   r[   rN   r   r   s   &  @@r   testResourceExhaustion&CooperatorTests.testResourceExhaustion   s    		$ 	$ OO=	FH((5	 	
		%eBi1r   c                  a aaaa . o ! R R4      oVVV 3R lp\         P                  ! VR R7      oSP                  \        R	4      4      p. oVV3R lpVP	                  V4       ^ pS'       gX   V^,          pS'       d+   SP                  ^ 4      P                  4        V^,          pK2  V^28  g   KL  S P                  R4       K_  R# )
a  
If a callback to a deferred returned by coiterate calls coiterate on
the same Cooperator, we should make sure to only do the minimal amount
of scheduling work.  (This test was added to demonstrate a specific bug
that was found while writing the scheduler.)
c                   8   a  ] tR t^t o R tV 3R lR ltRtV tR# )9CooperatorTests.testCallbackReCoiterate.<locals>.FakeCallc                    Wn         R # r1   r	   r   s   &&r   r   BCooperatorTests.testCallbackReCoiterate.<locals>.FakeCall.__init__   s     	r   c                    < V ^8  d   QhRS[ /# )r   return)str)formatr   s   "r   __annotate__FCooperatorTests.testCallbackReCoiterate.<locals>.FakeCall.__annotate__   s     3 3# 3r   c                $    R V P                   : R2# )z
<FakeCall >r   r   s   &r   __repr__BCooperatorTests.testCallbackReCoiterate.<locals>.FakeCall.__repr__   s    #DII=22r   r   N)r   r   r   r   r   r   r   r   r   s   @r   FakeCallr      s     !3 3r   r   c                 z   < SP                  S\        S4      4       SP                  S! V 4      4       SR,          # )r^   r_   )assertFalsereprr%   )fr   callsr   s   &r   sched6CooperatorTests.testCallbackReCoiterate.<locals>.sched   s1    UDK0LL!%9r   c                      R  # )c                      R # TrF   rF   r   r   rD   KCooperatorTests.testCallbackReCoiterate.<locals>.<lambda>.<locals>.<lambda>   s    r   rF   rF   r   r   rD   9CooperatorTests.testCallbackReCoiterate.<locals>.<lambda>   s    r   	schedulerr   c                 n   < SP                  \        R4      4      P                  SP                  4       R # r   )rI   rJ   addBothr%   )r:   rN   r/   s   &r   anotherTask<CooperatorTests.testCallbackReCoiterate.<locals>.anotherTask   s"    KKR!))$++6r   zCooperator took too longNrF   )r   rG   rI   rJ   rK   popr	   r9   )	r   r   rO   r   r"   r   rN   r   r/   s	   f    @@@@r   testCallbackReCoiterate'CooperatorTests.testCallbackReCoiterate   s     	3 	3	
 OO9M
 KKR!	7 	
k"AID		!!!#	by		45 r   c                  a R.oV3R lp\         P                  ! VR7      pVP                  \        ^^.4      4      pVP                  \        ^^.4      4      pV P	                  S^ ,          P
                  VP                  4       VP                  4        V P                  S^ ,          P                  4       V P	                  VP                  S^ ,          4       VP                  4        V P                  S^ ,          P                  4       V P                  VP                  4       VP                  \        ^^.4      4       V P                  S^ ,          P                  4       V P	                  VP                  S^ ,          4       R# )z
If the last task in a Cooperator is removed, the scheduled call for
the next tick is cancelled, since it is no longer necessary.

This behavior is useful for tests that want to assert they have left
no reactor state behind when they're done.
Nc                 2   < \        V 4      S^ &   S^ ,          # )rh   )r   )r   r   s   &r   r   FCooperatorTests.test_removingLastTaskStopsScheduledCall.<locals>.sched  s    &q)E!H8Or   )r   )r   rG   	cooperaterJ   rA   r	   r   rH   r   r
   r   r   assertIsNone)r   r   cooptask1task2r   s   &    @r   'test_removingLastTaskStopsScheduledCall7CooperatorTests.test_removingLastTaskStopsScheduledCall   s%    	 / tQF|,tQF|,q

3 	

q++,**E!H5 	

a**+$++, 	tQF|$q++,**E!H5r   c                f    \         P                  ! 4       pV P                  VP                  4       R# )zU
L{Cooperator.running} reports C{True} if the L{Cooperator}
was started on creation.
N)r   rG   r   runningr   rN   s   & r   test_runningWhenStarted'CooperatorTests.test_runningWhenStarted"  s     
 OO		"r   c                j    \         P                  ! RR7      pV P                  VP                  4       R# )zS
L{Cooperator.running} reports C{False} if the L{Cooperator}
has not been started.
FstartedN)r   rG   r   r   r   s   & r   test_runningWhenNotStarted*CooperatorTests.test_runningWhenNotStarted*  s$    
 OOE*#r   c                    \         P                  ! RR7      pVP                  4        V P                  VP                  4       V P                  VP                  4       R# )zJ
L{Cooperator.running} reports C{True} when the L{Cooperator}
is running.
Fr   N)r   rG   start
addCleanuprH   r   r   r   s   & r   test_runningWhenRunning'CooperatorTests.test_runningWhenRunning2  s;    
 OOE*				"r   c                    \         P                  ! RR7      pVP                  4        VP                  4        V P	                  VP
                  4       R# )zR
L{Cooperator.running} reports C{False} after the L{Cooperator}
has been stopped.
Fr   N)r   rG   r   rH   r   r   r   s   & r   test_runningWhenStopped'CooperatorTests.test_runningWhenStopped<  s6    
 OOE*			#r   rF   N)r   r   r   r   r4   r6   r;   rU   rc   rt   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r.   r.   >   sc     FR.S6
333
&24(6T"6H#$#$ $r   r.   c                       ] tR tRtRtRtR# )UnhandledExceptioniG  z(
An exception that should go unhandled.
rF   N)r   r   r   r   r   r   rF   r   r   r   r   G  s    r   r   c                   *   a  ] tR tRt o RtR tRtV tR# )
AliasTestsiM  z[
Integration test to verify that the global singleton aliases do what
they're supposed to.
c                   a \         P                  ! 4       oV3R lpV! 4       p\        P                  ! V4      pV P	                  V\        P
                  P                  4       S# )zJ
L{twisted.internet.task.cooperate} ought to run the generator that it is
c               3   J   <"   ^x  ^x  ^x  S P                  R4       R# 5i)r^   yayN)rj   )rO   s   r   doit'AliasTests.test_cooperate.<locals>.doitY  s!     GGGJJus    #)r   rS   r   r   assertIn_theCooperator_tasks)r   r   ittheTaskrO   s   &   @r   test_cooperateAliasTests.test_cooperateS  sL     NN	 V..$gt2299:r   rF   N)r   r   r   r   r   r  r   r   r   s   @r   r   r   M  s     
 r   r   c                      a  ] tR tRt o RtR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )RunStateTestsie  z
Tests to verify the behavior of L{CooperativeTask.pause},
L{CooperativeTask.resume}, L{CooperativeTask.stop}, exhausting the
underlying iterator, and their interactions with each other.
c                <   RV n         RV n        RV n        . V n        \	        4       V n        \        P                  ! V P
                  R R7      V n        V P                  P                  V P                  4       4      V n        V P                  P                  4        R# )z
Create a cooperator with a fake scheduler and a termination predicate
that ensures only one unit of work will take place per tick.
Fc                      R  # )c                      R # r   rF   rF   r   r   rD   7RunStateTests.setUp.<locals>.<lambda>.<locals>.<lambda>z  s    r   rF   rF   r   r   rD   %RunStateTests.setUp.<locals>.<lambda>z  s    r   r   N)_doDeferNext_doStopNext
_doDieNextr"   r   r   r   rG   
cooperatorr   workerr   r   s   &r   setUpRunStateTests.setUpl  su    
 " 	&//nn )=	
 OO--dkkm<	r   c              #  b  "   ^ p V^,          pV P                   '       d>   RV n         \        P                  ! 4       pV P                  P	                  V4       Vx  KY  V P
                  '       d   R# V P                  '       d   \        4       hV P                  P	                  V4       Vx  K  5i)zz
This is a sample generator which yields Deferreds when we are testing
deferral and an ascending integer count otherwise.
FN)r  r   rS   r"   r%   r  r  r   )r   r   rO   s   &  r   r  RunStateTests.worker  s     
 FA   $)!NN$		  #!!!(**		  #s   B/AB/0B/+B/c                    V = V =R# )zw
Drop references to interesting parts of the fixture to allow Deferred
errors to be noticed when things start failing.
N)r   r   r   s   &r   tearDownRunStateTests.tearDown  s    
 INr   c                    RV n         R# )z0
Defer the next result from my worker iterator.
TN)r  r   s   &r   	deferNextRunStateTests.deferNext  s     !r   c                    RV n         R# )zU
Make the next result from my worker iterator be completion (raising
StopIteration).
TN)r  r   s   &r   stopNextRunStateTests.stopNext  s    
  r   c                    R pRV n         R# )zS
Make the next result from my worker iterator be raising an
L{UnhandledException}.
c                 0    V P                  \        4       R # r1   )r2   r   )failures   &r   ignoreUnhandled.RunStateTests.dieNext.<locals>.ignoreUnhandled  s    LL+,r   TN)r  )r   r%  s   & r   dieNextRunStateTests.dieNext  s    	 r   c                h   V P                   P                  4        V P                  V P                  ^.4       V P                   P                  4        V P                  V P                  ^^.4       V P                  P                  4        V P                   P                  4        V P                  V P                  ^^.4       V P                  P                  4        V P                  V P                  ^^.4       V P                   P                  4        V P                  V P                  . RO4       R# )zh
Cooperators should stop running their tasks when they're paused, and
start again when they're resumed.
Nr   )r   r+   rA   r"   r   pauseresumer   s   &r   test_pauseResumeRunStateTests.test_pauseResume  s     	QC(QF+ 			QF+		QF+I.r   c                >   V P                  \        P                  V P                  P                  4       V P                  P	                  4        V P                  P                  4        V P                  \        P                  V P                  P                  4       R# )z
L{CooperativeTask.resume} should raise a L{TaskNotPaused} exception if
it was not paused; e.g. if L{CooperativeTask.pause} was not invoked
more times than L{CooperativeTask.resume} on that object.
N)assertRaisesr   	NotPausedr+  r*  r   s   &r   test_resumeNotPaused"RunStateTests.test_resumeNotPaused  s^     	$..$))*:*:;				$..$))*:*:;r   c                   V P                   P                  4        V P                  P                  4        V P	                  V P
                  . 4       V P                   P                  4        V P                  P                  4        V P	                  V P
                  . 4       V P                   P                  4        V P                  P                  4        V P	                  V P
                  . 4       V P                   P                  4        V P                  P                  4        V P	                  V P
                  ^.4       R# )zf
Pauses on tasks should behave like a stack. If a task is paused twice,
it needs to be resumed twice.
N)r   r*  r   r+   rA   r"   r+  r   s   &r   test_pauseTwiceRunStateTests.test_pauseTwice  s     			B'		B'		B'		QC(r   c                   V P                  4        V P                  P                  4        V P                  \	        V P
                  4      ^4       V P                  V P
                  ^ ,          \        P                  4       V P                  P                  4        V P                  \	        V P
                  4      ^4       V P                  P                  4        V P                  P                  4        V P                  \	        V P
                  4      ^4       V P                  P                  4        V P                  P                  4        V P                  \	        V P
                  4      ^4       V P
                  ^ ,          P                  R4       V P                  P                  4        V P                  \	        V P
                  4      ^4       V P                  V P
                  ^,          ^4       R# )z
C{pause()}ing a task while it is waiting on an outstanding
L{defer.Deferred} should put the task into a state where the
outstanding L{defer.Deferred} must be called back I{and} the task is
C{resume}d before it will continue processing.
zSTUFF!N)r  r   r+   rA   lenr"   assertIsInstancer   rS   r   r*  r+  rj   r   s   &r   test_pauseWhileDeferred%RunStateTests.test_pauseWhileDeferred  s>    	TYY+diilENN;TYY+		TYY+		TYY+		!h'TYY+1q)r   c                
  aa V P                   P                  4       pV P                   P                  4       p. o. o. p. pV3R lpV3R lpVP                  V4       VP                  V4       VP                  VP                  4       VP                  VP                  4       V P	                  4        V P
                  P                  4        V P                  \        S4      ^4       V P                  \        S4      ^4       V P                  S^ ,          V P                   P                  4       V P                  S^ ,          V P                   P                  4       V P                  V^.4       V P                  V^.4       R# )a  
L{CooperativeTask.whenDone} returns a Deferred which fires when the
Cooperator's iterator is exhausted.  It returns a new Deferred each
time it is called; callbacks added to other invocations will not modify
the value that subsequent invocations will fire with.
c                 *   < SP                  V 4       ^# )r^   r   )rC   results1s   &r   callbackOne0RunStateTests.test_whenDone.<locals>.callbackOne      OOF#r   c                 *   < SP                  V 4       ^# )r   r   )rC   results2s   &r   callbackTwo0RunStateTests.test_whenDone.<locals>.callbackTwo  r@  r   N)r   whenDonerK   r%   r   r   r+   rA   r7  assertIs	_iterator)	r   	deferred1	deferred2final1final2r>  rC  r=  rB  s	   &      @@r   test_whenDoneRunStateTests.test_whenDone  s(    II&&(	II&&(			 	k*k*fmm,fmm, 	X*X*hqk499#6#67hqk499#6#67!%!%r   c                ^   V P                   P                  4       p. pVP                  VP                  4       V P	                  4        V P
                  P                  4        V P                  \        V4      ^4       V P                  V^ ,          P                  \        4      \        4       R# )z
L{CooperativeTask.whenDone} returns a L{defer.Deferred} that will fail
when the iterable's C{next} method raises an exception, with that
exception.
N)r   rE  rL   r%   r'  r   r+   rA   r7  checkr   )r   rH  resultss   &  r   test_whenDoneError RunStateTests.test_whenDoneError/  s{     II&&(	W^^,Wq)))*<=?QRr   c                f   V P                   P                  4       p. pVP                  VP                  4       V P                   P	                  4        V P                  \        V4      ^4       V P                  V^ ,          P                  \         P                  4      \         P                  4       R# )z
L{CooperativeTask.whenDone} returns a L{defer.Deferred} that fails with
L{TaskStopped} when the C{stop} method is called on that
L{CooperativeTask}.
N)	r   rE  rL   r%   rH   rA   r7  rO  TaskStopped)r   rH  errorss   &  r   test_whenDoneStopRunStateTests.test_whenDoneStop=  sx     II&&(	V]]+		Va()9)9:D<L<LMr   c                   V P                  4        V P                  P                  4        . pV P                  P	                  4       P                  VP                  4       V P                  WP                  P                  .4       R# )z
L{CooperativeTask.whenDone} will return a L{defer.Deferred} that will
succeed immediately if its iterator has already completed.
N)	r   r   r+   r   rE  rK   r%   rA   rG  )r   rP  s   & r   test_whenDoneAlreadyDone&RunStateTests.test_whenDoneAlreadyDoneJ  s\    
 			((899#6#6"78r   c                   V P                   P                  4        V P                  P                  4        V P	                  \        V P                  4      ^ 4       V P                  \         P                  V P                   P                  4       V P                  \         P                  V P                   P                  4       V P                  P                  4        V P	                  V P                  . 4       R# )z
C{stop()}ping a task should cause it to be removed from the run just as
C{pause()}ing, with the distinction that C{resume()} will raise a
L{TaskStopped} exception.
N)
r   rH   r   r+   rA   r7  r"   r/  rT  r*  r   s   &r   test_stopStopsRunStateTests.test_stopStopsU  s     			TYY+$**DIINN;$**DIIOO<B'r   c                   V P                   P                  4        V P                   P                  4        V P                   P                  4        V P                  P                  4        V P                  V P                  . 4       R# )z
C{resume()}ing a paused, stopped task should be a no-op; it should not
raise an exception, because it's paused, but neither should it actually
do more work from the task.
N)r   r*  rH   r+  r   r+   rA   r"   r   s   &r   test_pauseStopResume"RunStateTests.test_pauseStopResumed  sT     							B'r   c                d   V P                  4        V P                  P                  4        V P                  P	                  4       pV P                  V P                  P                  ^4       . pVP                  VP                  4       V P                  P                  4        V P                  P                  4        V P                  P                  4        VP                  ^4       V P                  P                  4        V P                  VR.4       V P                  V P                  . 4       R# )z
As a corrolary of the interaction of C{pause()} and C{unpause()},
C{stop()}ping a task which is waiting on a L{Deferred} should cause the
task to gracefully shut down, meaning that it should not be unpaused
when the deferred fires.
N)r  r   r+   r"   r   rA   r   _pauseCountr   r%   rH   rj   )r   rO   rP  s   &  r   test_stopDeferredRunStateTests.test_stopDeferredp  s     	IIMMO..2			'..!			

1
 	4&)B'r   c                    V P                  4        V P                  P                  4        V P                  \        P
                  V P                  P                  4       R# )z`
C{stop()}ping a L{CooperativeTask} whose iterator has been exhausted
should raise L{TaskDone}.
N)r   r   r+   r/  r   TaskDonerH   r   s   &r   test_stopExhausted RunStateTests.test_stopExhausted  s9    
 	$--8r   c                    V P                  4        V P                  P                  4        V P                  \        P
                  V P                  P                  4       R# )zh
C{stop()}ping a L{CooperativeTask} whose iterator has encountered an
error should raise L{TaskFailed}.
N)r'  r   r+   r/  r   
TaskFailedrH   r   s   &r   test_stopErroredRunStateTests.test_stopErrored  s9    
 	$//499>>:r   c                  a a . oVV 3R lpS P                   P                  4       P                  V4       S P                  4        S P                  P                  4        S P                  SS P                   P                  R.4       R# )a[  
If a callback of a L{Deferred} from L{CooperativeTask.whenDone} calls
C{Cooperator.stop} on its L{CooperativeTask._cooperator}, the
L{Cooperator} will stop, but the L{CooperativeTask} whose callback is
calling C{stop} should already be considered 'stopped' by the time the
callback is running, and therefore removed from the
L{CoooperativeTask}.
c                    < SP                  V 4       SP                  P                  4        SP                  R 4       R# )r/   N)r%   r  rH   )rC   callbackPhasesr   s   &r   stopit;RunStateTests.test_stopCooperatorReentrancy.<locals>.stopit  s1    !!&)OO  " !!&)r   r/   N)r   rE  rK   r   r   r+   rA   rG  )r   rp  ro  s   f @r   test_stopCooperatorReentrancy+RunStateTests.test_stopCooperatorReentrancy  sd     	* 			((0$))*=*=v)FGr   )r  r  r  r  r   r   r"   N)r   r   r   r   r   r  r  r  r  r   r'  r,  r1  r4  r9  rL  rQ  rV  rY  r\  r_  rc  rg  rk  rr  r   r   r   s   @r   r
  r
  e  sx      &*! 
/,	<),*0)&VSN	9(
((49;H Hr   r
  N)r   twisted.internetr   r   r   twisted.trialr   r   r   TestCaser.   	Exceptionr   r   r
  rF   r   r   <module>rx     sr    2 1 " & :F$h'' F$R "" 0MHH%% MHr   