HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_application.cpython-38.pyc
U


W[0��@s2dZddlmZmZddlZddlZddlZzddlZWnek
rPdZYnXddl	m
Z
mZmZm
Z
ddlmZmZmZmZddlmZddlmZddlmZmZdd	lmZdd
lmZddlmZddl m!Z!dd
l"m#Z#ddl$m%Z%Gdd�d�Z&Gdd�de%j'�Z(e)ed��r0e�*�Z+e�,�Z-ndZ+Z-Gdd�de%j'�Z.Gdd�de%j'�Z/Gdd�de%j'�Z0Gdd�de%j'�Z1Gdd�de%j'�Z2Gdd�dej3�Z4Gd d!�d!�Z5Gd"d#�d#�Z6Gd$d%�d%ej7�Z8Gd&d'�d'e%j'�Z9Gd(d)�d)e%j'�Z:Gd*d+�d+e
j;�Z<Gd,d-�d-e!e%j'�Z=Gd.d/�d/e%j'�Z>dS)0zU
Tests for L{twisted.application} and its interaction with
L{twisted.persisted.sob}.
�)�absolute_import�divisionN)�service�internet�app�reactors)�
interfaces�defer�protocol�reactor)�sob)�twisted_reactors)�wire�basic)�usage)�NativeStringIO)�platformType)�TwistedModulesMixin)�
MemoryReactor)�unittestc@seZdZdZdS)�DummyN)�__name__�
__module__�__qualname__�processName�rr�?/usr/lib/python3/dist-packages/twisted/test/test_application.pyr"src@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�ServiceTestscCs$t��}|�d�|�|jd�dS�N�hello)r�Service�setName�assertEqual�name��self�srrr�testName's
zServiceTests.testNamecCs>t��}t��}|�|�|�t|�|g�|�|j|�dS�N)rr �MultiService�setServiceParentr"�list�parent�r%r&�prrr�
testParent,s

zServiceTests.testParentcCsLt��}t�d�}|�|�|�tt�|��|g�|�|jt�|��dS)N�)rr �Applicationr*r"r+�IServiceCollectionr,r-rrr�testApplicationAsParent3s


z$ServiceTests.testApplicationAsParentcCsZt��}t��}|�d�|�|�|�t|�|g�|�|j|�|�|�d�|�dSr)	rr r)r!r*r"r+r,ZgetServiceNamedr-rrr�testNamedChild:s

zServiceTests.testNamedChildcCs8t��}t��}|�d�|�|�|�t|jd�dS)Nr�lala�rr r)r!r*�assertRaises�RuntimeErrorr-rrr�testDoublyNamedChildCs


z!ServiceTests.testDoublyNamedChildcCsJt��}t��}|�d�|�|�t��}|�d�|�t|j|�dSrr6r-rrr�testDuplicateNamedChildJs


z$ServiceTests.testDuplicateNamedChildcCsbt��}t��}|�|�|�t|�|g�|�|j|�|��|�t|�g�|�|j�dSr()	rr r)r*r"r+r,�disownServiceParent�assertIsNoner-rrr�
testDisowningSs
zServiceTests.testDisowningcCs@t��}|�|j�|��|�|j�|��|�|j�dSr()rr �assertFalse�running�startService�
assertTrue�stopServicer$rrr�testRunning]szServiceTests.testRunningcCsvt��}t��}|�|�|�|j�|�|j�|��|�|j�|�|j�|��|�|j�|�|j�dSr()	rr r)r*r>r?r@rArBr-rrr�testRunningChildren1es
z!ServiceTests.testRunningChildren1csZt�����fdd�}t��}||_||_t��}��|�|�|�|��|��dS)Ncs���j�dSr()rAr?r�r&r%rr�checkRunningtsz7ServiceTests.testRunningChildren2.<locals>.checkRunning)rr rBr@r)r*)r%rF�tr.rrEr�testRunningChildren2rs

z!ServiceTests.testRunningChildren2cCsRt��}|��t��}|�|j�|�|�|�|j�|��|�|j�dSr()	rr)r@r r>r?r*rAr;)r%r.r&rrr�testAddingIntoRunnings
z"ServiceTests.testAddingIntoRunningcsVt����fdd�}|�_t��}t��}��|�|�|�|��|��j�dS)Ncs
d�_dS)N�)�privilegedStartedr�r&rr�pss�sz(ServiceTests.testPrivileged.<locals>.pss)rr �privilegedStartServicer)r*rArK)r%rM�s1r.rrLr�testPrivileged�s

zServiceTests.testPrivilegedcCs6t��}|��t�|�}|�|j�|�|j�dSr()rr r@�copyr>r?rA)r%r&rOrrr�testCopying�s

zServiceTests.testCopyingN)rrrr'r/r3r4r9r:r=rCrDrHrIrPrRrrrrr%s		



r�getuidc@s$eZdZdd�Zdd�Zdd�ZdS)�ProcessTestscCs,t�dd�}|�|jd�|�|jd�dS)N��)r�Processr"�uid�gid�r%r.rrr�testID�szProcessTests.testIDcCsnt�d�}|�|jd�|�|j�tjdd�}|�|j�|�|jd�t��}|�|j�|�|j�dS)NrU)rY)rrWr"rXr<rYrZrrr�testDefaults�s
zProcessTests.testDefaultscCs,t��}|�|j�d|_|�|jd�dSr)rrWr<rr"rZrrr�testProcessName�szProcessTests.testProcessNameN)rrrr[r\r]rrrrrT�srTc@s$eZdZdd�Zdd�Zdd�ZdS)�InterfacesTestscCs|�tj�t����dSr()rAr�IService�
providedByr �r%rrr�testService�szInterfacesTests.testServicecCs0|�tj�t����|�tj�t����dSr()rArr_r`r)r2rarrr�testMultiService�s
�z InterfacesTests.testMultiServicecCs|�tj�t����dSr()rAr�IProcessr`rWrarrr�testProcess�szInterfacesTests.testProcessN)rrrrbrcrerrrrr^�sr^c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ApplicationTestscCs(t�d�t�dd�t�ddd�dS�NrrUrV)rr1rarrr�testConstructor�s
z ApplicationTests.testConstructorcCs�t�d�}|�t�|�j�|�t�|�j�t�dd�}|�t�|�jd�|�t�|�j�t�ddd�}|�t�|�jd�|�t�|�jd�dSrg)rr1r<rdrXrYr"�r%�arrr�testProcessComponent�s
z%ApplicationTests.testProcessComponentcCsLt�d�}|�t�|�t�|��|�t�|�jd�|�t�|�j�dSr)	rr1�assertIsr_r2r"r#r<r,rirrr�testServiceComponent�s
z%ApplicationTests.testServiceComponentcCsBt�d�}t�|�}|�|jd�|�|jd�|�|j|�dS)Nr�pickle)	rr1r�IPersistabler"�styler#rlZoriginal)r%rjr.rrr�testPersistableComponent�s


z)ApplicationTests.testPersistableComponentN)rrrrhrkrmrqrrrrrf�srfc@seZdZdd�ZdS)�LoadingTestsc	Cs�t�d�}t�|�}d��D]>}|�|�|��t�d|d|�}|�t�	|�j
d�qtdd��}|�ddg�W5QRXt�dd	�}|�t�	|�j
d�dS)
Nr�
source picklezhello.tarz	hello.tac�w�(from twisted.application import service
�+application = service.Application('hello')
�python)
rr1rro�split�setStyle�save�loadApplicationr"r_r#�open�
writelines)r%rjr.rp�a1�frrr�test_simpleStoreAndLoad�s


�z$LoadingTests.test_simpleStoreAndLoadN)rrrr�rrrrrr�srrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�AppSupportTestscCs|�t�d��dS)Nr)r<rZ
getPassphraserarrr�testPassphraseszAppSupportTests.testPassphrasec	Cs�t�d�}dddd�}d��D]b}|��}d|ddi�||�<t�|��|�t�|�jdd�t	�
|d�}|�t�|�j
d�q|��}d|d	<tdd
��}|�ddg�W5QRXt	�
|d�}|�t�|�j
d�dS)
zL
        Test loading an application file in different dump format.
        rN)�file�sourcerwrsZhelloapplicationrnr���filenamerwrtrurv)rr1rxrQ�getrroryrzrZgetApplicationr"r_r#r|r})r%rjZ
baseconfigrpZconfigr~rrrr�testLoadApplications$
�z#AppSupportTests.testLoadApplicationc
Cs�t�d�}d��D]h}d��D]Z}t�|��|�t�|�jdd�t�d|dd|d�t�	d|�}|�
t�|�jd�qqdS)Nr5rsZconverttestr�zconverttest.outr)
rr1rxrroryrzrZconvertStyler{r"r_r#)r%�applZinstyleZoutstyleZappl2rrr�test_convertStyles

�z!AppSupportTests.test_convertStylecCs,t�d�}t�|d�|�t�|�j�dS)Nr5r)rr1rZstartApplicationrAr_r?)r%r�rrr�test_startApplication&s
z%AppSupportTests.test_startApplicationN)rrrr�r�r�r�rrrrr��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�FoocCs|j�d�dS)Nslalala
)�	transport�writerarrr�connectionMade-szFoo.connectionMadecCs||j_|j��dSr()�factory�liner�ZloseConnection)r%r�rrr�lineReceived/szFoo.lineReceivedcCs|jj�|jj�dSr()r��d�callbackr��r%�reasonrrr�connectionLost2szFoo.connectionLostN)rrrr�r�r�rrrrr�,sr�c@s eZdZdZdd�Zdd�ZdS)�DummyAppNcCs||j|j<dSr(��servicesr#�r%rrrr�
addService8szDummyApp.addServicecCs|j|j=dSr(r�r�rrr�
removeService:szDummyApp.removeService)rrrrr�r�rrrrr�6sr�c@seZdZdd�Zdd�ZdS)�TimerTargetcCs
g|_dSr(��lrarrr�__init__?szTimerTarget.__init__cCs|j�|�dSr()r��append)r%Zwhatrrrr�AszTimerTarget.appendN)rrrr�r�rrrrr�>sr�c@seZdZdd�ZdS)�TestEchocCs|j�d�dS�NT)r�r�r�rrrr�GszTestEcho.connectionLostN)rrrr�rrrrr�Fsr�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
e�e
d�sjdZee_ee	_ee
_dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�ZdS)#�
InternetTestscs�t������t��}t|_t��t_t	�
d|�}|���|j�
�j}t��}t��|_t|_d|_t	�d||����|j�|jd�|j��fdd��|j�dd��|jS)Nr�	127.0.0.1�lalalacs���Sr(�rB��xrLrr�<lambda>]�z'InternetTests.testTCP.<locals>.<lambda>cSstjSr(�r�r�r�rrrr�^r�)rr)r@r
�
ServerFactoryr�r	�Deferredr�r�	TCPServerr*�_port�getHost�port�
ClientFactoryr�r��	TCPClient�addCallbackr")r%r�rG�numrrLr�testTCPNs"


zInternetTests.testTCPcsjt�td�st�d��t���t�d��}|�	�|j
��j�|�
�d���fdd�}t�|j��|�S)z�
        Test L{internet.UDPServer} with a random port: starting the service
        should give it valid port, and stopService should free it so that we
        can start a server on the same port again.
        Nz)This reactor does not support UDP socketsrcst����}|��|��Sr()r�	UDPServerr@rB)�ignoredrG�r�r.rr�onStoposz&InternetTests.test_UDP.<locals>.onStop)rZIReactorUDPrrZSkipTestr
ZDatagramProtocolrr�r@r�r�r�ZassertNotEqualr	Z
maybeDeferredrBr�)r%rGr�rr�r�test_UDPbs
zInternetTests.test_UDPcs�t��}t|_t��t_t�d|��d�_��	��j
��j}t�
�}t��|_t|_d|_t�d||�����|j�|jd�|j��fdd��|j��fdd��|j�dd��|jS)	NrrJr�r�cs���Sr(r�r�)�crrr��r�z.InternetTests.testPrivileged.<locals>.<lambda>cs���Sr(r�r��rGrrr��r�cSstjSr(r�r�rrrr��r�)r
r�r�r	r�r�rr�Z
privilegedrNr�r�r�r�r�r�r�r@r�r")r%r�r�r)r�rGrrPvs$

zInternetTests.testPrivilegedcspt��}tj|_t�d|�}|��|j��j	}|�
�t���t�
�}�fdd�|_t�d||�}|���S)Nrcs
��d�Sr(�r���args�r�rrr��r�z<InternetTests.testConnectionGettingRefused.<locals>.<lambda>r�)r
r�r�Echorr�r@r�r�r�rBr	r�r��clientConnectionFailedr�)r%r�rGr�r�rr�r�testConnectionGettingRefused�sz*InternetTests.testConnectionGettingRefusedcs�t������t��}t|_t��t_t	�
d|�}|���t��}t
|_t��|_d|_t	�d|����|j�|jd�|j��fdd��|j�dd��|j�|j|��|jS)N�echo.sktr�cs���Sr(r�r�rLrrr��r�z(InternetTests.testUNIX.<locals>.<lambda>cSstjSr(r�r�rrrr��r�)rr)r@r
r�r�r	r�r�r�
UNIXServerr*r�r�r��
UNIXClientr�r"�_cbTestUnix�r%r�rGrrLr�testUNIX�s"


zInternetTests.testUNIXcs\t��t_d|_t��|_���|j�|jd�|j��fdd��|j�dd��|jS)Nr�cs���Sr(r�r�rLrrr��r�z+InternetTests._cbTestUnix.<locals>.<lambda>cSstjSr(r�r�rrrr��r�)r	r�r�r�r�r@r�r")r%r�r�r&rrLrr��s

zInternetTests._cbTestUnixcCs�t��}tj|_t�d|�}|��|�|jd�t	�	|�}|�
|j�|��|�
|j�|�|j
�t��}tj|_t�d|�}|��|�|jd�t	�	|�}|�
|j�|��|�
|j�|�|j
�dS)Nr�)r
r�rr�rr�r@ZfailIfIdenticalr�rQr<rBr>r?r�r�Z_connection)r%r�rG�t1rrr�testVolatile�s(

zInternetTests.testVolatilecsft��}tj|_t�d|�}|��|��|�|j	�t�
�}t����fdd�|_
t�d|��S)Nr�cs
��d�Sr(r�r�r�rrr��r�z2InternetTests.testStoppingServer.<locals>.<lambda>)r
r�rr�rr�r@rBr>r?r�r	r�r�rZconnectUNIXr�rr�r�testStoppingServer�sz InternetTests.testStoppingServerNz1This reactor does not support UNIX domain socketscCsJt�}t�d|jd�}|��t�|�}|��t�|�}|�	|j
�dS)NrJr)r�r�TimerServicer�r@rn�dumpsrB�loadsr>r?)r%�targetZt0r&rGrrr�testPickledTimer�s

zInternetTests.testPickledTimercsbt���t�ddd����j���fdd�}|�_������fdd�����fdd���S)NrJcSsddS)NrJrrrrrrr��r�z/InternetTests.testBrokenTimer.<locals>.<lambda>cs�|���d�dSr(r�)Zwhy)r��	oldFailedrr�_failed�sz.InternetTests.testBrokenTimer.<locals>._failedcs�jSr(r�r�r�rrr��r�cs��tgdd���t�D��S)NcSsg|]}|jj�qSr)�value�	__class__)�.0�orrr�
<listcomp>�szCInternetTests.testBrokenTimer.<locals>.<lambda>.<locals>.<listcomp>)r"�ZeroDivisionErrorZflushLoggedErrorsr�rarrr��s�)r	r�rr�r�r@r�)r%r�r)r�r�r%rGr�testBrokenTimer�szInternetTests.testBrokenTimercCs�d��}|dd�D]"}ttd|�td�s|�|�q|D]�}d��D]�}|dkr^|dkr^qH|dkrp|dkrpqH|�tt||��tt||�j}dd	d
�|}|�tt||�p�|d	ko�|dk�tt||��}|�	t
�|�|�qHq<dS)z�
        L{twisted.application.internet} dynamically defines a set of
        L{service.Service} subclasses that in general have corresponding
        reactor.listenXXX or reactor.connectXXX calls.
        z'TCP UNIX SSL UDP UNIXDatagram MulticastNZIReactorz
Server ClientZ	Multicast�ClientZUDPZlistenZconnect)ZServerr�)rx�getattrrr�removerA�hasattrr�methodr"rr_)r%ZtransZtranZsider��prefixr�rrr�test_everythingThere�s$�z"InternetTests.test_everythingTherecCs(tjD]}|�tt|�d|f�qdS)z�
        L{twisted.application.internet} dynamically defines L{service.Service}
        subclasses. This test ensures that the subclasses exposed by C{__all__}
        are valid attributes of the module.
        z3%s not importable from twisted.application.internetN)r�__all__rAr�)r%�clsrrr�test_importAlls

�zInternetTests.test_importAllcCsFt�}t�}tjd||d�}|��|�|j��dd�d|f�dS)z�
        L{internet._AbstractServer} supports a C{reactor} keyword argument
        that can be used to parametrize the reactor used to listen for
        connections.
        ���rN�)r�objectrr�r@r"�
tcpServers�pop�r%rr�rGrrr�#test_reactorParametrizationInServer"s
z1InternetTests.test_reactorParametrizationInServercCsLt�}t��}tjdd||d�}|��|�|j��dd�dd|f�dS)z�
        L{internet._AbstractClient} supports a C{reactor} keyword arguments
        that can be used to parametrize the reactor used to create new client
        connections.
        r�r�r�N�)	rr
r�rr�r@r"�
tcpClientsr�r�rrr�#test_reactorParametrizationInClient0s�z1InternetTests.test_reactorParametrizationInClientcCsvt�}t��}tjd||d�}|��|�|j��dd�d|f�|�	�|��|�|j��dd�d|f�dS)z�
        Like L{test_reactorParametrizationInServer}, but stop and restart the
        service and check that the given reactor is still used.
        r�r�Nr�)
rr
ZFactoryrr�r@r"r�r�rBr�rrr�0test_reactorParametrizationInServerMultipleStart?sz>InternetTests.test_reactorParametrizationInServerMultipleStartcCs|t�}t��}tjdd||d�}|��|�|j��dd�dd|f�|�	�|��|�|j��dd�dd|f�dS)z�
        Like L{test_reactorParametrizationInClient}, but stop and restart the
        service and check that the given reactor is still used.
        r�r�r�Nr�)
rr
r�rr�r@r"r�r�rBr�rrr�0test_reactorParametrizationInClientMultipleStartOs��z>InternetTests.test_reactorParametrizationInClientMultipleStart)rrrr�r�rPr�r�r�r�r�rZIReactorUNIXrZ_skipMsg�skipr�r�r�r�r�r�r�r�rrrrr�Ls*


r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TimerBasicTestscsZt��}t�d|jd��_�j��|��jd�|��fdd��|��fdd��|S)NrJrcs
�j��Sr(�rGrBr�rarrr�ir�z/TimerBasicTests.testTimerRuns.<locals>.<lambda>cs���jj�Sr()r>rGr?r�rarrr�jr�)	r	r�rr�r�rGr@r�r")r%r�rrar�
testTimerRunsds
zTimerBasicTests.testTimerRunscCs
|j��Sr(r�rarrr�tearDownmszTimerBasicTests.tearDowncs�t��}t����df|dfg��fdd�}t�d|��_�j���fdd�}��fdd	�}�fd
d�}|�|�|�|�|�|�|S)N�bar�foocs���\}}|�|�dSr()r�r�)r��arg)�workrr�triggerusz1TimerBasicTests.testTimerRestart.<locals>.triggerrJcs��|d��j��S)Nr��r"rGrB��resultrarr�
onFirstResultzsz7TimerBasicTests.testTimerRestart.<locals>.onFirstResultcs���jj��j���Sr()r>rGr?r@)r�)�d2r%rr�onFirstStop}s
z5TimerBasicTests.testTimerRestart.<locals>.onFirstStopcs��|d��j��dS)Nr�r�rrarr�onSecondResult�sz8TimerBasicTests.testTimerRestart.<locals>.onSecondResult)r	r�rr�rGr@r�)r%Zd1r�rrrr)rr%r�r�testTimerRestartps



z TimerBasicTests.testTimerRestartcs`g��fdd�}t��}t�d|dd|��_�j��|��jdgd�|��fdd��|S)Ncs$��|�t��|kr |���dSr()r��lenr�)�dataZnumberr�r�rrr��s
z/TimerBasicTests.testTimerLoops.<locals>.triggerg{�G�z�?r�
cs
�j��Sr(r�r�rarrr��r�z0TimerBasicTests.testTimerLoops.<locals>.<lambda>)r	r�rr�rGr@r�r")r%r�r�r)r�r%r�testTimerLoops�s
zTimerBasicTests.testTimerLoopsN)rrrr�r�rr
rrrrr�bs	r�c@seZdZdZdd�ZdS)�FakeReactorz6
    A fake reactor with a hooked install method.
    cOstjj|f|�|�||_dS)zv
        @param install: any callable that will be used as install method.
        @type install: C{callable}
        N)r�Reactorr��install)r%r
r��kwargsrrrr��szFakeReactor.__init__N)rrr�__doc__r�rrrrr�src@szeZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�PluggableReactorTestsz:
    Tests for the reactor discovery/inspection APIs.
    cCs g|_g|_tj|_|jt_dS)aI
        Override the L{reactors.getPlugins} function, normally bound to
        L{twisted.plugin.getPlugins}, in order to control which
        L{IReactorInstaller} plugins are seen as available.

        C{self.pluginResults} can be customized and will be used as the
        result of calls to C{reactors.getPlugins}.
        N)�pluginCalls�
pluginResultsr�
getPlugins�originalFunction�_getPluginsrarrr�setUp�s	zPluggableReactorTests.setUpcCs|jt_dS)z>
        Restore the original L{reactors.getPlugins}.
        N)rrrrarrrr��szPluggableReactorTests.tearDownNcCs|j�||f�t|j�S)zy
        Stand-in for the real getPlugins method which records its arguments
        and returns a fixed result.
        )rr�r+r)r%Z	interface�packagerrrr�sz!PluggableReactorTests._getPluginscCstd}td}d}t�|||�g|_t��}|�|jtjdfg�|D] }|j|krD|�|j	|�qpqD|�
d�dS)zP
        Test that reactor plugins are returned from L{getReactorTypes}
        �fakereactortestz.fakereactor�descriptionNz6Reactor plugin not present in getReactorTypes() result)rrrr�getReactorTypesr"rZIReactorInstaller�	shortNamerZfail)r%r#rrZreactorTypes�rrrr�test_getPluginReactorTypes�s
�
z0PluggableReactorTests.test_getPluginReactorTypescsXg��fdd�}t|dtd�}d|i}|�|�t�ddd�}|��|��dg�dS)zy
        Test that L{reactors.Reactor.install} loads the correct module and
        calls its install attribute.
        cs��d�dSr��r�r��	installedrrr
�sz?PluggableReactorTests.test_reactorInstallation.<locals>.installr�	describedZfakereactorTN)rrZreplaceSysModulesrrr
r")r%r
�fakeReactor�modulesZ	installerrrr�test_reactorInstallation�s�
z.PluggableReactorTests.test_reactorInstallationcsJg��fdd�}d}t}d}t||||�g|_t�|�|��dg�dS)zu
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor.
        cs��d�dSr�rrrrrr
�sz:PluggableReactorTests.test_installReactor.<locals>.installrrTN�rrrr�installReactorr"�r%r
r#rrrrr�test_installReactor�s
z)PluggableReactorTests.test_installReactorcsLt����fdd�}d}t}d}t||||�g�_t�|�}��|��dS)zt
        Test that the L{reactors.installReactor} function correctly returns
        the installed reactor.
        csddlm}��|d��dS)Nr�rr)ZtwistedrZpatchr)�rr%rrr
szHPluggableReactorTests.test_installReactorReturnsReactor.<locals>.installrrN)r�rrrrr&rl)r%r
r#rrr rr*r�!test_installReactorReturnsReactors
z7PluggableReactorTests.test_installReactorReturnsReactorcsbg��fdd�}d}t}d}t||||�}tdd�d||�}||g|_t�|�|��dg�d	S)
z�
        Test that the L{reactors.installReactor} function correctly installs
        the specified reactor when there are multiple reactor plugins.
        cs��d�dSr�rrrrrr
szIPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.installrrcSsdSr(rrrrrr�r�zJPluggableReactorTests.test_installReactorMultiplePlugins.<locals>.<lambda>ZotherreactorTNr%)r%r
r#rrr"ZotherReactorrrr�"test_installReactorMultiplePluginss�

z8PluggableReactorTests.test_installReactorMultiplePluginscCsg|_|�tjtjd�dS)z�
        Test that L{reactors.installReactor} raises L{reactors.NoSuchReactor}
        when asked to install a reactor which it cannot find.
        ZsomereactorN)rr7rZ
NoSuchReactorr&rarrr�test_installNonExistentReactor%s�z4PluggableReactorTests.test_installNonExistentReactorcCs:dd�}d}t}d}t||||�g|_|�ttj|�dS)z�
        Test that L{reactors.installReactor} raises an exception when asked to
        install a reactor which doesn't work in this environment.
        cSstd��dS)N�Missing foo bar��ImportErrorrrrrr
5szFPluggableReactorTests.test_installNotAvailableReactor.<locals>.installrrN)rrrr7r0rr&r'rrr�test_installNotAvailableReactor0sz5PluggableReactorTests.test_installNotAvailableReactorcs�g�d�d�G��fdd�dtjtj�}��fdd�}t|dtd�g|_|�}|�d	dd
g�|��d��|���	��d�|�|d
d�dS)zx
        Test that the reactor selected is installed as soon as possible, ie
        when the option is parsed.
        zreactor installedzsubcommands loadedcs"eZdZ��fdd�Zee�ZdS)zQPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptionscs ����dd�fdd�dfgS)N�
subcommandcs�Sr(rrrarrr�Jr�zoPluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommands.<locals>.<lambda>ztest subcommandrra��SUBCOMMAND_EVENT�executedrar�subCommandsHs
z]PluggableReactorTests.test_reactorSelectionMixin.<locals>.ReactorSelectionOptions.subCommandsN)rrrr6�propertyrr3rr�ReactorSelectionOptionsGsr8cs����dSr(rr)�
INSTALL_EVENTr5rrr
MszAPluggableReactorTests.test_reactorSelectionMixin.<locals>.installrr!�	--reactorr2rrJrN)
r�Optionsr�ReactorSelectionMixinrrr�parseOptionsr"�count)r%r8r
�optionsr)r9r4r5r�test_reactorSelectionMixin>s�z0PluggableReactorTests.test_reactorSelectionMixincCsjGdd�dtjtj�}g|_|�}t�|_|�tj|j	dddg�}|�
d|jd�|�
d|jd�dS)	z�
        Test that the usage mixin exits when trying to use a non existent
        reactor (the name not matching to any reactor), giving an error
        message.
        c@seZdZdS)z\PluggableReactorTests.test_reactorSelectionMixinNonExistent.<locals>.ReactorSelectionOptionsN�rrrrrrrr8`sr8r:rr2r�
help-reactorsN)rr;rr<rr�
messageOutputr7�
UsageErrorr=�assertInr�)r%r8r?�errr�%test_reactorSelectionMixinNonExistentZs�z;PluggableReactorTests.test_reactorSelectionMixinNonExistentcs�Gdd�dtjtj�}d��fdd�}d}t}d}t||||�g|_|�}t�|_|�	tj
|jddd	g�}|��|j
d
�|�d|j
d
�dS)
z�
        Test that the usage mixin exits when trying to use a reactor not
        available (the reactor raises an error at installation), giving an
        error message.
        c@seZdZdS)z]PluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.ReactorSelectionOptionsNrArrrrr8rsr8r.cst���dSr(r/r��messagerrr
uszMPluggableReactorTests.test_reactorSelectionMixinNotAvailable.<locals>.installrrr:r2rrBN)rr;rr<rrrrrCr7rDr=rEr�)r%r8r
r#rrr?rFrrHr�&test_reactorSelectionMixinNotAvailablels�z<PluggableReactorTests.test_reactorSelectionMixinNotAvailable)N)rrrrrr�rrr$r(r+r,r-r1r@rGrJrrrrr�s
	rc@speZdZdZdd�Zdd�Zer&de_dd�Zes8d	e_d
d�Z	e
dkrNd
e	_dd�Ze
dkrdd
e_dd�ZdS)�HelpReactorsTestsz6
    --help-reactors lists the available reactors
    cCs6t��|_t�|j_|�t|jj�|jj��|_	dS)z3
        Get the text from --help-reactors
        N)
rr<r?rrCr7�
SystemExit�opt_help_reactors�getvaluerIrarrrr�s

zHelpReactorsTests.setUpcCs,|�tjj|j�|�dtjj|j�dS)zX
        --help-reactors should NOT display the asyncio reactor on Python < 3.4
        �!N)rEr
�asynciorrIrrarrr�test_lacksAsyncIO�sz#HelpReactorsTests.test_lacksAsyncIOz$Not applicable, asyncio is availablecCs,|�tjj|j�|�dtjj|j�dS)zU
        --help-reactors should display the asyncio reactor on Python >= 3.4
        rON)rEr
rPrrI�assertNotInrrarrr�test_hasAsyncIO�s

�z!HelpReactorsTests.test_hasAsyncIOzasyncio library not availablecCs,|�tjj|j�|�dtjj|j�dS)zL
        --help-reactors should display the iocp reactor on Windows
        rON)rEr
�iocprrIrRrrarrr�test_iocpWin32�sz HelpReactorsTests.test_iocpWin32Zwin32zTest only applicable on WindowscCs,|�tjj|j�|�dtjj|j�dS)zP
        --help-reactors should NOT display the iocp reactor on Windows
        rON)rEr
rTrrIrrarrr�test_iocpNotWin32�sz#HelpReactorsTests.test_iocpNotWin32cCsFdd�}t��}||_t�|_|�t|j�|j��}|�	d|�dS)z>
        --help-reactors with only supported reactors
        csstjVdSr()r
�defaultrrrrr�szEHelpReactorsTests.test_onlySupportedReactors.<locals>.getReactorTypeszreactors not availableN)
rr<Z_getReactorTypesrrCr7rLrMrNrR)r%rr?rIrrr�test_onlySupportedReactors�s
z,HelpReactorsTests.test_onlySupportedReactorsN)
rrrrrrQrPr�rSrUrrVrXrrrrrK�s
rK)?rZ
__future__rrrQ�osrnrPr0Ztwisted.applicationrrrrZtwisted.internetrr	r
rZtwisted.persistedrZtwisted.pluginsr
Ztwisted.protocolsrrZtwisted.pythonrZtwisted.python.compatrZtwisted.python.runtimerZ#twisted.python.test.modules_helpersrZtwisted.test.proto_helpersrZ
twisted.trialrrZTestCaserr�rSZcuruid�getgidZcurgidrTr^rfrrr�ZLineReceiverr�r�r�r�r�r�r�rrrrKrrrr�<module>sT
x
.
5a