Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/test/__pycache__/test_iosim.cpython-37.pyc

B

;��]d#�@s�dZddlmZmZddlmZddlmZddlm	Z	ddl
mZmZddl
mZGdd	�d	e�Zee�Gd
d�de��ZGdd
�d
e�ZGdd�de�ZdS)z"
Tests for L{twisted.test.iosim}.
�)�absolute_import�division)�implementer)�
IPushProducer)�Protocol)�
FakeTransport�connect)�TestCasec@s(eZdZdZdd�Zdd�Zdd�ZdS)	�FakeTransportTestsz%
    Tests for L{FakeTransport}.
    cCsHtt�d�}tt�d�}|�|jt�|�|jt�|�|j|j�dS)ze
        Each L{FakeTransport} receives a serial number that uniquely identifies
        it.
        TFN)r�objectZassertIsInstance�serial�intZassertNotEqual)�self�a�b�r�J/opt/alt/python37/lib64/python3.7/site-packages/twisted/test/test_iosim.py�test_connectionSerials
z(FakeTransportTests.test_connectionSerialcCs>tt�d�}|�d�|�dddg�|�d�|j�d�dS)	zl
        L{FakeTransport.writeSequence} will write a sequence of L{bytes} to the
        transport.
        F�a�b�c�d�sabcdN)rr�writeZ
writeSequence�assertEqual�join�stream)rrrrr�test_writeSequence$s
z%FakeTransportTests.test_writeSequencecCs@tt�d�}|�d�|��|�d�|�d�|j�d�dS)z�
        L{FakeTransport.write} will accept writes after transport was closed,
        but the data will be silently discarded.
        FsbeforesafterrN)rrrZloseConnectionrrr)rrrrr�test_writeAfterClose1s


z'FakeTransportTests.test_writeAfterCloseN)�__name__�
__module__�__qualname__�__doc__rrrrrrrr
s
r
c@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�StrictPushProducerz�
    An L{IPushProducer} implementation which produces nothing but enforces
    preconditions on its state transition methods.
    �runningcCs|jdkrtd��d|_dS)N�stoppedz)Cannot stop already-stopped IPushProducer)�_state�
ValueError)rrrr�
stopProducingGs
z StrictPushProducer.stopProducingcCs$|jdkrtd�|j���d|_dS)Nr$zCannot pause {} IPushProducer�paused)r&r'�format)rrrr�pauseProducingMs
z!StrictPushProducer.pauseProducingcCs$|jdkrtd�|j���d|_dS)Nr)zCannot resume {} IPushProducerr$)r&r'r*)rrrr�resumeProducingUs
z"StrictPushProducer.resumeProducingN)rr r!r"r&r(r+r,rrrrr#?s
r#c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�StrictPushProducerTestsz*
    Tests for L{StrictPushProducer}.
    cCst�S)zp
        @return: A new L{StrictPushProducer} which has not been through any state
            changes.
        )r#)rrrr�_initialbsz StrictPushProducerTests._initialcCst�}|��|S)z@
        @return: A new, stopped L{StrictPushProducer}.
        )r#r()r�producerrrr�_stoppedjsz StrictPushProducerTests._stoppedcCst�}|��|S)z?
        @return: A new, paused L{StrictPushProducer}.
        )r#r+)rr/rrr�_pausedsszStrictPushProducerTests._pausedcCst�}|��|��|S)zY
        @return: A new L{StrictPushProducer} which has been paused and resumed.
        )r#r+r,)rr/rrr�_resumed|sz StrictPushProducerTests._resumedcCs|�|jd�dS)z�
        Assert that the given producer is in the stopped state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r%N)rr&)rr/rrr�
assertStopped�sz%StrictPushProducerTests.assertStoppedcCs|�|jd�dS)z�
        Assert that the given producer is in the paused state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r)N)rr&)rr/rrr�assertPaused�sz$StrictPushProducerTests.assertPausedcCs|�|jd�dS)z�
        Assert that the given producer is in the running state.

        @param producer: The producer to verify.
        @type producer: L{StrictPushProducer}
        r$N)rr&)rr/rrr�
assertRunning�sz%StrictPushProducerTests.assertRunningcCs|�t|��j�dS)zz
        L{StrictPushProducer.stopProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)�assertRaisesr'r0r()rrrr�test_stopThenStop�sz)StrictPushProducerTests.test_stopThenStopcCs|�t|��j�dS)z{
        L{StrictPushProducer.pauseProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)r6r'r0r+)rrrr�test_stopThenPause�sz*StrictPushProducerTests.test_stopThenPausecCs|�t|��j�dS)z|
        L{StrictPushProducer.resumeProducing} raises L{ValueError} if called when
        the producer is stopped.
        N)r6r'r0r,)rrrr�test_stopThenResume�sz+StrictPushProducerTests.test_stopThenResumecCs|��}|��|�|�dS)zn
        L{StrictPushProducer} is stopped if C{stopProducing} is called on a paused
        producer.
        N)r1r(r3)rr/rrr�test_pauseThenStop�sz*StrictPushProducerTests.test_pauseThenStopcCs|��}|�t|j�dS)zs
        L{StrictPushProducer.pauseProducing} raises L{ValueError} if called on a
        paused producer.
        N)r1r6r'r+)rr/rrr�test_pauseThenPause�sz+StrictPushProducerTests.test_pauseThenPausecCs|��}|��|�|�dS)zp
        L{StrictPushProducer} is resumed if C{resumeProducing} is called on a
        paused producer.
        N)r1r,r5)rr/rrr�test_pauseThenResume�sz,StrictPushProducerTests.test_pauseThenResumecCs|��}|��|�|�dS)zo
        L{StrictPushProducer} is stopped if C{stopProducing} is called on a
        resumed producer.
        N)r2r(r3)rr/rrr�test_resumeThenStop�sz+StrictPushProducerTests.test_resumeThenStopcCs|��}|��|�|�dS)zo
        L{StrictPushProducer} is paused if C{pauseProducing} is called on a
        resumed producer.
        N)r2r+r4)rr/rrr�test_resumeThenPause�sz,StrictPushProducerTests.test_resumeThenPausecCs|��}|�t|j�dS)zu
        L{StrictPushProducer.resumeProducing} raises L{ValueError} if called on a
        resumed producer.
        N)r2r6r'r,)rr/rrr�test_resumeThenResume�sz-StrictPushProducerTests.test_resumeThenResumecCs|��}|��|�|�dS)zn
        L{StrictPushProducer} is stopped if C{stopProducing} is called in the
        initial state.
        N)r.r(r3)rr/rrr�	test_stop�sz!StrictPushProducerTests.test_stopcCs|��}|��|�|�dS)zn
        L{StrictPushProducer} is paused if C{pauseProducing} is called in the
        initial state.
        N)r.r+r4)rr/rrr�
test_pausesz"StrictPushProducerTests.test_pausecCs|��}|�t|j�dS)zz
        L{StrictPushProducer} raises L{ValueError} if C{resumeProducing} is called
        in the initial state.
        N)r.r6r'r,)rr/rrr�test_resume
sz#StrictPushProducerTests.test_resumeN)rr r!r"r.r0r1r2r3r4r5r7r8r9r:r;r<r=r>r?r@rArBrrrrr-^s(		




	


	

r-c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�IOPumpTestsz
    Tests for L{IOPump}.
    c	Csrt�}t|dd�}t�}t|dd�}t||||dd�}t�}||d�|}|j|dd�|��|�d|j�dS)	a�
        Connect a couple protocol/transport pairs to an L{IOPump} and then pump
        it.  Verify that a streaming producer registered with one of the
        transports does not receive invalid L{IPushProducer} method calls and
        ends in the right state.

        @param mode: C{u"server"} to test a producer registered with the
            server transport.  C{u"client"} to test a producer registered with
            the client transport.
        T)ZisServerF)Zgreet)�server�client)Z	streamingr$N)rrrr#ZregisterProducer�pumprr&)	r�modeZserverProtoZserverTransportZclientProtoZclientTransportrFr/Zvictimrrr�_testStreamingProducersz"IOPumpTests._testStreamingProducercCs|jdd�dS)z�
        L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
        (stream producer) registered with the server transport.
        rD)rGN)rH)rrrr�test_serverStreamingProducer:sz(IOPumpTests.test_serverStreamingProducercCs|jdd�dS)z�
        L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer}
        (stream producer) registered with the client transport.
        rE)rGN)rH)rrrr�test_clientStreamingProducerBsz(IOPumpTests.test_clientStreamingProducerN)rr r!r"rHrIrJrrrrrCs"rCN)r"�
__future__rrZzope.interfacerZtwisted.internet.interfacesrZtwisted.internet.protocolrZtwisted.test.iosimrrZtwisted.trial.unittestr	r
rr#r-rCrrrr�<module>s,7