ϪfdZddlmZddlmZddlmZddlmZddl m Z  ddl m Z Gd d Zee d Gd d e Zy#e $rdZ Y,wxYw)z- Tests for L{twisted.internet.epollreactor}. )skipIfConnectionDone)_ContinuousPolling)Clock)TestCase) epollreactorNc.eZdZdZdZdZdZdZdZy) DescriptorzF Records reads and writes, as if it were a C{FileDescriptor}. cg|_yN)eventsselfs I/usr/lib/python3/dist-packages/twisted/internet/test/test_epollreactor.py__init__zDescriptor.__init__s  cy)Nrs rfilenozDescriptor.filenosrc:|jjdy)Nreadrappendrs rdoReadzDescriptor.doRead s 6"rc:|jjdy)Nwriterrs rdoWritezDescriptor.doWrite#s 7#rcd|jt|jjdy)Nlost)traprrr)rreasons rconnectionLostzDescriptor.connectionLost&s  N# 6"rN) __name__ __module__ __qualname____doc__rrrrr$rrrr r s #$#rr z(epoll not supported in this environment.c^eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZy)ContinuousPollingTestsza L{_ContinuousPolling} can be used to read and write from C{FileDescriptor} objects. ctt}|j|jt }|j |j ||j||j|j|j|jj|j|jj|j|j|j |y)zi Adding a reader when there was previously no reader starts up a C{LoopingCall}. N)rr assertIsNone_loopobject assertFalse isReading addReaderassertIsNotNone assertTruerunningassertIsclock_reactorrpollerreaders rtest_addReaderz%ContinuousPollingTests.test_addReader2 $EG, &,,' ))&12  V\\*  ,,- fll((&//: ((01rctt}|j|jt }|j |j ||j||j|j|j|jj|j|jj|j|j|j |y)zi Adding a writer when there was previously no writer starts up a C{LoopingCall}. N)rrr,r-r.r/ isWriting addWriterr2r3r4r5r6r7rr9writers rtest_addWriterz%ContinuousPollingTests.test_addWriterAr<rcLtt}t}|j||j ||j |j |j|jjg|j|j|y)z= Removing a reader stops the C{LoopingCall}. N) rrr.r1 removeReaderr,r- assertEqualr7getDelayedCallsr/r0r8s rtest_removeReaderz(ContinuousPollingTests.test_removeReaderP{$EG, F# &,,' 88:B? ))&12rcLtt}t}|j||j ||j |j |j|jjg|j|j|y)z= Removing a writer stops the C{LoopingCall}. N) rrr.r? removeWriterr,r-rEr7rFr/r>r@s rtest_removeWriterz(ContinuousPollingTests.test_removeWriter\rHrctt}|jt|j ty)zM Removing unknown readers and writers silently does nothing. N)rrrJr.rD)rr9s rtest_removeUnknownz)ContinuousPollingTests.test_removeUnknownhs0$EG,FH%FH%rctt}t}|j||j |j |jt|j |j |j t|j |j |j t|j||j |j |j|j j|jt|jjdy)za Adding multiple readers and writers results in a single C{LoopingCall}. rN)rrr.r?r2r-r1rJr3r4rElenr7rFr@s rtest_multipleReadersAndWritersz5ContinuousPollingTests.test_multipleReadersAndWritersps $EG,  V\\*" V\\*" V\\*"F# V\\*  ,,- V__<<>?Crct}t|}t}|j||j |j g|j d|j |j dg|j d|j |j ddg|j d|j |j gdy)za Adding a reader causes its C{doRead} to be called every 1 milliseconds. gh㈵>r)rrrN)rrr r1rEradvancerreactorr9descs rtest_readerPollingz)ContinuousPollingTests.test_readerPollings '#G,| b)  vh/  vv&67  &>?rct}t|}t}|j||j |j g|j d|j |j dg|j d|j |j ddg|j d|j |j gdy)zb Adding a writer causes its C{doWrite} to be called every 1 milliseconds. MbP?r)rrrN)rrr r?rErrRrSs rtest_writerPollingz)ContinuousPollingTests.test_writerPollings '#G,| b) wi0 w&89 &ABrct}t|}t}d|_|j ||j |j g|jd|j |j dgy)zu If a C{doRead} returns a value indicating disconnection, C{connectionLost} is called on it. ctSr rrrrzBContinuousPollingTests.test_connectionLostOnRead..s n.rrXr!N)rrr rr1rErrRrSs rtest_connectionLostOnReadz0ContinuousPollingTests.test_connectionLostOnReadsg '#G,|.  b) vh/rct}t|}t}d|_|j ||j |j g|jd|j |j dgy)zv If a C{doWrite} returns a value indicating disconnection, C{connectionLost} is called on it. ctSr rrrrr\zCContinuousPollingTests.test_connectionLostOnWrite..s ~/rrXr!N)rrr rr?rErrRrSs rtest_connectionLostOnWritez1ContinuousPollingTests.test_connectionLostOnWritesg '#G,|/  b) vh/rctt}t}t}t}|j||j||j ||j ||j }|j |jg|j |jg|j t|d|j t||||hy)zv L{_ContinuousPolling.removeAll} removes all descriptors and returns the readers and writers. N) rrr.r1r? removeAllrE getReaders getWritersrOset)rr9r:rAbothremoveds rtest_removeAllz%ContinuousPollingTests.test_removeAlls $EG,x  ""$ **,b1 **,b1 Wq) W'=>rctt}t}|j||j ||j y)zb L{_ContinuousPolling.getReaders} returns a list of the read descriptors. N)rrr.r1assertInrdr8s rtest_getReadersz&ContinuousPollingTests.test_getReaders< $EG,  ff//12rctt}t}|j||j ||j y)zc L{_ContinuousPolling.getWriters} returns a list of the write descriptors. N)rrr.r?rkrer@s rtest_getWritersz&ContinuousPollingTests.test_getWritersrmrN)r%r&r'r(r;rBrGrKrMrPrVrYr]r`rirlrorrrr*r*+sK 2 2 3 3&D&@"C" 0 0?&33rr*)r(unittestrtwisted.internet.errorrtwisted.internet.posixbasertwisted.internet.taskrtwisted.trial.unittestrtwisted.internetr ImportErrorr r*rrrrwsm19'+- ##,LDEz3Xz3Fz37LsA AA