+
    Dfju+                         R t ^ RIt^ RIt^ RIHt ^ RIHtHtHtH	t	H
t
Ht ^ RIHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ R	IHt  ! R
 R]4      t]! 4       P7                  ]P9                  4       4       R# )z/
Tests for implementations of L{IReactorCore}.
N)	FrameType)CallableListOptionalTupleUnioncast)FileDescriptor)Deferred)ReactorAlreadyRunningReactorNotRestartable)ReactorBuilderFailure)SynchronousTestCasec                      a  ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR lt	V 3R lR lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR# ) SystemEventTestsBuilderzo
Builder defining tests relating to L{IReactorCore.addSystemEventTrigger}
and L{IReactorCore.fireSystemEvent}.
c                   < V ^8  d   QhRR/#    returnN )format__classdict__s   "A/usr/lib/python3/dist-packages/twisted/internet/test/test_core.py__annotate__$SystemEventTestsBuilder.__annotate__   s     Q Q Q    c                    V P                  4       p\        \        V 4      P                  \        VP
                  4       R# )z]
C{reactor.stop()} raises L{RuntimeError} when called when the reactor
has not been started.
N)buildReactorr   r   assertRaisesRuntimeErrorstopselfreactors   & r   test_stopWhenNotStarted/SystemEventTestsBuilder.test_stopWhenNotStarted   s.    
 ##% $'44\7<<Pr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   $   s     Q QT Qr   c                    V P                  4       pVP                  VP                  4       V P                  V4       \	        \
        V 4      P                  \        VP                  4       R# )zZ
C{reactor.stop()} raises L{RuntimeError} when called after the reactor
has been stopped.
N)r   callWhenRunningr"   
runReactorr   r   r    r!   r#   s   & r   test_stopWhenAlreadyStopped3SystemEventTestsBuilder.test_stopWhenAlreadyStopped$   sL    
 ##%-  $'44\7<<Pr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   .   s     Q Q4 Qr   c                6   V P                  4       p. pVP                  VP                  R4       VP                  VP                  R4       VP                  VP                  4       V P	                  V4       \        \        V 4      P                  VRR.4       R# )zU
Functions are run in the order that they were passed to
L{reactor.callWhenRunning}.
firstsecondN)r   r*   appendr"   r+   r   r   assertEqualr$   r%   eventss   &  r   test_callWhenRunningOrder1SystemEventTestsBuilder.test_callWhenRunningOrder.   sz    
 ##%w7x8-  $'33FWh<OPr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   ;   s     V Vd Vr   c           	       aa V P                  4       o/ oR VV3R llpR VV3R llpR VV3R llp\        \        V 4      pSP                  RRV4       SP                  R	RV4       SP                  R
RV4       SP	                  SP
                  4       VP                  S/ 4       V P                  S4       VP                  SRRR	RR
R/4       R# )z
The reactor is not running when C{"before"} C{"startup"} triggers are
called and is running when C{"during"} and C{"after"} C{"startup"}
triggers are called.
c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   JSystemEventTestsBuilder.test_runningForStartupEvents.<locals>.__annotate__D        	. 	.t 	.r   c                  &   < S P                   SR &   R# beforeNrunningr%   states   r   beforeStartupKSystemEventTestsBuilder.test_runningForStartupEvents.<locals>.beforeStartupD       %ooE(Or   c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   r;   G   r<   r   c                  &   < S P                   SR &   R# )duringNr@   rB   s   r   duringStartupKSystemEventTestsBuilder.test_runningForStartupEvents.<locals>.duringStartupG   rF   r   c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   r;   J   s     	- 	-d 	-r   c                  &   < S P                   SR &   R# afterNr@   rB   s   r   afterStartupJSystemEventTestsBuilder.test_runningForStartupEvents.<locals>.afterStartupJ   s    $__E'Nr   r?   startuprI   rO   FTN)r   r   r   addSystemEventTriggerr*   r"   r3   r+   )r$   rD   rJ   rP   testCaser%   rC   s   &    @@r   test_runningForStartupEvents4SystemEventTestsBuilder.test_runningForStartupEvents;   s     ##%	. 	.	. 	.	- 	- +T2%%h	=I%%h	=I%%gy,G-UB' UXuhgt$TUr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   W   s      -  -4  -r   c                  aa V P                  4       pRoR V3R llpR V3R llpVP                  RRV4       VP                  RRV4       . oR	 VV3R
 llp\        \        V 4      pVP	                  \
        RV4       VP                  VP                  4       VP                  S4       VP                  S. 4       V P                  V4       VP                  RS4       VP                  SR4       R# )zM
Signal handlers are installed in responsed to the C{"during"}
C{"startup"}.
Nc                    V ^8  d   QhRR/# r   r   )r   s   "r   r   WSystemEventTestsBuilder.test_signalHandlersInstalledDuringStartup.<locals>.__annotate___   s     	 	t 	r   c                     < R o R# r>   r   phases   r   rD   XSystemEventTestsBuilder.test_signalHandlersInstalledDuringStartup.<locals>.beforeStartup_   s    Er   c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   rZ   c   s     	 	d 	r   c                     < R o R# rN   r   r\   s   r   rP   WSystemEventTestsBuilder.test_signalHandlersInstalledDuringStartup.<locals>.afterStartupc   s    Er   r?   rR   rO   c                Z    V ^8  d   QhR\         R\        \         \        .R3,          RR/# )r   signumactionNr   )intr   r   )r   s   "r   r   rZ   l   s1     	# 	#s 	#Hc95Et5K,L 	#QU 	#r   c                 *   < SP                  S4       R # Nr2   )rc   rd   r]   sawPhases   &&r   
fakeSignalUSystemEventTestsBuilder.test_signalHandlersInstalledDuringStartup.<locals>.fakeSignall   s    OOE"r   signal)r   rS   r   r   patchrl   r*   r"   assertIsNoner3   r+   assertIn)r$   r%   rD   rP   rj   rT   r]   ri   s   &     @@r   )test_signalHandlersInstalledDuringStartupASystemEventTestsBuilder.test_signalHandlersInstalledDuringStartupW   s    
 ##%#	 		 	 	%%h	=I%%gy,G	# 	# +T2vx4-e$Xr* (H-UG,r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   y   s     
 
 
r   c                R  a V P                  4       p. oVP                  RRV3R l4       VP                  RRV3R l4       VP                  RRV3R l4       VP                  VP                  4       V P	                  V4       \        \        V 4      P                  S. R	O4       R# )
zn
C{reactor.stop()} fires all three phases of shutdown event triggers
before it makes C{reactor.run()} return.
r?   shutdownc                  &   < S P                  R4      # r?   r?   rt   rh   r5   s   r   <lambda>ASystemEventTestsBuilder.test_stopShutDownEvents.<locals>.<lambda>       &--8N*Or   rI   c                  &   < S P                  R4      # )rI   rI   rt   rh   rx   s   r   ry   rz      r{   r   rO   c                  &   < S P                  R4      # )rO   rO   rt   rh   rx   s   r   ry   rz      s    7L)Mr   N)rw   r}   r   )r   rS   r*   r"   r+   r   r   r3   r4   s   & @r   test_stopShutDownEvents/SystemEventTestsBuilder.test_stopShutDownEventsy   s    
 ##%%%j"O	
 	%%j"O	
 	%%Z!M	
 	-  $'33S	
r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     E E$ Er   c                .  aa V P                  4       o. oSP                  RRSP                  R4       R VV3R llp\        \        V 4      pSP                  V4       VP                  S. 4       V P                  S4       VP                  SRR.4       R# )zT
C{"before"} C{"shutdown"} triggers are not run synchronously from
L{reactor.stop}.
r?   rt   zbefore shutdownc                    V ^8  d   QhRR/# r   r   )r   s   "r   r   VSystemEventTestsBuilder.test_shutdownFiresTriggersAsynchronously.<locals>.__annotate__   s     	% 	% 	%r   c                  J   < SP                  4        S P                  R 4       R# )stoppedN)r"   r2   r5   r%   s   r   stopItPSystemEventTestsBuilder.test_shutdownFiresTriggersAsynchronously.<locals>.stopIt   s    LLNMM)$r   r   N)r   rS   r2   r   r   r*   r3   r+   )r$   r   rT   r5   r%   s   &  @@r   (test_shutdownFiresTriggersAsynchronously@SystemEventTestsBuilder.test_shutdownFiresTriggersAsynchronously   s    
 ##%%%j&--1B	
	% 	% +T2'VR( Vi1B%CDr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     ' ' 'r   c                  aa R.o ! R R\         4      p ! V3R lR\         4      p\        \        V 4      pV P                  4       p\	        V! 4       V! 4       .4      oV3R lVn        VP                  VP                  4       V P                  V4       VP                  \        VP                  \        4      4      ^4       VP                  S^ ,          4       R# )z
A L{IFileDescriptor.connectionLost} implementation which raises an
exception does not prevent the remaining L{IFileDescriptor}s from
having their C{connectionLost} method called.
Fc                   2   a  ] tR t^t o V 3R lR ltRtV tR# )ZSystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.ProblematicFileDescriptorc                $   < V ^8  d   QhRS[ RR/# r   reasonr   Nr   )r   r   s   "r   r   gSystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.ProblematicFileDescriptor.__annotate__   s     E EW E Er   c                    \        R 4      h)zsimulated connectionLost error)r!   )r$   r   s   &&r   connectionLostiSystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.ProblematicFileDescriptor.connectionLost   s    "#CDDr   r   N__name__
__module____qualname____firstlineno__r   __static_attributes____classdictcell__r   s   @r   ProblematicFileDescriptorr      s     E Er   r   c                   :   <a  ] tR t^t o V 3R lV3R lltRtV tR# )QSystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.OKFileDescriptorc                $   < V ^8  d   QhRS[ RR/# r   r   )r   r   s   "r   r   ^SystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.OKFileDescriptor.__annotate__   s     ! !W ! !r   c                   < R S^ &   R# )TNr   )r$   r   lostOKs   &&r   r   `SystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.OKFileDescriptor.connectionLost   s     q	r   r   Nr   )r   r   s   @r   OKFileDescriptorr      s     ! ! !r   r   c                     < S # rg   r   )fdss   r   ry   ISystemEventTestsBuilder.test_shutdownDisconnectsCleanly.<locals>.<lambda>   s    Cr   N)r	   r   r   r   iter	removeAllr*   r"   r+   r3   lenflushLoggedErrorsr!   
assertTrue)r$   r   r   rT   r%   r   r   s   &    @@r   test_shutdownDisconnectsCleanly7SystemEventTestsBuilder.test_shutdownDisconnectsCleanly   s     	E 	E	!~ 	! +T2##% -/1A1CDE'- S!;!;L!IJANF1I&r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     1 1$ 1r   c                  aaa . o\        \        V 4      oR VVV3R llpV P                  4       oSP                  V4       SP                  SP                  4       V P                  S4       SP                  SR.4       R# )zc
C{reactor.run()} raises L{ReactorAlreadyRunning} when called when
the reactor is already running.
c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   >SystemEventTestsBuilder.test_multipleRun.<locals>.__annotate__   s     	$ 	$d 	$r   c                  j   < SP                  \        SP                  4       S P                  R 4       R# testedN)r    r   runr2   r5   r%   rT   s   r   reentrantRun>SystemEventTestsBuilder.test_multipleRun.<locals>.reentrantRun   $    !!"7EMM(#r   r   N)r   r   r   r*   r"   r+   r3   )r$   r   r5   r%   rT   s   & @@@r   test_multipleRun(SystemEventTestsBuilder.test_multipleRun   so    
 +T2	$ 	$ ##%-- VhZ0r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     U Ud Ur   c                   aaa . oR VVV3R llpR VV3R lloV P                  4       oSP                  RRV4       V P                  S4       \        \        V 4      P                  SRR.4       R	# )
z
When there is a C{'before'} C{'startup'} trigger which returns an
unfired L{Deferred}, C{reactor.run()} starts the reactor and does not
return until after C{reactor.stop()} is called
c                :    V ^8  d   QhR\         \        ,          /# )r   r   )r
   object)r   s   "r   r   ZSystemEventTestsBuilder.test_runWithAsynchronousBeforeStartupTrigger.<locals>.__annotate__   s     	 	&) 	r   c                     < SP                  R 4       \        4       p V P                  S4       SP                  ^ V P                  R4       V # )triggerN)r2   r
   addCallback	callLatercallback)dr   r5   r%   s    r   r   USystemEventTestsBuilder.test_runWithAsynchronousBeforeStartupTrigger.<locals>.trigger   s=    MM)$"**AMM(#aT2Hr   c                (    V ^8  d   QhR\         RR/# )r   ignoredr   N)r   )r   s   "r   r   r      s     	 	f 	 	r   c                 J   < SP                  R 4       SP                  4        R# )r   N)r2   r"   )r   r5   r%   s   &r   r   VSystemEventTestsBuilder.test_runWithAsynchronousBeforeStartupTrigger.<locals>.callback   s    MM*%LLNr   r?   rR   r   r   N)r   rS   r+   r   r   r3   )r$   r   r   r5   r%   s   & @@@r   ,test_runWithAsynchronousBeforeStartupTriggerDSystemEventTestsBuilder.test_runWithAsynchronousBeforeStartupTrigger   si     	 		 	 ##%%%h	7C  $'33FY
<STr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s      d r   c                F   V P                  4       pVP                  ^VP                  4      p\        P                  ! 4       pVP	                  ^ 4       \        P                  ! 4       V,
          p\        \        V 4      P                  V^8  4       VP                  4        R# )z&
C{reactor.iterate()} does not block.
N)	r   r   crashtimeiterater   r   r   cancel)r$   r%   tstartelapseds   &    r   test_iterate$SystemEventTestsBuilder.test_iterate   sr     ##%a/		))+% $'227Q;?	
r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     
 
D 
r   c                D  a V P                  4       p. oVP                  RRV3R l4       VP                  VP                  ^ VP                  4       V P                  V4       \        \        V 4      pVP                  VP                  4       VP                  SR4       R# )zK
C{reactor.crash()} stops the reactor and does not fire shutdown
triggers.
r?   rt   c                  &   < S P                  R4      # rv   rh   rx   s   r   ry   4SystemEventTestsBuilder.test_crash.<locals>.<lambda>  r{   r   z8Shutdown triggers invoked but they should not have been.N)
r   rS   r*   r   r   r+   r   r   assertFalserA   )r$   r%   rT   r5   s   &  @r   
test_crash"SystemEventTestsBuilder.test_crash   s    
 ##%%%j"O	
 	 1 11gmmD +T2W__-N	
r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     W WD Wr   c                "  aa . oR VV3R llpV P                  4       oSP                  V4       V P                  S4       R VV3R llpSP                  V4       V P                  S4       \        \        V 4      P                  SRR.4       R# )zX
C{reactor.run()} restarts the reactor after it has been stopped by
C{reactor.crash()}.
c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   @SystemEventTestsBuilder.test_runAfterCrash.<locals>.__annotate__  s     	 	t 	r   c                  J   < S P                  R 4       SP                  4        R# )r   N)r2   r   r   s   r   r   9SystemEventTestsBuilder.test_runAfterCrash.<locals>.crash  s    MM'"MMOr   c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   r      s     	 	d 	r   c                  b   < S P                  R SP                  34       SP                  4        R# )r"   N)r2   rA   r"   r   s   r   r"   8SystemEventTestsBuilder.test_runAfterCrash.<locals>.stop   s!    MM67??34LLNr   r   N)r"   T)r   r*   r+   r   r   r3   )r$   r   r"   r5   r%   s   &  @@r   test_runAfterCrash*SystemEventTestsBuilder.test_runAfterCrash  s    
 68	 	 ##%& 	 	 	%  $'33FWn<UVr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   (  s     1 14 1r   c                
  aaa . o\        \        V 4      oR VVV3R llpV P                  4       oSP                  SP                  4       SP                  RRV4       V P                  S4       SP                  SR.4       R# )z{
C{reactor.run()} raises L{ReactorNotRestartable} when called when
the reactor is being run after getting stopped priorly.
c                    V ^8  d   QhRR/# r   r   )r   s   "r   r   ?SystemEventTestsBuilder.test_runAfterStop.<locals>.__annotate__1  s     	$ 	$ 	$r   c                  j   < SP                  \        SP                  4       S P                  R 4       R# r   )r    r   r   r2   r   s   r   restart:SystemEventTestsBuilder.test_runAfterStop.<locals>.restart1  r   r   rO   rt   r   N)r   r   r   r*   r"   rS   r+   r3   )r$   r   r5   r%   rT   s   & @@@r   test_runAfterStop)SystemEventTestsBuilder.test_runAfterStop(  ss    
 +T2	$ 	$ ##%-%%gz7C VhZ0r   r   N)r   r   r   r   __doc__r&   r,   r6   rU   rp   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r      s     
Q QQ QQ QV V8 -  -D
 
.E E,' '@1 1&U U0 
 
$W W.1 1r   r   )r   rl   r   typesr   typingr   r   r   r   r   r   twisted.internet.abstractr	   twisted.internet.deferr
   twisted.internet.errorr   r   #twisted.internet.test.reactormixinsr   twisted.python.failurer   twisted.trial.unittestr   r   globalsupdatemakeTestCaseClassesr   r   r   <module>r     sX   
    ? ? 4 + O > * 6c1n c1L	 	  (<<> ?r   