o
    Òó·iµ  ã                   @  s,  d Z ddlmZ ddlmZ zddlmZ W n ey#   dZdZ	Y n9w dZddl
mZ dd	lmZmZ dd
lmZ d dd„Zd dd„ e dd¡ d¡D ƒ¡ZedƒZedurZeneZ	ddlmZ ddlmZ ddlmZmZ estdZe	du p{e	dvZde e	ƒ› �Z!es‹ddlm"Z" G dd„ deeƒZ#dS )!z\
GObject Introspection reactor tests; i.e. `gireactor` module for gio/glib/gtk
integration.
é    )Úannotations)ÚskipIf)ÚGioFNT)Úenviron)Úget_required_versionÚrequire_version)Ú	gireactorÚsomeVersionÚstrÚreturnc              
   C  s>   zt d| ƒ W dS  ty } z
t|ƒW  Y d }~S d }~ww )NÚGtkÚ )r   Ú
ValueErrorr
   )r	   Úve© r   újC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/internet/test/test_gireactor.pyÚrequireEach   s   ý€ÿr   z, c                 c  s   � | ]}t |ƒV  qd S )N)r   )Ú.0Úversionr   r   r   Ú	<genexpr>"   s
   € ÿ
ÿr   ZTWISTED_TEST_GTK_VERSIONz4.0,3.0ú,r   )ÚReactorAlreadyRunning)ÚReactorBuilder)ÚSkipTestÚTestCasez0GObject Introspection `gi` module not importable)z3.0z4.0zUnknown GTK version: )r   c                   @  st   e Zd ZdZddd	„Zdd
d„Zeeeƒddd„ƒZ	eeeƒddd„ƒZ
ddd„Zddd„Zddd„Zddd„ZdS )ÚGApplicationRegistrationTestsa  
    GtkApplication and GApplication are supported by
    L{twisted.internet.gtk3reactor} and L{twisted.internet.gireactor}.

    We inherit from L{ReactorBuilder} in order to use some of its
    reactor-running infrastructure, but don't need its test-creation
    functionality.
    ÚappúGio.ApplicationÚreactorúgireactor.GIReactorr   ÚNonec                   sv   t |dƒs	tdƒ‚g ‰d‡ ‡fdd„‰d‡ ‡‡fd	d
„}| d|¡ | ¡  ˆ  |¡ t | ˆ ¡ |  ˆddg¡ dS )z˜
        Register the app, run the reactor, make sure app was activated, and
        that reactor was running, and that reactor can be stopped.
        Úquitz Version of PyGObject is too old.r   r    c                     s   ˆ  d¡ ˆ  ¡  d S )NÚstopped)ÚappendÚstopr   )r   Úresultr   r   r$   R   s   
z6GApplicationRegistrationTests.runReactor.<locals>.stopÚwidgetÚobjectc                   s   ˆ  d¡ ˆ  dˆ¡ d S )NÚ	activatedr   )r#   Ú	callLater)r&   ©r   r%   r$   r   r   ÚactivateV   s   
z:GApplicationRegistrationTests.runReactor.<locals>.activater+   r(   r"   N©r   r    )r&   r'   r   r    )Úhasattrr   ÚconnectZholdÚregisterGApplicationr   Ú
runReactorÚassertEqual)Úselfr   r   r+   r   r*   r   r0   D   s   
	
z(GApplicationRegistrationTests.runReactorc                 C  s4   dd„ | _ |  ¡ }tjdtjjd�}|  ||¡ dS )zR
        L{Gio.Application} instances can be registered with a gireactor.
        c                   S  ó   t jdd�S ©NF)ZuseGtk©r   Ú	GIReactorr   r   r   r   Ú<lambda>j   ó    zIGApplicationRegistrationTests.test_gApplicationActivate.<locals>.<lambda>ú!com.twistedmatrix.trial.gireactor©Zapplication_idÚflagsN)ÚreactorFactoryÚbuildReactorr   ÚApplicationÚApplicationFlagsÚ
FLAGS_NONEr0   ©r2   r   r   r   r   r   Útest_gApplicationActivatef   s   
þz7GApplicationRegistrationTests.test_gApplicationActivatec                 C  sn   ddl m}m}m} |  |tj¡ |  |tj¡ |  |tj¡ |  ¡ }|  	t
|ƒd¡ |  d|d d ¡ dS )z‡
        L{twisted.internet.gtk3reactor} is now just a set of compatibility
        aliases for L{twisted.internet.GIReactor}.
        r   )ÚGtk3ReactorÚPortableGtk3ReactorÚinstallé   z+twisted.internet.gtk3reactor was deprecatedÚmessageN)Ztwisted.internet.gtk3reactorrC   rD   rE   ZassertIsr   r6   ÚPortableGIReactorZflushWarningsr1   ÚlenZassertIn)r2   rC   rD   rE   Úwarningsr   r   r   Útest_gtkAliasess   s   ÿz-GApplicationRegistrationTests.test_gtkAliasesc                 C  s2   t j| _|  ¡ }tjdtjjd�}|  	||¡ dS )zT
        L{Gtk.Application} instances can be registered with a gtk3reactor.
        z#com.twistedmatrix.trial.gtk3reactorr:   N)
r   r6   r<   r=   r   r>   r   r?   r@   r0   rA   r   r   r   Útest_gtkApplicationActivateˆ   s   þz9GApplicationRegistrationTests.test_gtkApplicationActivatec                 C  s6   t j| _|  ¡ }tjdtjjd�}|  t	|j
|¡ dS )zo
        L{gireactor.PortableGIReactor} doesn't support application
        registration at this time.
        r9   r:   N)r   rH   r<   r=   r   r>   r?   r@   ÚassertRaisesÚNotImplementedErrorr/   rA   r   r   r   Útest_portable•   s   þz+GApplicationRegistrationTests.test_portablec                 C  sB   dd„ | _ |  ¡ }tƒ }|  t|j|¡}|  |jd  d¡¡ dS )zp
        Older versions of PyGObject lack C{Application.quit}, and so won't
        allow registration.
        c                   S  r3   r4   r5   r   r   r   r   r7   §   r8   z;GApplicationRegistrationTests.test_noQuit.<locals>.<lambda>r   zApplication registration is notN)	r<   r=   r'   rM   ÚRuntimeErrorr/   Ú
assertTrueÚargsÚ
startswith)r2   r   r   Úexcr   r   r   Útest_noQuit¢   s
   
z)GApplicationRegistrationTests.test_noQuitc                   sR   dd„ ˆ_ ˆ ¡ ‰tjdtjjd�‰ d‡ ‡‡fdd„}ˆ d	|¡ t ˆˆ¡ d
S )zp
        It is not possible to register a C{Application} after the reactor has
        already started.
        c                   S  r3   r4   r5   r   r   r   r   r7   ³   r8   zIGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.<lambda>r9   r:   r   r    c                    s.   ˆ  tˆjˆ ¡} ˆ | jd d¡ ˆ ¡  d S )Nr   z5Can't register application after reactor was started.)rM   r   r/   r1   rR   r$   )rT   ©r   r   r2   r   r   ÚtryRegisterº   s   ÿ
ÿzLGApplicationRegistrationTests.test_cantRegisterAfterRun.<locals>.tryRegisterr   Nr,   )	r<   r=   r   r>   r?   r@   r)   r   r0   )r2   rW   r   rV   r   Útest_cantRegisterAfterRun®   s   
þ	z7GApplicationRegistrationTests.test_cantRegisterAfterRunc                 C  sf   dd„ | _ |  ¡ }tjdtjjd�}| |¡ tjdtjjd�}|  t|j|¡}|  	|j
d d¡ dS )	zN
        It is not possible to register more than one C{Application}.
        c                   S  r3   r4   r5   r   r   r   r   r7   Ê   r8   zFGApplicationRegistrationTests.test_cantRegisterTwice.<locals>.<lambda>r9   r:   z"com.twistedmatrix.trial.gireactor2r   z2Can't register more than one application instance.N)r<   r=   r   r>   r?   r@   r/   rM   rP   r1   rR   )r2   r   r   Zapp2rT   r   r   r   Útest_cantRegisterTwiceÆ   s   
þ
þ
ÿz4GApplicationRegistrationTests.test_cantRegisterTwiceN)r   r   r   r   r   r    r,   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   rB   r   Ú	noGtkSkipÚnoGtkMessagerK   rL   rO   rU   rX   rY   r   r   r   r   r   :   s    
	
"


r   )r	   r
   r   r
   )$r]   Ú
__future__r   Zunittestr   Zgi.repositoryr   ÚImportErrorZ
giImportedZ
gtkVersionÚosr   Zgir   r   Ztwisted.internetr   r   ÚjoinÚgetÚsplitZerrorMessageZactualVersionZtwisted.internet.errorr   Z#twisted.internet.test.reactormixinsr   Ztwisted.trial.unittestr   r   Úskipr^   Úreprr_   r   r   r   r   r   r   Ú<module>   s:   þ

þ