ϪfW&dZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZmZmZdd lmZGd d eZeeGd d ZGddeZGddeZy)z" Tests for L{twisted.test.iosim}. ) annotations)Literal) implementer) IPushProducer)Protocol)Clock) FakeTransportconnectconnectedServerAndClient)TestCasec(eZdZdZddZddZddZy)FakeTransportTestsz% Tests for L{FakeTransport}. c ttd}ttd}|j|jt|j|jt|j |j|jy)ze Each L{FakeTransport} receives a serial number that uniquely identifies it. TFN)r objectassertIsInstanceserialintassertNotEqual)selfabs 9/usr/lib/python3/dist-packages/twisted/test/test_iosim.pytest_connectionSerialz(FakeTransportTests.test_connectionSerials` &(D ) &(E * ahh, ahh, AHHahh/cttd}|jd|jgd|j dj |j dy)zl L{FakeTransport.writeSequence} will write a sequence of L{bytes} to the transport. Fa)bcdrsabcdN)r rwrite writeSequence assertEqualjoinstreamrrs rtest_writeSequencez%FakeTransportTests.test_writeSequence$sG &(E *   *+ !((+W5rcttd}|jd|j|jd|j dj |j dy)z L{FakeTransport.write} will accept writes after transport was closed, but the data will be silently discarded. FsbeforesafterrN)r rr loseConnectionr"r#r$r%s rtest_writeAfterClosez'FakeTransportTests.test_writeAfterClose0sS &(E *     !((+Y7rNreturnNone)__name__ __module__ __qualname____doc__rr&r)rrrrs 0 6 8rrc,eZdZdZdZddZddZddZy)StrictPushProducerz An L{IPushProducer} implementation which produces nothing but enforces preconditions on its state transition methods. runningcF|jdk(r tdd|_y)Nstoppedz)Cannot stop already-stopped IPushProducer_state ValueErrorrs r stopProducingz StrictPushProducer.stopProducingFs! ;;) #HI I rcb|jdk7rtd|jdd|_y)Nr4z Cannot pause  IPushProducerpausedr7r:s rpauseProducingz!StrictPushProducer.pauseProducingKs- ;;) #}T[[MHI I rcb|jdk7rtd|jdd|_y)Nr>zCannot resume r=r4r7r:s rresumeProducingz"StrictPushProducer.resumeProducingPs- ;;( "~dkk].IJ J rNr*)r-r.r/r0r8r;r?rAr1rrr3r3=s F   rr3ceZdZdZddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zdd ZddZddZddZddZddZddZddZy)StrictPushProducerTestsz* Tests for L{StrictPushProducer}. ctS)zp @return: A new L{StrictPushProducer} which has not been through any state changes. )r3r:s r_initialz StrictPushProducerTests._initial[s "##rc:t}|j|S)z@ @return: A new, stopped L{StrictPushProducer}. )r3r;rproducers r_stoppedz StrictPushProducerTests._stoppedbs&' rc:t}|j|S)z? @return: A new, paused L{StrictPushProducer}. )r3r?rGs r_pausedzStrictPushProducerTests._pausedjs&'!rcZt}|j|j|S)zY @return: A new L{StrictPushProducer} which has been paused and resumed. )r3r?rArGs r_resumedz StrictPushProducerTests._resumedrs)&'!  "rc<|j|jdy)z Assert that the given producer is in the stopped state. @param producer: The producer to verify. @type producer: L{StrictPushProducer} r6Nr"r8rGs r assertStoppedz%StrictPushProducerTests.assertStopped{ )4rc<|j|jdy)z Assert that the given producer is in the paused state. @param producer: The producer to verify. @type producer: L{StrictPushProducer} r>NrOrGs r assertPausedz$StrictPushProducerTests.assertPauseds (3rc<|j|jdy)z Assert that the given producer is in the running state. @param producer: The producer to verify. @type producer: L{StrictPushProducer} r4NrOrGs r assertRunningz%StrictPushProducerTests.assertRunningrQrc`|jt|jjy)zz L{StrictPushProducer.stopProducing} raises L{ValueError} if called when the producer is stopped. N) assertRaisesr9rIr;r:s rtest_stopThenStopz)StrictPushProducerTests.test_stopThenStops *dmmo&C&CDrc`|jt|jjy)z{ L{StrictPushProducer.pauseProducing} raises L{ValueError} if called when the producer is stopped. N)rWr9rIr?r:s rtest_stopThenPausez*StrictPushProducerTests.test_stopThenPauses *dmmo&D&DErc`|jt|jjy)z| L{StrictPushProducer.resumeProducing} raises L{ValueError} if called when the producer is stopped. N)rWr9rIrAr:s rtest_stopThenResumez+StrictPushProducerTests.test_stopThenResumes *dmmo&E&EFrcf|j}|j|j|y)zn L{StrictPushProducer} is stopped if C{stopProducing} is called on a paused producer. N)rKr;rPrGs rtest_pauseThenStopz*StrictPushProducerTests.test_pauseThenStops) <<>  8$rcd|j}|jt|jy)zs L{StrictPushProducer.pauseProducing} raises L{ValueError} if called on a paused producer. N)rKrWr9r?rGs rtest_pauseThenPausez+StrictPushProducerTests.test_pauseThenPauses% <<> *h&=&=>rcf|j}|j|j|y)zp L{StrictPushProducer} is resumed if C{resumeProducing} is called on a paused producer. N)rKrArUrGs rtest_pauseThenResumez,StrictPushProducerTests.test_pauseThenResumes) <<>  " 8$rcf|j}|j|j|y)zo L{StrictPushProducer} is stopped if C{stopProducing} is called on a resumed producer. N)rMr;rPrGs rtest_resumeThenStopz+StrictPushProducerTests.test_resumeThenStop) ==?  8$rcf|j}|j|j|y)zo L{StrictPushProducer} is paused if C{pauseProducing} is called on a resumed producer. N)rMr?rSrGs rtest_resumeThenPausez,StrictPushProducerTests.test_resumeThenPause) ==?! (#rcd|j}|jt|jy)zu L{StrictPushProducer.resumeProducing} raises L{ValueError} if called on a resumed producer. N)rMrWr9rArGs rtest_resumeThenResumez-StrictPushProducerTests.test_resumeThenResume% ==? *h&>&>?rcf|j}|j|j|y)zn L{StrictPushProducer} is stopped if C{stopProducing} is called in the initial state. N)rEr;rPrGs r test_stopz!StrictPushProducerTests.test_stoprercf|j}|j|j|y)zn L{StrictPushProducer} is paused if C{pauseProducing} is called in the initial state. N)rEr?rSrGs r test_pausez"StrictPushProducerTests.test_pauserhrcd|j}|jt|jy)zz L{StrictPushProducer} raises L{ValueError} if C{resumeProducing} is called in the initial state. N)rErWr9rArGs r test_resumez#StrictPushProducerTests.test_resumerkrN)r+r3)rHr3r+r,r*)r-r.r/r0rErIrKrMrPrSrUrXrZr\r^r`rbrdrgrjrmrorqr1rrrCrCVsk$545EFG%?%%$@%$@rrCc0eZdZdZddZddZddZddZy) IOPumpTestsz Tests for L{IOPump}. c"t}t|d}t}t|d}t||||d}t}||d|}|j |d|j |j d|jy) 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)isServerF)greet)serverclient) streamingr4N)rr r r3registerProducerpumpr"r8) rmode serverProtoserverTransport clientProtoclientTransportr{rHvictims r_testStreamingProducerz"IOPumpTests._testStreamingProducersj ' dCj ' eD      &'%%   D9  HOO4rc(|jdy)z L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer} (stream producer) registered with the server transport. rwr|Nrr:s rtest_serverStreamingProducerz(IOPumpTests.test_serverStreamingProducer" ###2rc(|jdy)z L{IOPump.pump} does not call C{resumeProducing} on a L{IPushProducer} (stream producer) registered with the client transport. rxrNrr:s rtest_clientStreamingProducerz(IOPumpTests.test_clientStreamingProducer)rrcgt}ttt|\}}}|jdfd|j |j |j y)zE L{IOPump.pump} advances time in the given L{Clock}. )clockrc&jdS)NT)append) time_passedsrz/IOPumpTests.test_timeAdvances..7s;#5#5d#;rN)rr r callLater assertFalser{ assertTrue)rr_r{rs @rtest_timeAdvanceszIOPumpTests.test_timeAdvances0sW -hN 1d ;< %   $rN)r|zLiteral['server', 'client']r+r,r*)r-r.r/r0rrrrr1rrrsrss!5F33 %rrsN)r0 __future__rtypingrzope.interfacertwisted.internet.interfacesrtwisted.internet.protocolrtwisted.internet.taskrtwisted.test.iosimr r r twisted.trial.unittestr rr3rCrsr1rrrsq#&5.'OO+&8&8R ]   0a@ha@H@%(@%r