Ϫf0zdddZddlmZddlmZGddZGdd ZGd d eZGd d ejZ GddZ GddZ Gdde ejZ Gdde ejZ Gdde ejZGdde ejZGddejZGddejZGddZGd d!eejZGd"d#eejZGd$d%ejZGd&d'ejZy())z$Revision: 1.5 $ )pcp)unittestc"eZdZdZdZdZdZy)DummyTransportz A dumb transport to wrap around.cg|_yN)_writesselfs 7/usr/lib/python3/dist-packages/twisted/test/test_pcp.py__init__zDummyTransport.__init__%s  c:|jj|yr )r appendr datas rwritezDummyTransport.write(s D!rc8dj|jS)N)joinr r s rgetvaluezDummyTransport.getvalue+swwt||$$rN)__name__ __module__ __qualname____doc__rrrrrrr"s*"%rrc0eZdZdZdZdZdZdZdZdZ y) DummyProducerFc||_yr )consumer)r r"s rrzDummyProducer.__init__4s   rc d|_d|_y)NTF)resumedpausedr s rresumeProducingzDummyProducer.resumeProducing7s  rcd|_yNT)r%r s rpauseProducingzDummyProducer.pauseProducing;s  rcd|_yr()stoppedr s r stopProducingzDummyProducer.stopProducing>s  rN) rrrr$r+r%rr&r)r,rrrr r /s%GG F!rr c*eZdZdZdZdZdZdZdZy) DummyConsumerNFTc||f|_yr )producer)r r0 streamings rregisterProducerzDummyConsumer.registerProducerGs!9- rcd|_yr() unregisteredr s runregisterProducerz DummyConsumer.unregisterProducerJs  rcd|_yr()finishedr s rfinishzDummyConsumer.finishMs  r) rrrr0r7r4r2r5r8rrrr.r.Bs HHL.!rr.c0eZdZejZdZdZy)TransportInterfaceTestscbt|_|j|j|_yr )r. underlying proxyClass transportr s rsetUpzTransportInterfaceTests.setUpTs'/9rc:|jjdyNz some bytes)r>rr s r testWritez!TransportInterfaceTests.testWriteXs \*rN)rrrrBasicProducerConsumerProxyr=r?rBrrrr:r:Qs//J:+rr:c(eZdZdZdZdZdZdZy)ConsumerInterfaceTestzTest ProducerConsumerProxy as a Consumer. Normally we have ProducingServer -> ConsumingTransport. If I am to go between (Server -> Shaper -> Transport), I have to play the role of Consumer convincingly for the ProducingServer. ct|_|j|j|_t |j|_yr )r.r<r=r"r r0r s rr?zConsumerInterfaceTest.setUpes/'/8 %dmm4 rc|jj|jd|j|jjyr()r"r2r0 assertFalser$r s rtestRegisterPushz&ConsumerInterfaceTest.testRegisterPushjs2 &&t}}d; ../rc$|jj|jd|jjd|j_|jj |j |jjyNF)r"r2r0r5r$r&rHr s rtestUnregisterz$ConsumerInterfaceTest.testUnregistervs` &&t}}e< ((* !&  %%' ../rc$|jj|jd|jjd|j_|jj |j |jjyrK)r"r2r0r8r$r&rHr s r testFinishz ConsumerInterfaceTest.testFinishs^ &&t}}e<  %  %%' ../rN)rrrrr?rIrLrNrrrrErE\s5 0 00rrEc:eZdZdZdZdZdZdZdZdZ dZ y ) ProducerInterfaceTestzTest ProducerConsumerProxy as a Producer. Normally we have ProducingServer -> ConsumingTransport. If I am to go between (Server -> Shaper -> Transport), I have to play the role of Producer convincingly for the ConsumingTransport. cbt|_|j|j|_yr )r.r"r=r0r s rr?zProducerInterfaceTest.setUps%  6 rcj|j|jjd|jy)Nr) assertEqualr"r0r s rtestRegistersProducerz+ProducerInterfaceTest.testRegistersProducers% //2DMMBrc|jj|jjd|j|jj dy)N yakkity yakz*Paused producer should not have sent data.)r0r)rrHr"rr s r testPausezProducerInterfaceTest.testPausesE $$& M*  MM " " $&R rc|jj|jj|jjd|j |j j dy)NrV)r0r)r&rrSr"rr s r testResumez ProducerInterfaceTest.testResumesQ $$& %%' M* //1=Arc|jj|jj|jt |j j ddy)Nrz Resume triggered an empty write.)r0r)r&rSlenr"r r s rtestResumeNoEmptyWritez,ProducerInterfaceTest.testResumeNoEmptyWritesG $$& %%'   %% &+M rc|jj|jjd|jj|j |j j dy)Nz buffer this)r0r)rr&rSr"rr s rtestResumeBufferz&ProducerInterfaceTest.testResumeBuffersQ $$& M* %%' //1=Arc|jj|jjd|j|jj dy)NrVz+Stopped producer should not have sent data.)r0r,rrHr"rr s rtestStopzProducerInterfaceTest.testStopsE ##% M*  MM " " $&S rN) rrrrr?rTrWrYr\r^r`rrrrPrPs-7C B  B  rrPc$eZdZejZy)PCP_ConsumerInterfaceTestsNrrrrrCr=rrrrbrb //Jrrbc$eZdZejZy)PCPII_ConsumerInterfaceTestsNrrrrProducerConsumerProxyr=rrrrfrf **Jrrfc$eZdZejZy)PCP_ProducerInterfaceTestsNrcrrrrkrkrdrrkc$eZdZejZy)PCPII_ProducerInterfaceTestsNrgrrrrmrmrirrmc4eZdZdZej ZdZdZy)ProducerProxyTestszAProducer methods on me should be relayed to the Producer I proxy.c|jd|_t|j|_|jj |jdyr()r=proxyr parentProducerr2r s rr?zProducerProxyTests.setUps=__T* +DJJ7 ##D$7$7>rc|jj|j|jjyr )rqr, assertTruerrr+r s rr`zProducerProxyTests.testStops*   " ++334rN) rrrrrrCr=r?r`rrrrorosK//J? 5rroc@eZdZdZej ZdZdZdZ dZ y)ConsumerProxyTestszAConsumer methods on me should be relayed to the Consumer I proxy.cbt|_|j|j|_yr )r.r<r=r"r s rr?zConsumerProxyTests.setUps'/8 rc|jjd|j|jj dyrA)r"rrSr<rr s rrBzConsumerProxyTests.testWrites1 L) 113\Brc|jj|j|jjyr )r"r8rtr<r7r s rrNzConsumerProxyTests.testFinishs(  001rc|jj|j|jjyr )r"r5rtr<r4r s rrLz!ConsumerProxyTests.testUnregisters( ((* 445rN) rrrrrrCr=r?rBrNrLrrrrvrvs%K//J9C 26rrvc*eZdZdZdZdZdZdZy)PullProducerTestct|_|j|j|_t |j|_|jj |j dyr()r.r<r=rqr rrr2r s rr?zPullProducerTest.setUpsJ'/__T__5 +DJJ7 ##D$7$7>rc|jjd|j|jj dy)Nhelloz+Pulling Consumer got data before it pulled.)rqrrHr<rr s rtestHoldWriteszPullProducerTest.testHoldWritess5 !  OO $ $ &(U rc|jjd|jj|j|jj dy)Nr)rqrr&rSr<rr s rtestPullzPullProducerTest.testPullsA ! ""$ 113W=rcd|jjd|jjd|jjt|jj }|j |dd|fz|j |jjdy)Nzhello sunshinez(Pull resulted in %d writes instead of 1.zhello sunshine)rqrr&r[r<r rSr)r nwritess rtestMergeWritesz PullProducerTest.testMergeWritess " $ ""$doo--.  QE R  1135EFrc|jj|jjd|j|jj dy)Nr)rqr&rrSr<rr s r testLateWritezPullProducerTest.testLateWritesA ""$   113V G=rr|c6eZdZGddejZy)PCP_PullProducerTestsceZdZdZy) PCP_PullProducerTests.proxyClassFNrrr iAmStreamingrrrr=r rr=NrcrrrrrsS33rrc6eZdZGddejZy)PCPII_PullProducerTestsceZdZdZy)"PCPII_PullProducerTests.proxyClassFNrrrrr=rrrr=NrgrrrrrsS..rrcLeZdZdZej ZdZdZdZ dZ dZ dZ y) BufferedConsumerTestsz=As a consumer, ask the producer to pause after too much data.ct|_|j|j|_d|j_t |j|_|jj|j dy)NdTr.r<r=rq bufferSizer rrr2r s rr?zBufferedConsumerTests.setUp)sV'/__T__5 # +DJJ7 ##D$7$7>rc|jj|jd|j|jjyrK)rqr2rrrtr$r s rtestRegisterPullz&BufferedConsumerTests.testRegisterPull1s4 ##D$7$7? ++334rc|jj|j|jjyr )rqr)rHrrr%r s rtestPauseInterceptz(BufferedConsumerTests.testPauseIntercept6s, !!# ,,334rc|jj|jj|j|jj yr )rqr)r&rHrrr$r s rtestResumeInterceptz)BufferedConsumerTests.testResumeIntercept:s> !!# ""$ ,,445rc|jj|j|jjd|jj d|j|jjd|jj d|j |jjy)zMake sure I say "when." zdon't pause yet3xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxN)rqr)rHrrr%rrtr s rtestTriggerPausez&BufferedConsumerTests.testTriggerPauseBs !!# ,,335FG " ,,335FG " ++223rc|jj|jjd|j|jj d|jj |j|jj d|j|jjy)z3Make sure I resumeProducing when my buffer empties.fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzshould be pausedzProducer should have resumed.N) rqr)rrtrrr%r&rHproducerPausedr s rtestTriggerResumez'BufferedConsumerTests.testTriggerResumeMs !!# # ++224FG ""$ ,,335TU 223rN) rrrrrrhr=r?rrrrrrrrrr$s.G**J?5 56 4 4rrcHeZdZGddejZdZdZdZy)BufferedPullTestsceZdZdZdZy)BufferedPullTests.proxyClassFcrtjj||ddtt |dS)Nr)rrh_writeSomeDataminr[rs rrz+BufferedPullTests.proxyClass._writeSomeData]s/  % % 4 4T4: Fs4y#& &rN)rrrrrrrrr=rZs   'rr=ct|_|j|j|_d|j_t |j|_|jj|j dy)NrFrr s rr?zBufferedPullTests.setUpasV'/__T__5 # +DJJ7 ##D$7$7?rcd|j_|jj|j |jjyrK)rrr$rqr&rtr s rtestResumePullz BufferedPullTests.testResumePullis:',# ""$ ++334rc|jj|jjd|j|jj d|j|jj dgy)Nidatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumddatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatumdatum)rqr&rrSr<r_bufferr s rtestLateWriteBufferingz(BufferedPullTests.testLateWriteBufferingps] ""$ & 113\B ++gY7rN) rrrrrhr=r?rrrrrrrYs$'S..'@58rrN) __version__twisted.protocolsr twisted.trialrrr r.TestCaser:rErPrbrfrkrmrorvr|rrrrrrrrs3 !B' !"2 % %& N +h//++0+0\/ / d0!68I8I0+#8(:K:K+0!68I8I0+#8(:K:K+ 5** 56**6."="=J,h.?.? .0A0A24H--24j8))8r