U
    Jë]j`  ã                   @   sp   d dl mZmZ d dlmZ ddlmZ er2eZneZddœdd„Z	e	ƒ  G d	d
„ d
eeƒZ
eƒ  e
 ¡ ¡ dS )é    )ÚTYPE_CHECKINGÚList)ÚSynchronousTestCaseé   )ÚReactorBuilderN©Úreturnc                   C   s   dS )z0
    Do-nothing callable. Stub for testing.
    N© r	   r	   r	   úmc:\users\psant\downloads\hotstarbackend\school\venv\Lib\site-packages\twisted/internet/test/test_cfreactor.pyÚnoop   s    r   c                   @   sN   e Zd ZdZdgZddœdd„Zddœdd„Zddœd	d
„Zddœdd„ZdS )ÚCoreFoundationSpecificTestszN
    Tests for platform interactions of the CoreFoundation-based reactor.
    z$twisted.internet.cfreactor.CFReactorNr   c                 C   s>   |   ¡ }| d|j¡ | dt¡ |  |¡ |  |jd¡ dS )zO
        CFReactor's simulation timer is None after CFReactor crashes.
        r   éd   N)ÚbuildReactorÚ	callLaterZcrashr   Ú
runReactorÚassertIsÚ_currentSimulator)ÚselfÚrr	   r	   r
   Útest_whiteboxStopSimulating   s
    
z7CoreFoundationSpecificTests.test_whiteboxStopSimulatingc                    sn   |   ¡ }| dt¡}|   ¡ ‰ ddœ‡ ‡fdd„}ddœ‡ fdd„‰ˆ  d|¡ |  ˆ ¡ |  | ¡ |g¡ dS )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   Nr   c                      s   ˆ   dˆ¡ d S )Nr   )r   r	   ©Úr2Úr2stopr	   r
   ÚstopBlocking3   s    zGCoreFoundationSpecificTests.test_callLaterLeakage.<locals>.stopBlockingc                      s   ˆ   ¡  d S ©N)Ústopr	   )r   r	   r
   r   6   s    zACoreFoundationSpecificTests.test_callLaterLeakage.<locals>.r2stop)r   r   r   r   ÚassertEqualÚgetDelayedCalls)r   r   Údelayedr   r	   r   r
   Útest_callLaterLeakage&   s    	
z1CoreFoundationSpecificTests.test_callLaterLeakagec                 C   sb   |   ¡ }g }| d|jd¡ | dt¡}| ¡  |  |jd¡ |  | ¡ |g¡ |  |dg¡ dS )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   Ziterater   r   r   r   )r   r   Úxr   r	   r	   r
   Útest_whiteboxIterate=   s    z0CoreFoundationSpecificTests.test_whiteboxIteratec                    s^   |   ¡ ‰g ‰ddœ‡‡fdd„‰ ddœ‡ ‡fdd„}ˆ dˆj|¡ ˆ ¡  |  ˆdg¡ dS )	zS
        The loop can wake up just fine even if there are no timers in it.
        Nr   c                      s   ˆ   ¡  ˆ d¡ d S )NÚyes)r   r    r	   )r   Ústoppedr	   r
   ÚdoStopU   s    z9CoreFoundationSpecificTests.test_noTimers.<locals>.doStopc                      s   ˆ  ˆ ¡ d S r   )ZcallFromThreadr	   )r%   r   r	   r
   ÚsleepThenStopY   s    z@CoreFoundationSpecificTests.test_noTimers.<locals>.sleepThenStopr   r#   )r   r   ZcallInThreadÚrunr   )r   r&   r	   )r%   r   r$   r
   Útest_noTimersN   s    z)CoreFoundationSpecificTests.test_noTimers)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Z	_reactorsr   r   r"   r(   r	   r	   r	   r
   r      s   
r   )Útypingr   r   Ztwisted.trial.unittestr   Zreactormixinsr   ZfakeBaseÚobjectr   r   ÚglobalsÚupdateZmakeTestCaseClassesr	   r	   r	   r
   Ú<module>   s   P