
    Vh`                         d dl mZmZ d dlmZ ddlmZ ereZneZd	dZ	 e	         G d dee      Z
 e       j                  e
j                                y)
    )TYPE_CHECKINGList)SynchronousTestCase   )ReactorBuilderNc                       y)z0
    Do-nothing callable. Stub for testing.
    N r	       T/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/test/test_cfreactor.pynoopr      s    r
   c                   6    e Zd ZdZdgZddZddZddZddZy)	CoreFoundationSpecificTestszN
    Tests for platform interactions of the CoreFoundation-based reactor.
    z$twisted.internet.cfreactor.CFReactorNc                     | j                         }|j                  d|j                         |j                  dt               | j	                  |       | j                  |j                  d       y)zO
        CFReactor's simulation timer is None after CFReactor crashes.
        r   d   N)buildReactor	callLatercrashr   
runReactorassertIs_currentSimulator)selfrs     r   test_whiteboxStopSimulatingz7CoreFoundationSpecificTests.test_whiteboxStopSimulating   sR     	Aqww	Ca))40r
   c                    | j                         }|j                  dt              }| j                         dfd}dfdj                  d|       | j                         | j	                  |j                         |g       y)a\  
        callLater should not leak global state into CoreFoundation which will
        be invoked by a different reactor running the main loop.

        @note: this test may actually be usable for other reactors as well, so
            we may wish to promote it to ensure this invariant across other
            foreign-main-loop reactors.
        r   Nc                  *     j                  d       y )Nr   )r   )r2r2stops   r   stopBlockingzGCoreFoundationSpecificTests.test_callLaterLeakage.<locals>.stopBlocking3   s    LLF#r
   c                  &     j                          y N)stop)r   s   r   r   zACoreFoundationSpecificTests.test_callLaterLeakage.<locals>.r2stop6   s    GGIr
   returnN)r   r   r   r   assertEqualgetDelayedCalls)r   r   delayedr   r   r   s       @@r   test_callLaterLeakagez1CoreFoundationSpecificTests.test_callLaterLeakage&   sr     ++a& 	$	 	Q%**,wi8r
   c                 N   | j                         }g }|j                  d|j                  d       |j                  dt              }|j	                          | j                  |j                  d       | j                  |j                         |g       | j                  |dg       y)an  
        C{.iterate()} should remove the CFTimer that will run Twisted's
        callLaters from the loop, even if one is still pending.  We test this
        state indirectly with a white-box assertion by verifying the
        C{_currentSimulator} is set to C{None}, since CoreFoundation does not
        allow us to enumerate all active timers or sources.
        r   r   r   N)	r   r   appendr   iterater   r   r$   r%   )r   r   xr&   s       r   test_whiteboxIteratez0CoreFoundationSpecificTests.test_whiteboxIterate=   s     	Aqxx#++c4(			a))40**,wi8QC r
   c                     | j                         g dfddfd}j                  dj                  |       j                          | j	                  dg       y)zS
        The loop can wake up just fine even if there are no timers in it.
        Nc                  H     j                          j                  d       y )Nyes)r!   r)   )r   stoppeds   r   doStopz9CoreFoundationSpecificTests.test_noTimers.<locals>.doStopU   s    FFHNN5!r
   c                  (    j                          y r    )callFromThread)r1   r   s   r   sleepThenStopz@CoreFoundationSpecificTests.test_noTimers.<locals>.sleepThenStopY   s    V$r
   r   r/   r"   )r   r   callInThreadrunr$   )r   r4   r1   r   r0   s     @@@r   test_noTimersz)CoreFoundationSpecificTests.test_noTimersN   sU     	"	% 	
Aq~~}5
 	
5'*r
   r"   )	__name__
__module____qualname____doc__	_reactorsr   r'   r,   r7   r	   r
   r   r   r      s%     88I19.!"+r
   r   r"   )typingr   r   twisted.trial.unittestr   reactormixinsr   fakeBaseobjectr   r   globalsupdatemakeTestCaseClassesr	   r
   r   <module>rE      sT    & 6 )"HH M+.( M+` 	  ,@@B Cr
   