U
    n5{iF  ã                   @   sˆ   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ G dd„ deƒZG d	d
„ d
eƒZeƒ  e ¡ ¡ eƒ  e ¡ ¡ dS )z/
Tests for implementations of L{IReactorTime}.
é    )ÚIReactorThreadsÚIReactorTime)ÚReactorBuilder)Úmsg)Úplatform)ÚSkipTestc                   @   s&   e Zd ZdZefZdd„ Zdd„ ZdS )ÚTimeTestsBuilderzA
    Builder for defining tests relating to L{IReactorTime}.
    c                 C   s"   |   ¡ }| d|j¡ | ¡  dS )z?
        The reactor can be stopped by a delayed call.
        r   N)ÚbuildReactorÚ	callLaterÚstopÚrun)ÚselfÚreactor© r   úC/tmp/pip-unpacked-wheel-mnhg7r0q/twisted/internet/test/test_time.pyÚtest_delayedCallStopsReactor   s    z-TimeTestsBuilder.test_delayedCallStopsReactorc                    sˆ   |   ¡ ‰t ˆ¡rdd„ ‰ ntdƒ‚ˆ dd d dd„ ¡}‡fd	d
„‰ˆ ˆ‡ ‡‡fdd„ƒ ˆ ¡  |  | ¡ ¡ |  |ˆ 	¡ ¡ dS )z
        Scheduling a delayed call at a point in the extreme future does not
        prevent normal reactor operation.
        c                 S   s   t d|d� |  |¡ d S )Nz.Thread-based event-source scheduling %(event)r)ÚformatÚevent)r   ZcallFromThread)r   r   r   r   r   ÚeventSource&   s
     ÿz=TimeTestsBuilder.test_distantDelayedCall.<locals>.eventSourcez=Do not know how to synthesize non-time event to stop the testé   é€   é   c                   S   s   d S ©Nr   r   r   r   r   Ú<lambda>2   ó    z:TimeTestsBuilder.test_distantDelayedCall.<locals>.<lambda>c                      s   t dƒ ˆ  ¡  d S )NzStopping the reactor)r   r   r   )r   r   r   r   4   s    z6TimeTestsBuilder.test_distantDelayedCall.<locals>.stopc                      s
   ˆ ˆˆƒS r   r   r   ©r   r   r   r   r   r   <   r   N)
r	   r   Z
providedByr   r
   r   Ú
assertTrueÚactiveZassertInZgetDelayedCalls)r   ZdelayedCallr   r   r   Útest_distantDelayedCall   s    

ÿz(TimeTestsBuilder.test_distantDelayedCallN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚrequiredInterfacesr   r   r   r   r   r   r      s   r   c                   @   s0   e Zd ZdZefZe ¡ rdndgZdd„ Z	dS )ÚGlibTimeTestsBuilderza
    Builder for defining tests relating to L{IReactorTime} for reactors based
    off glib.
    z,twisted.internet.gireactor.PortableGIReactorz$twisted.internet.gireactor.GIReactorc                    sb   ddl m} |  ¡ ‰g ‰‡ ‡fdd„}‡‡fdd„‰ ˆ |jd|¡ |  ˆd¡ |  ˆd	g¡ d
S )z¶
        A
        L{reactor.callLater<twisted.internet.interfaces.IReactorTime.callLater>}
        call scheduled from a C{gobject.timeout_add}
        call is run on time.
        r   )ÚGObjectc                      s   ˆ  dˆ ¡ dS )Nr   )r
   r   )Úcallbackr   r   r   Ú	gschedulef   s    z8GlibTimeTestsBuilder.test_timeout_add.<locals>.gschedulec                      s   ˆ  d¡ ˆ  ¡  d S )NT)Úappendr   r   )r   Úresultr   r   r&   j   s    
z7GlibTimeTestsBuilder.test_timeout_add.<locals>.callbacké
   é   TN)Zgi.repositoryr%   r	   ZcallWhenRunningZtimeout_addZ
runReactorÚassertEqual)r   r%   r'   r   )r&   r   r)   r   Útest_timeout_addY   s    z%GlibTimeTestsBuilder.test_timeout_addN)
r   r    r!   r"   r   r#   r   Z	isWindowsZ	_reactorsr-   r   r   r   r   r$   K   s   ÿýr$   N)r"   Ztwisted.internet.interfacesr   r   Z#twisted.internet.test.reactormixinsr   Ztwisted.python.logr   Ztwisted.python.runtimer   Ztwisted.trial.unittestr   r   r$   ÚglobalsÚupdateZmakeTestCaseClassesr   r   r   r   Ú<module>   s   <(