ó
    ×›‘h[S  ã                   óä   • S r SSKJrJrJr  SSKJr   " S S5      r " S S5      r " S S	\R                  5      r
 " S
 S\5      r " S S\R                  5      r " S S\R                  5      rg)z_
This module contains tests for L{twisted.internet.task.Cooperator} and
related functionality.
é    )ÚdeferÚreactorÚtask)Úunittestc                   ó$   • \ rS rSrSrS rS rSrg)ÚFakeDelayedCallé   z9
Fake delayed call which lets us simulate the scheduler.
c                 ó   • Xl         SU l        g)z
A function to run, later.
FN)ÚfuncÚ	cancelled©Úselfr   s     Ú`C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/test/test_cooperator.pyÚ__init__ÚFakeDelayedCall.__init__   s   € ð Œ	Øˆ�ó    c                 ó   • SU l         g)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__© r   r   r   r      s   † ñòõr   r   c                   ó*   • \ rS rSrSrS rS rS rSrg)ÚFakeScheduleré!   z'
A fake scheduler for testing against.
c                 ó   • / U l         g)z4
Create a fake scheduler with a list of work to do.
N©Úworkr   s    r   r   ÚFakeScheduler.__init__&   s   € ð ˆ�	r   c                 óR   • [        U5      nU R                  R                  U5        U$ )z+
Schedule a unit of work to be done later.
)r   r#   Úappend)r   ÚthunkÚunits      r   Ú__call__ÚFakeScheduler.__call__,   s%   € ô ˜uÓ%ˆØ�	‰	×Ñ˜ÔØˆr   c                 ó‚   • U R                   / sol         U H&  nUR                  (       a  M  UR                  5         M(     g)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   r   r   r   !   s   † ñòòõr   r   c                   óx   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)ÚCooperatorTestsé>   Údonec                 óX   • UR                  [        R                  5        U R                  $ ©N)Útrapr   ÚSchedulerStoppedÚRESULT)r   Úerrs     r   ÚebIterÚCooperatorTests.ebIterA   s   € Ø�‰”×&Ñ&Ô'Ø�{‰{Ðr   c                 ó$   • U R                  5         g r3   )Úfail)r   Úigns     r   ÚcbIterÚCooperatorTests.cbIterE   s   € Ø�	‰	�r   c                 óH   ^ ^• U 4S jmT" S5      R                  U4S j5      $ )zE
Test that Cooperators refuse new tasks when they have been stopped.
c                 ó  >• [         R                  " 5       nUR                  5         UR                  [	        S5      U 5      nUR                  TR                  5        UR                  TR                  5        UR                  U4S j5      $ )Nr   c                 ó<   >• TR                  U TR                  5      $ r3   ©ÚassertEqualr6   ©Úresultr   s    €r   Ú<lambda>ÚNCooperatorTests.testStoppedRejectsNewTasks.<locals>.testwith.<locals>.<lambda>S   s   ø€ °×0@Ñ0@ÀÈÏÉÔ0Ur   )	r   Ú
CooperatorÚstopÚ	coiterateÚiterÚaddCallbackr=   Ú
addErrbackr8   )ÚstuffÚcÚdr   s      €r   ÚtestwithÚ<CooperatorTests.testStoppedRejectsNewTasks.<locals>.testwithM   s\   ø€ Ü—’Ó!ˆAØ�F‰FŒHØ—‘œD ›H eÓ,ˆAØ�M‰M˜$Ÿ+™+Ô&Ø�L‰L˜Ÿ™Ô%Ø—=‘=Ô!UÓVÐVr   Nc                 ó:   >• T" [         R                  " 5       5      $ r3   )r   ÚDeferred)r<   rQ   s    €r   rF   Ú<CooperatorTests.testStoppedRejectsNewTasks.<locals>.<lambda>U   s   ø€ ±h¼u¿~º~Ó?OÔ6Pr   )rL   )r   rQ   s   `@r   ÚtestStoppedRejectsNewTasksÚ*CooperatorTests.testStoppedRejectsNewTasksH   s!   ù€ õ
	Wñ ˜‹~×)Ñ)Ô*PÓQÐQr   c                 ó0  ^ ^• [         R                  " 5       nS mSTl        UR                  T" 5       5      nUR	                  T R
                  5        UR                  T R                  5        UR                  5         UU 4S jnUR	                  U5        U$ )zY
Test that a running iterator will not run to completion when the
cooperator is stopped.
c               3   ó6   #   • [        S5       S h  v•N   g  N7f)Né   )Úranger   r   r   ÚmyiterÚ/CooperatorTests.testStopRunning.<locals>.myiter^   s   é € Ü˜Q“x×Óùs   ‚‘’éÿÿÿÿc                 óv   >• TR                  U TR                  5        TR                  TR                  S5        g ©Nr^   )rC   r6   Úvalue)rE   r\   r   s    €€r   Ú	doassertsÚ2CooperatorTests.testStopRunning.<locals>.doassertsg   s+   ø€ Ø×Ñ˜V T§[¡[Ô1Ø×Ñ˜VŸ\™\¨2Õ.r   )	r   rH   ra   rJ   rL   r=   rM   r8   rI   )r   rO   rP   rb   r\   s   `   @r   ÚtestStopRunningÚCooperatorTests.testStopRunningW   sp   ù€ ô
 �OŠOÓˆò	 ð ˆŒØ�K‰K™›Ó!ˆØ	�‰�d—k‘kÔ"Ø	�‰�T—[‘[Ô!Ø	�‰Œö	/ð 	
�‰�iÔ Øˆr   c                 óŠ  ^ ^^^• [         R                  " 5       m[         R                  " 5       mUU U4S jn[        R                  " 5       mTR	                  U" 5       5      nUU4S jnTR                  U5        UR                  T R                  5        UR                  T R                  5        UR                  U 4S j5      $ )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   óz   >#   • [         R                  " STR                  S 5        T v •  TR                  5         g 7f©Nr   )r   Ú	callLaterÚcallbackr;   )ÚoutstandingDr   ÚtestControlDs   €€€r   r\   Ú3CooperatorTests.testStopOutstanding.<locals>.myiterw   s-   øé € Ü×Ò˜a ×!6Ñ!6¸Ô=ØÒØ�I‰I�Kùs   ƒ8;c                 óH   >• TR                  5         TR                  S5        g )NÚarglebargle)rI   rj   )r<   rO   rk   s    €€r   Ú	stopAndGoÚ6CooperatorTests.testStopOutstanding.<locals>.stopAndGo   s   ø€ Ø�F‰FŒHØ×!Ñ! -Õ0r   c                 ó<   >• TR                  U TR                  5      $ r3   rB   rD   s    €r   rF   Ú5CooperatorTests.testStopOutstanding.<locals>.<lambda>‡   s   ø€ ¨D×,<Ñ,<¸VÀTÇ[Á[Ô,Qr   )	r   rT   r   rH   rJ   rL   r=   rM   r8   )r   r\   rP   rp   rO   rk   rl   s   `   @@@r   ÚtestStopOutstandingÚ#CooperatorTests.testStopOutstandingn   s…   û€ ô —~’~Ó'ˆÜ—~’~Ó'ˆ÷	ô
 �OŠOÓˆØ�K‰K™›Ó!ˆö	1ð 	× Ñ  Ô+Ø	�‰�d—k‘kÔ"Ø	�‰�T—[‘[Ô!à�}‰}ÔQÓRÐRr   c                 óŠ   • [         R                  " 5       nS nUR                  U" 5       5      nU R                  U[        5      $ )Nc               3   ó    #   •  [        5       e7fr3   )ÚRuntimeErrorr   r   r   r\   Ú3CooperatorTests.testUnexpectedError.<locals>.myiterŒ   s   é € Øô #“nÐ$ùs   ‚©r   rH   rJ   ÚassertFailurerx   )r   rO   r\   rP   s       r   ÚtestUnexpectedErrorÚ#CooperatorTests.testUnexpectedError‰   s8   € Ü�OŠOÓˆò	%ð �K‰K™›Ó!ˆØ×!Ñ! !¤\Ó2Ð2r   c                 óŠ   • S n[         R                  " 5       nUR                  U" 5       5      nU R                  U[        5      $ )Nc               3   ó’   #   • [         R                  " 5       n [        R                  " SU R                  [        5       5        U v •  g 7frh   )r   rT   r   ri   Úerrbackrx   )ÚDs    r   r\   Ú@CooperatorTests.testUnexpectedErrorActuallyLater.<locals>.myiter–   s.   é € Ü—’Ó ˆAÜ×Ò˜a §¡¬L«NÔ;Ø‹Gùs   ‚AArz   ©r   r\   rO   rP   s       r   Ú testUnexpectedErrorActuallyLaterÚ0CooperatorTests.testUnexpectedErrorActuallyLater•   s8   € ò	ô
 �OŠOÓˆØ�K‰K™›Ó!ˆØ×!Ñ! !¤\Ó2Ð2r   c                 óŠ   • S n[         R                  " 5       nUR                  U" 5       5      nU R                  U[        5      $ )Nc               3   óL   #   • [         R                  " [        5       5      v •  g 7fr3   )r   r;   rx   r   r   r   r\   ÚCCooperatorTests.testUnexpectedErrorNotActuallyLater.<locals>.myiter    s   é € Ü—*’*œ\›^Ó,Ó,ùs   ‚"$rz   rƒ   s       r   Ú#testUnexpectedErrorNotActuallyLaterÚ3CooperatorTests.testUnexpectedErrorNotActuallyLaterŸ   s8   € ò	-ô �OŠOÓˆØ�K‰K™›Ó!ˆØ×!Ñ! !¤\Ó2Ð2r   c                 ó  ^ ^^• / mU4S jn/ SQm[         R                  " 5       n/ nT H)  nUR                  UR                  U" U5      5      5        M+     [        R
                  " U5      R                  UUU 4S j5      $ )Nc              3   óJ   >#   • U  H  nTR                  U5        S v •  M     g 7fr3   ©r&   )ÚthingsÚthÚLs     €r   r\   Ú/CooperatorTests.testCooperation.<locals>.myiterª   s    øé € Û�Ø—‘˜”Ø”
ò ùs   ƒ #)Úabc©é   é   rZ   Údef)é   é   é   c                 óZ   >• TR                  [        T5      [        [        T6 S5      5      $ ©Nr   )rC   ÚtupleÚsumÚzip)r<   r�   ÚgroupsOfThingsr   s    €€€r   rF   Ú1CooperatorTests.testCooperation.<locals>.<lambda>·   s"   ø€ ˜×(Ñ(¬¨q«´3´s¸NÐ7KÈRÓ3PÔQr   )r   rH   r&   rJ   r   ÚDeferredListrL   )r   r\   rO   ÚtasksrN   r�   rŸ   s   `    @@r   ÚtestCooperationÚCooperatorTests.testCooperation§   sk   ú€ Øˆõ	ò
 >ˆä�OŠOÓˆØˆÛ#ˆEØ�L‰L˜Ÿ™¡V¨E£]Ó3Ö4ñ $ô ×!Ò! %Ó(×4Ñ4ÞQó
ð 	
r   c                 ó¦  ^^• / mUU4S jn " S S5      m[         R                  " TS9nUR                  U" 5       5      R                  U R                  5        UR
                  R                  5         UR                  5         UR                  5         U R                  TR                  5        U R                  T[        [        S5      5      5        g )Nc               3   óv   >#   • [        S5       H%  n TR                  U 5        U S:X  a  STl        U v •  M'     g 7f)Néd   é	   T)r[   r&   Ústopped)ÚiÚ_TPFÚoutputs    €€r   r\   Ú6CooperatorTests.testResourceExhaustion.<locals>.myiter½   s3   øé € Ü˜3–Z�Ø—‘˜aÔ Ø˜“6Ø#'�D”LØ”ò	  ùs   ƒ69c                   ó   • \ rS rSrSrS rSrg)Ú4CooperatorTests.testResourceExhaustion.<locals>._TPFéÄ   Fc                 ó   • U R                   $ r3   )r©   r   s    r   r)   Ú=CooperatorTests.testResourceExhaustion.<locals>._TPF.__call__Ç   s   € Ø—|‘|Ð#r   r   N)r   r   r   r   r©   r)   r   r   r   r   r«   r¯   Ä   s   † ØˆGõ$r   r«   )ÚterminationPredicateFactoryé
   )r   rH   rJ   rM   r8   Ú_delayedCallr   Ú_tickrI   Ú
assertTruer©   rC   Úlistr[   )r   r\   rO   r«   r¬   s      @@r   ÚtestResourceExhaustionÚ&CooperatorTests.testResourceExhaustionº   s�   ù€ Øˆö	÷	$ñ 	$ô �OŠO¸Ñ=ˆØ	�‰‘F“HÓ×(Ñ(¨¯©Ô5Ø	�‰×ÑÔð 	
�‰Œ	Ø	�‰ŒØ�‰˜Ÿ™Ô%Ø×Ñ˜¤¤e¨B£i£Õ1r   c                 ó�  ^ ^^^^• / m " S S5      mUUU 4S jn[         R                  " US S9mTR                  [        S5      5      n/ mUU4S jnUR	                  U5        SnT(       dZ  US	-  nT(       a-  TR                  S5      R                  5         US	-  nT(       a  M-  US
:”  a  T R                  S5        T(       d  MY  gg)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                   ó(   • \ rS rSrS rS\4S jrSrg)Ú9CooperatorTests.testCallbackReCoiterate.<locals>.FakeCalléÝ   c                 ó   • Xl         g r3   ©r   r   s     r   r   ÚBCooperatorTests.testCallbackReCoiterate.<locals>.FakeCall.__init__Þ   s   € Ø •	r   Úreturnc                 ó$   • SU R                   < S3$ )Nz
<FakeCall Ú>rÀ   r   s    r   Ú__repr__ÚBCooperatorTests.testCallbackReCoiterate.<locals>.FakeCall.__repr__á   s   € Ø# D§I¡I¡=°Ð2Ð2r   rÀ   N)r   r   r   r   r   ÚstrrÅ   r   r   r   r   ÚFakeCallr½   Ý   s   † ò!ð3 #÷ 3r   rÈ   c                 ór   >• TR                  T[        T5      5        TR                  T" U 5      5        TS   $ r`   )ÚassertFalseÚreprr&   )ÚfrÈ   Úcallsr   s    €€€r   ÚschedÚ6CooperatorTests.testCallbackReCoiterate.<locals>.schedä   s1   ø€ Ø×Ñ˜U¤D¨£KÔ0Ø�L‰L™ !›Ô%Ø˜‘9Ðr   c                  ó   • S $ )Nc                  ó   • g©NTr   r   r   r   rF   ÚKCooperatorTests.testCallbackReCoiterate.<locals>.<lambda>.<locals>.<lambda>ê   s   € Èr   r   r   r   r   rF   Ú9CooperatorTests.testCallbackReCoiterate.<locals>.<lambda>ê   s   € Âr   ©Ú	schedulerr³   r   c                 ól   >• TR                  [        S5      5      R                  TR                  5        g r›   )rJ   rK   ÚaddBothr&   )r<   rO   r1   s    €€r   ÚanotherTaskÚ<CooperatorTests.testCallbackReCoiterate.<locals>.anotherTaskð   s"   ø€ Ø�K‰Kœ˜R›Ó!×)Ñ)¨$¯+©+Õ6r   r   r”   é2   zCooperator took too longN)r   rH   rJ   rK   rL   Úpopr   r;   )	r   rÎ   rP   rÙ   r#   rÈ   rO   rÍ   r1   s	   `    @@@@r   ÚtestCallbackReCoiterateÚ'CooperatorTests.testCallbackReCoiterateÔ   s°   ü€ ð ˆ÷	3ñ 	3÷	ô
 �OŠOØÑ9Mñ
ˆð �K‰Kœ˜R›Ó!ˆàˆö	7ð 	
�‰�kÔ"àˆÞØ�A‰IˆDÞØ—	‘	˜!“×!Ñ!Ô#Ø˜‘	�÷ �%ð �b‹yØ—	‘	Ð4Ô5÷ ’$r   c                 óà  ^• S/mU4S jn[         R                  " US9nUR                  [        SS/5      5      nUR                  [        SS/5      5      nU R	                  TS   R
                  UR                  5        UR                  5         U R                  TS   R                  5        U R	                  UR                  TS   5        UR                  5         U R                  TS   R                  5        U R                  UR                  5        UR                  [        SS/5      5        U R                  TS   R                  5        U R	                  UR                  TS   5        g)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                 ó*   >• [        U 5      TS'   TS   $ rh   )r   )rÌ   rÍ   s    €r   rÎ   ÚFCooperatorTests.test_removingLastTaskStopsScheduledCall.<locals>.sched  s   ø€ Ü& qÓ)ˆE�!‰HØ˜‘8ˆOr   )rÖ   r”   r•   r   )r   rH   Ú	cooperaterK   rC   r   r¶   rI   rÊ   r   rµ   r·   ÚassertIsNone)r   rÎ   ÚcoopÚtask1Útask2rÍ   s        @r   Ú'test_removingLastTaskStopsScheduledCallÚ7CooperatorTests.test_removingLastTaskStopsScheduledCallþ   s%  ø€ ð �ˆõ	ô �Š¨Ñ/ˆð —‘œt Q¨ F›|Ó,ˆØ—‘œt Q¨ F›|Ó,ˆØ×Ñ˜˜q™Ÿ™¨¯
©
Ô3ð 	�
‰
ŒØ×Ñ˜˜q™×+Ñ+Ô,Ø×Ñ˜×*Ñ*¨E°!©HÔ5ð 	�
‰
ŒØ�‰˜˜a™×*Ñ*Ô+Ø×Ñ˜$×+Ñ+Ô,ð 	�‰”t˜Q ˜F“|Ô$Ø×Ñ˜˜q™×+Ñ+Ô,Ø×Ñ˜×*Ñ*¨E°!©HÕ5r   c                 ód   • [         R                  " 5       nU R                  UR                  5        g)zU
L{Cooperator.running} reports C{True} if the L{Cooperator}
was started on creation.
N)r   rH   r·   Úrunning©r   rO   s     r   Útest_runningWhenStartedÚ'CooperatorTests.test_runningWhenStarted"  s    € ô
 �OŠOÓˆØ�‰˜Ÿ	™	Õ"r   c                 ób   • [         R                  " SS9nU R                  UR                  5        g)zS
L{Cooperator.running} reports C{False} if the L{Cooperator}
has not been started.
F©ÚstartedN)r   rH   rÊ   rê   rë   s     r   Útest_runningWhenNotStartedÚ*CooperatorTests.test_runningWhenNotStarted*  s$   € ô
 �OŠO EÑ*ˆØ×Ñ˜Ÿ™Õ#r   c                 ó¸   • [         R                  " SS9nUR                  5         U R                  UR                  5        U R                  UR                  5        g)zJ
L{Cooperator.running} reports C{True} when the L{Cooperator}
is running.
Frï   N)r   rH   ÚstartÚ
addCleanuprI   r·   rê   rë   s     r   Útest_runningWhenRunningÚ'CooperatorTests.test_runningWhenRunning2  s;   € ô
 �OŠO EÑ*ˆØ	�‰Œ	Ø�‰˜Ÿ™ÔØ�‰˜Ÿ	™	Õ"r   c                 ó¢   • [         R                  " SS9nUR                  5         UR                  5         U R	                  UR
                  5        g)zR
L{Cooperator.running} reports C{False} after the L{Cooperator}
has been stopped.
Frï   N)r   rH   rô   rI   rÊ   rê   rë   s     r   Útest_runningWhenStoppedÚ'CooperatorTests.test_runningWhenStopped<  s6   € ô
 �OŠO EÑ*ˆØ	�‰Œ	Ø	�‰ŒØ×Ñ˜Ÿ™Õ#r   r   N)r   r   r   r   r6   r8   r=   rV   rd   rt   r|   r„   r‰   r£   r¹   rÝ   rç   rì   rñ   rö   rù   r   r   r   r   r/   r/   >   s[   † Ø€FòòòRòò.Sò6
3ò3ò3ò
ò&2ò4(6òT"6òH#ò$ò#õ$r   r/   c                   ó   • \ rS rSrSrSrg)ÚUnhandledExceptioniG  z(
An exception that should go unhandled.
r   N)r   r   r   r   r   r   r   r   r   rü   rü   G  s   † ôr   rü   c                   ó   • \ rS rSrSrS rSrg)Ú
AliasTestsiM  z[
Integration test to verify that the global singleton aliases do what
they're supposed to.
c                 óÌ   ^• [         R                  " 5       mU4S jnU" 5       n[        R                  " U5      nU R	                  U[        R
                  R                  5        T$ )zJ
L{twisted.internet.task.cooperate} ought to run the generator that it is
c               3   óH   >#   • Sv •  Sv •  Sv •  T R                  S5        g 7f)Nr”   r•   rZ   Úyay)rj   )rP   s   €r   ÚdoitÚ'AliasTests.test_cooperate.<locals>.doitY  s!   øé € ØŠGØŠGØŠGØ�J‰J�uÕùs   ƒ")r   rT   r   râ   ÚassertInÚ_theCooperatorÚ_tasks)r   r  ÚitÚtheTaskrP   s       @r   Útest_cooperateÚAliasTests.test_cooperateS  sL   ø€ ô �NŠNÓˆõ	ñ ‹VˆÜ—.’. Ó$ˆØ�‰�gœt×2Ñ2×9Ñ9Ô:Øˆr   r   N)r   r   r   r   r   r	  r   r   r   r   rþ   rþ   M  s   † ñõ
r   rþ   c                   ó�   • \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rSrg)Ú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                 ó4  • SU l         SU l        SU l        / U l        [	        5       U l        [        R                  " U R
                  S S9U l        U R                  R                  U R                  5       5      U l        U R                  R                  5         g)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                  ó   • S $ )Nc                  ó   • grÒ   r   r   r   r   rF   Ú7RunStateTests.setUp.<locals>.<lambda>.<locals>.<lambda>z  s   € ¸r   r   r   r   r   rF   Ú%RunStateTests.setUp.<locals>.<lambda>z  s   € ²r   rÕ   N)Ú_doDeferNextÚ_doStopNextÚ
_doDieNextr#   r   rÖ   r   rH   Ú
cooperatorrâ   Úworkerrô   r   s    r   ÚsetUpÚRunStateTests.setUpl  su   € ð
 "ˆÔØ ˆÔØˆŒØˆŒ	Ü&›ˆŒÜŸ/š/Ø—n‘nñ )=ñ	
ˆŒð —O‘O×-Ñ-¨d¯k©k«mÓ<ˆŒ	Ø�‰×ÑÕr   c              #   óP  #   • Sn US-  nU R                   (       a<  SU l         [        R                  " 5       nU R                  R	                  U5        Uv •  OLU R
                  (       a  gU R                  (       a
  [        5       eU R                  R	                  U5        Uv •  M   7f)zz
This is a sample generator which yields Deferreds when we are testing
deferral and an ascending integer count otherwise.
r   r”   FN)r  r   rT   r#   r&   r  r  rü   )r   rª   rP   s      r   r  ÚRunStateTests.worker  s„   é € ð
 ˆØØ�‰FˆAØ× × Ø$)�Ô!Ü—N’NÓ$�Ø—	‘	× Ñ  Ô#Ø“Ø×!×!ØØ——Ü(Ó*Ð*à—	‘	× Ñ  Ô#Ø’ñ ùs   ‚B$B&c                 ó   • U ? U ?g)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                 ó   • SU l         g)z0
Defer the next result from my worker iterator.
TN)r  r   s    r   Ú	deferNextÚRunStateTests.deferNextœ  s   € ð !ˆÕr   c                 ó   • SU l         g)zU
Make the next result from my worker iterator be completion (raising
StopIteration).
TN)r  r   s    r   ÚstopNextÚRunStateTests.stopNext¢  s   € ð
  ˆÕr   c                 ó   • S nSU l         g)zS
Make the next result from my worker iterator be raising an
L{UnhandledException}.
c                 ó.   • U R                  [        5        g r3   )r4   rü   )Úfailures    r   ÚignoreUnhandledÚ.RunStateTests.dieNext.<locals>.ignoreUnhandled¯  s   € Ø�L‰LÔ+Ô,Ør   TN)r  )r   r'  s     r   ÚdieNextÚRunStateTests.dieNext©  s   € ò	ð ˆ�r   c                 óf  • U R                   R                  5         U R                  U R                  S/5        U R                   R                  5         U R                  U R                  SS/5        U R                  R                  5         U R                   R                  5         U R                  U R                  SS/5        U R                  R                  5         U R                  U R                  SS/5        U R                   R                  5         U R                  U R                  / SQ5        g)zh
Cooperators should stop running their tasks when they're paused, and
start again when they're resumed.
r”   r•   r“   N)rÖ   r,   rC   r#   r   ÚpauseÚresumer   s    r   Útest_pauseResumeÚRunStateTests.test_pauseResumeµ  sÖ   € ð 	�‰×ÑÔØ×Ñ˜Ÿ™ Q CÔ(Ø�‰×ÑÔØ×Ñ˜Ÿ™ Q¨ FÔ+ð 	�	‰	�‰ÔØ�‰×ÑÔØ×Ñ˜Ÿ™ Q¨ FÔ+Ø�	‰	×ÑÔà×Ñ˜Ÿ™ Q¨ FÔ+Ø�‰×ÑÔà×Ñ˜Ÿ™¢IÕ.r   c                 ó<  • U R                  [        R                  U R                  R                  5        U R                  R	                  5         U R                  R                  5         U R                  [        R                  U R                  R                  5        g)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                 ó†  • U R                   R                  5         U R                  R                  5         U R	                  U R
                  / 5        U R                   R                  5         U R                  R                  5         U R	                  U R
                  / 5        U R                   R                  5         U R                  R                  5         U R	                  U R
                  / 5        U R                   R                  5         U R                  R                  5         U R	                  U R
                  S/5        g)zf
Pauses on tasks should behave like a stack. If a task is paused twice,
it needs to be resumed twice.
r”   N)r   r,  rÖ   r,   rC   r#   r-  r   s    r   Útest_pauseTwiceÚRunStateTests.test_pauseTwiceÖ  sÒ   € ð 	�	‰	�‰ÔØ�‰×ÑÔØ×Ñ˜Ÿ™ BÔ'à�	‰	�‰ÔØ�‰×ÑÔØ×Ñ˜Ÿ™ BÔ'à�	‰	×ÑÔØ�‰×ÑÔØ×Ñ˜Ÿ™ BÔ'à�	‰	×ÑÔØ�‰×ÑÔØ×Ñ˜Ÿ™ Q CÕ(r   c                 óÖ  • U R                  5         U R                  R                  5         U R                  [	        U R
                  5      S5        U R                  U R
                  S   [        R                  5        U R                  R                  5         U R                  [	        U R
                  5      S5        U R                  R                  5         U R                  R                  5         U R                  [	        U R
                  5      S5        U R                  R                  5         U R                  R                  5         U R                  [	        U R
                  5      S5        U R
                  S   R                  S5        U R                  R                  5         U R                  [	        U R
                  5      S5        U R                  U R
                  S   S5        g)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.
r”   r   zSTUFF!r•   N)r  rÖ   r,   rC   Úlenr#   ÚassertIsInstancer   rT   r   r,  r-  rj   r   s    r   Útest_pauseWhileDeferredÚ%RunStateTests.test_pauseWhileDeferredì  s>  € ð 	�‰ÔØ�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø×Ñ˜dŸi™i¨™l¬E¯N©NÔ;Ø�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø�	‰	�‰ÔØ�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø�	‰	×ÑÔØ�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø�	‰	�!‰×Ñ˜hÔ'Ø�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø×Ñ˜Ÿ™ 1™ qÕ)r   c                 óø  ^^• U R                   R                  5       nU R                   R                  5       n/ m/ m/ n/ nU4S jnU4S jnUR                  U5        UR                  U5        UR                  UR                  5        UR                  UR                  5        U R	                  5         U R
                  R                  5         U R                  [        T5      S5        U R                  [        T5      S5        U R                  TS   U R                   R                  5        U R                  TS   U R                   R                  5        U R                  US/5        U R                  US/5        g)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                 ó(   >• TR                  U 5        g)Nr”   r�   )rE   Úresults1s    €r   ÚcallbackOneÚ0RunStateTests.test_whenDone.<locals>.callbackOne  ó   ø€ Ø�O‰O˜FÔ#Ør   c                 ó(   >• TR                  U 5        g)Nr•   r�   )rE   Úresults2s    €r   ÚcallbackTwoÚ0RunStateTests.test_whenDone.<locals>.callbackTwo  rB  r   r”   r   r•   N)r   ÚwhenDonerL   r&   r"  rÖ   r,   rC   r9  ÚassertIsÚ	_iterator)	r   Ú	deferred1Ú	deferred2Úfinal1Úfinal2r@  rE  r?  rD  s	          @@r   Útest_whenDoneÚRunStateTests.test_whenDone  s(  ù€ ð —I‘I×&Ñ&Ó(ˆ	Ø—I‘I×&Ñ&Ó(ˆ	ØˆØˆØˆØˆõ	õ	ð 	×Ñ˜kÔ*Ø×Ñ˜kÔ*à×Ñ˜fŸm™mÔ,Ø×Ñ˜fŸm™mÔ,ð 	�‰ŒØ�‰×ÑÔà×Ñœ˜X›¨Ô*Ø×Ñœ˜X›¨Ô*à�‰�h˜q‘k 4§9¡9×#6Ñ#6Ô7Ø�‰�h˜q‘k 4§9¡9×#6Ñ#6Ô7à×Ñ˜ ! Ô%Ø×Ñ˜ ! Õ%r   c                 óT  • U R                   R                  5       n/ nUR                  UR                  5        U R	                  5         U R
                  R                  5         U R                  [        U5      S5        U R                  US   R                  [        5      [        5        g)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.
r”   r   N)r   rG  rM   r&   r)  rÖ   r,   rC   r9  Úcheckrü   )r   rJ  Úresultss      r   Útest_whenDoneErrorÚ RunStateTests.test_whenDoneError/  s{   € ð —I‘I×&Ñ&Ó(ˆ	ØˆØ×Ñ˜WŸ^™^Ô,Ø�‰ŒØ�‰×ÑÔØ×Ñœ˜W› qÔ)Ø×Ñ˜ ™×)Ñ)Ô*<Ó=Ô?QÕRr   c                 ó\  • U R                   R                  5       n/ nUR                  UR                  5        U R                   R	                  5         U R                  [        U5      S5        U R                  US   R                  [         R                  5      [         R                  5        g)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}.
r”   r   N)	r   rG  rM   r&   rI   rC   r9  rQ  ÚTaskStopped)r   rJ  Úerrorss      r   Útest_whenDoneStopÚRunStateTests.test_whenDoneStop=  sx   € ð —I‘I×&Ñ&Ó(ˆ	ØˆØ×Ñ˜VŸ]™]Ô+Ø�	‰	�‰ÔØ×Ñœ˜V› aÔ(Ø×Ñ˜ ™Ÿ™¬×)9Ñ)9Ó:¼D×<LÑ<LÕMr   c                 ó  • U R                  5         U R                  R                  5         / nU R                  R	                  5       R                  UR                  5        U R                  XR                  R                  /5        g)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   rG  rL   r&   rC   rI  )r   rR  s     r   Útest_whenDoneAlreadyDoneÚ&RunStateTests.test_whenDoneAlreadyDoneJ  s\   € ð
 	�‰ŒØ�‰×ÑÔØˆØ�	‰	×ÑÓ×(Ñ(¨¯©Ô8Ø×Ñ˜§9¡9×#6Ñ#6Ð"7Õ8r   c                 óò  • U R                   R                  5         U R                  R                  5         U R	                  [        U R                  5      S5        U R                  [         R                  U R                   R                  5        U R                  [         R                  U R                   R                  5        U R                  R                  5         U R	                  U R                  / 5        g)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.
r   N)
r   rI   rÖ   r,   rC   r9  r#   r1  rV  r,  r   s    r   Útest_stopStopsÚRunStateTests.test_stopStopsU  sš   € ð 	�	‰	�‰ÔØ�‰×ÑÔØ×Ñœ˜TŸY™Y›¨Ô+Ø×Ñœ$×*Ñ*¨D¯I©I¯N©NÔ;Ø×Ñœ$×*Ñ*¨D¯I©I¯O©OÔ<à�‰×ÑÔØ×Ñ˜Ÿ™ BÕ'r   c                 ó  • U R                   R                  5         U R                   R                  5         U R                   R                  5         U R                  R                  5         U R                  U R                  / 5        g)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,  rI   r-  rÖ   r,   rC   r#   r   s    r   Útest_pauseStopResumeÚ"RunStateTests.test_pauseStopResumed  sT   € ð 	�	‰	�‰ÔØ�	‰	�‰ÔØ�	‰	×ÑÔØ�‰×ÑÔØ×Ñ˜Ÿ™ BÕ'r   c                 ób  • U R                  5         U R                  R                  5         U R                  R	                  5       nU R                  U R                  R                  S5        / nUR                  UR                  5        U R                  R                  5         U R                  R                  5         U R                  R                  5         UR                  S5        U R                  R                  5         U R                  US/5        U R                  U R                  / 5        g)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.
r”   é   N)r  rÖ   r,   r#   rÜ   rC   r   Ú_pauseCountrØ   r&   rI   rj   )r   rP   rR  s      r   Útest_stopDeferredÚRunStateTests.test_stopDeferredp  sÍ   € ð 	�‰ÔØ�‰×ÑÔØ�I‰I�M‰M‹OˆØ×Ñ˜Ÿ™×.Ñ.°Ô2ØˆØ	�	‰	�'—.‘.Ô!Ø�‰×ÑÔØ�	‰	�‰ÔØ�‰×ÑÔØ	�
‰
�1ŒØ�‰×ÑÔð
 	×Ñ˜ 4 &Ô)à×Ñ˜Ÿ™ BÕ'r   c                 óÀ   • U R                  5         U R                  R                  5         U R                  [        R
                  U R                  R                  5        g)z`
C{stop()}ping a L{CooperativeTask} whose iterator has been exhausted
should raise L{TaskDone}.
N)r"  rÖ   r,   r1  r   ÚTaskDonerI   r   s    r   Útest_stopExhaustedÚ RunStateTests.test_stopExhaustedŠ  s9   € ð
 	�‰ŒØ�‰×ÑÔØ×Ñœ$Ÿ-™-¨¯©¯©Õ8r   c                 óÀ   • U R                  5         U R                  R                  5         U R                  [        R
                  U R                  R                  5        g)zh
C{stop()}ping a L{CooperativeTask} whose iterator has encountered an
error should raise L{TaskFailed}.
N)r)  rÖ   r,   r1  r   Ú
TaskFailedrI   r   s    r   Útest_stopErroredÚRunStateTests.test_stopErrored“  s9   € ð
 	�‰ŒØ�‰×ÑÔØ×Ñœ$Ÿ/™/¨4¯9©9¯>©>Õ:r   c                 ó  ^ ^• / mUU 4S jnT R                   R                  5       R                  U5        T R                  5         T R                  R                  5         T R                  TT R                   R                  S/5        g)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                 ó~   >• TR                  U 5        TR                  R                  5         TR                  S5        g )Nr1   )r&   r  rI   )rE   ÚcallbackPhasesr   s    €€r   ÚstopitÚ;RunStateTests.test_stopCooperatorReentrancy.<locals>.stopit§  s1   ø€ Ø×!Ñ! &Ô)Ø�O‰O× Ñ Ô"ð ×!Ñ! &Õ)r   r1   N)r   rG  rL   r"  rÖ   r,   rC   rI  )r   rs  rr  s   ` @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.  r3  r6  r;  rN  rS  rX  r[  r^  ra  rf  rj  rn  ru  r   r   r   r   r  r  e  so   † ñò ò&ò*ò!ò ò
ò/ò,	<ò)ò,*ò0)&òVSòNò	9ò(ò
(ò(ò49ò;õHr   r  N)r   Útwisted.internetr   r   r   Útwisted.trialr   r   r   ÚTestCaser/   Ú	Exceptionrü   rþ   r  r   r   r   Ú<module>r{     sr   ðñ÷ 2Ñ 1Ý "÷ñ ÷&ñ ô:F$�h×'Ñ'ô F$ôR˜ô ô�×"Ñ"ô ô0MH�H×%Ñ%õ MHr   