Ϫf=.\dZddlZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZdZ dd lmZdd lmZdd lmZdd lmZGddeZGddeZGddeZGddeZGddeZGddeZGddeZGddeZy#e$rd ZYnwxYw)z> Tests for L{twisted.internet.posixbase} and supporting code. N)Deferred)IReadDescriptor)PosixReactorBase_Waker) ServerFactory)platform)TestCase)unix) ClientProtoz)Platform does not support AF_UNIX sockets)reactor)Portc,eZdZdZfdZfdZxZS)WarningCheckerTestCasezg A test case that will make sure that no warnings are left unchecked at the end of a test run. ct|tjj ddj dk(r&t jr|jyyy)NCItrue) supersetUposenvirongetlowerr isWindows flushWarnings)self __class__s F/usr/lib/python3/dist-packages/twisted/internet/test/test_posixbase.pyrzWarningCheckerTestCase.setUp sN   ::>>$ # ) ) +v 5(:L:L:N    ;O 5c t||j}tjj ddj dk(rtjry|jt|dd|y#|j}tjj ddj dk(rtjrYy|jt|dd|wxYw)Nrrrrz'Warnings found at the end of the test: ) rtearDownrrrrrrr assertEquallen)rwarningsrs rr!zWarningCheckerTestCase.tearDown+s  G  ))+Hzz~~dB'--/69h>P>P>R   H q$LXJ"W ))+Hzz~~dB'--/69h>P>P>R   H q$LXJ"W sBAD D)__name__ __module__ __qualname____doc__rr! __classcell__)rs@rrrs !rrc*eZdZdZdZdZdZdZy)TrivialReactorcJi|_i|_tj|yN)_readers_writersr__init__rs rr0zTrivialReactor.__init__>s  !!$'rc"d|j|<yNTr.rreaders r addReaderzTrivialReactor.addReaderC $ frc|j|=yr-r4r5s r removeReaderzTrivialReactor.removeReaderF MM& !rc"d|j|<yr3r/rwriters r addWriterzTrivialReactor.addWriterIr8rc|j|=yr-r=r>s r removeWriterzTrivialReactor.removeWriterLr;rN)r%r&r'r0r7r:r@rBrrr+r+=s( %"%"rr+c(eZdZdZdZdZdZdZy)PosixReactorBaseTestsz( Tests for L{PosixReactorBase}. c|j|jt|j|j|j|j|j|j yr-)assertIsInstancewakerrassertIn_internalReadersr.rr s r _checkWakerz!PosixReactorBaseTests._checkWakerUsF gmmV4 gmmW%=%=> gmmW%5%56rc:t}|j|y)z When L{PosixReactorBase} is instantiated, it creates a waker and adds it to its internal readers set. N)r+rLrKs rtest_wakerIsInternalReaderz0PosixReactorBaseTests.test_wakerIsInternalReaderZs !" !rcft}t}|jj||j||j |j |j|j||j||j|j||j y)z Any L{IReadDescriptor}s in L{PosixReactorBase._internalReaders} are left alone by L{PosixReactorBase._removeAll}. N) r+objectrJaddr7 _removeAllr.r/rLrI)rr extras r"test_removeAllSkipsInternalReadersz8PosixReactorBaseTests.test_removeAllSkipsInternalReadersbs !"  $$U+% 7++W-=-=> ! eW556 eW--.rct}t}t}|j||j||j|j |j }|jt|||h|j||j |j||j y)z L{PosixReactorBase._removeAll} returns a list of removed L{IReadDescriptor} and L{IWriteDescriptor} objects. N) r+rPr7r@rRr.r/r"set assertNotIn)rr r6r?removeds r'test_removeAllReturnsRemovedDescriptorsz=PosixReactorBaseTests.test_removeAllReturnsRemovedDescriptorsps !"&!&!$'$$W%5%5w7G7GH W'78 !1!12 !1!12rN)r%r&r'r(rLrNrTrYrCrrrErEPs7 " / 3rrEc,eZdZdZeeesdZdZy) TCPPortTestsz1 Tests for L{twisted.internet.tcp.Port}. zNon-posixbase reactorctdt}d|_d|_|j |j t S)z L{Port.stopListening} returns a L{Deferred} which errbacks if L{Port.connectionLost} raises an exception. i90Tc ddzS)NrrC)reasons rz8TCPPortTests.test_connectionLostFailed..s Q!Vr)r r connectedconnectionLost assertFailure stopListeningZeroDivisionError)rports rtest_connectionLostFailedz&TCPPortTests.test_connectionLostFaileds> E=?+3!!$"4"4"68IJJrN) r%r&r'r( isinstancer rskiprgrCrrr[r[s g/ 0&Krr[cHeZdZdZdZdeddfdZdeddfdZdZd Z d Z y) TimeoutReportReactorz A reactor which is just barely runnable and which cannot monitor any readers or writers, and which fires a L{Deferred} with the timeout passed to its C{doIteration} method as soon as that method is invoked. cZtj|t|_d|_y)Nd)rr0riterationTimeoutnowr1s rr0zTimeoutReportReactor.__init__s!!!$' ( rr6returnNcy)z Ignore the reader. This is necessary because the waker will be added. However, we won't actually monitor it for any events. NrCr5s rr7zTimeoutReportReactor.addReaderrcy)z# See L{addReader}. NrCr5s rr:z!TimeoutReportReactor.removeReaderrrrcgS)z There are no readers or writers, so there is nothing to remove. This will be called when the reactor stops, though, so it must be implemented. rCr1s r removeAllzTimeoutReportReactor.removeAlls  rc|jS)zx Override the real clock with a deterministic one that can be easily controlled in a unit test. )ror1s rsecondszTimeoutReportReactor.secondss xxrcR|j}|d|_|j|yyr-)rncallback)rtimeoutds r doIterationz TimeoutReportReactor.doIterations+  ! ! =$(D ! JJw  r) r%r&r'r(r0rr7r:rurwr|rCrrrkrksA    D  ? t  rrkc@eZdZdZdZdZdZdZdZdZ dZ d Z y ) IterationTimeoutTestsz Tests for the timeout argument L{PosixReactorBase.run} calls L{PosixReactorBase.doIteration} with in the presence of various delayed calls. cg}jj|jjjfdj|dS)Nc&jSr-)stop)ignoredr s rr`z>IterationTimeoutTests._checkIterationTimeout..s\W\\^rr)rn addCallbackappendrunrr rzs ` r_checkIterationTimeoutz,IterationTimeoutTests._checkIterationTimeoutsJ  ,,W^^<  ,,-KL qzrc\t}|j|}|j|y)zl If there are no delayed calls, C{doIteration} is called with a timeout of L{None}. N)rkr assertIsNoners r test_noCallsz"IterationTimeoutTests.test_noCallss* '(--g6 '"rct}|jdd|j|}|j|dy)z If there is a delayed call, C{doIteration} is called with a timeout which is the difference between the current time and the time at which that call is to run. rmcyr-rCrCrrr`z8IterationTimeoutTests.test_delayedCall..rrrNrk callLaterrr"rs rtest_delayedCallz&IterationTimeoutTests.test_delayedCalls> '(#|,--g6 #&rct}|jdd|xjdz c_|j|}|j |dy)z If a delayed call is scheduled and then some time passes, the timeout passed to C{doIteration} is reduced by the amount of time which passed. rmcyr-rCrCrrr`z7IterationTimeoutTests.test_timePasses..rrrKN)rkrrorr"rs rtest_timePassesz%IterationTimeoutTests.test_timePassessL '(#|, r --g6 "%rct}|jdd|jdd|jdd|j|}|j|dy)z If there are several delayed calls, C{doIteration} is called with a timeout which is the difference between the current time and the time at which the earlier of the two calls is to run. 2cyr-rCrCrrr`zAIterationTimeoutTests.test_multipleDelayedCalls..rrr cyr-rCrCrrr`zAIterationTimeoutTests.test_multipleDelayedCalls..rrrrmcyr-rCrCrrr`zAIterationTimeoutTests.test_multipleDelayedCalls..rrrNrrs rtest_multipleDelayedCallsz/IterationTimeoutTests.test_multipleDelayedCallssb '("l+"l+#|,--g6 "%rct}|jdd}|xjdz c_|jd|j |}|j |dy)z If a delayed call is reset, the timeout passed to C{doIteration} is based on the interval between the time when reset is called and the new delay of the call. rcyr-rCrCrrr`z=IterationTimeoutTests.test_resetDelayedCall..rrrrN)rkrroresetrr"rr callrzs rtest_resetDelayedCallz+IterationTimeoutTests.test_resetDelayedCallsY '( w  \2 r  2--g6 "%rct}|jdd}|xjdz c_|jd|j |}|j |dy)z If a delayed call is re-delayed, the timeout passed to C{doIteration} is based on the remaining time before the call would have been made and the additional amount of time passed to the delay method. rcyr-rCrCrrr`z=IterationTimeoutTests.test_delayDelayedCall..rrrr<N)rkrrodelayrr"rs rtest_delayDelayedCallz+IterationTimeoutTests.test_delayDelayedCallsY'( w  \2 r  2--g6 "%rct}|jdd}|j|j|}|j |y)zp If the only delayed call is canceled, L{None} is the timeout passed to C{doIteration}. rcyr-rCrCrrr`z>IterationTimeoutTests.test_cancelDelayedCall..rrrN)rkrcancelrrrs rtest_cancelDelayedCallz,IterationTimeoutTests.test_cancelDelayedCallsG '( w  \2 --g6 '"rN) r%r&r'r(rrrrrrrrrCrrr~r~s/ # ' & & & & #rr~c$eZdZdZeeZdZdZy)ConnectedDatagramPortTestsz/ Test connected datagram UNIX sockets. Nc|fd}tjdt}||_|j dy)z L{ConnectedDatagramPort} does not call the deprecated C{loseConnection} in L{ConnectedDatagramPort.connectionFailed}. c(jdy)z Dummy C{loseConnection} method. C{loseConnection} is deprecated and should not get called. z7loseConnection is deprecated and should not get called.N)failr1srloseConnectionz`ConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection..loseConnection0s IIO PrNgoodbye)r ConnectedDatagramPortr rconnectionFailed)rrrfs` r-test_connectionFailedDoesntCallLoseConnectionzHConnectedDatagramPortTests.test_connectionFailedDoesntCallLoseConnection*s5  Q))$ >, i(rcd_fd}tjdt}||_|j dj jy)z L{ConnectedDatagramPort} calls L{ConnectedDatagramPort.stopListening} instead of the deprecated C{loseConnection} in L{ConnectedDatagramPort.connectionFailed}. Fcd_y)z8 Dummy C{stopListening} method. TN)calledr1srrdzYConnectedDatagramPortTests.test_connectionFailedCallsStopListening..stopListeningCs DKrNr)rr rr rdr assertTrue)rrdrfs` r'test_connectionFailedCallsStopListeningzBConnectedDatagramPortTests.test_connectionFailedCallsStopListening;sM    ))$ >* i(  $r)r%r&r'r( skipSocketsrirrrCrrrr"s)"%rrceZdZdZy) WakerTestsct}|j}|jt|d||j d|j}|jt|d|y)zH No warnings are generated when constructing the waker. rN)rrr"r#rb)rrHr$s r test_noWakerConstructionWarningsz+WakerTests.test_noWakerConstructionWarningsPsc%%' X84 T"%%' X84rN)r%r&r'rrCrrrrOs 5rr) r(rtwisted.internet.deferrtwisted.internet.interfacesrtwisted.internet.posixbaserrtwisted.internet.protocolrtwisted.python.runtimertwisted.trial.unittestr rtwisted.internetr twisted.test.test_unixr ImportErrorr twisted.internet.tcpr rr+rEr[rkr~rrrCrrrs +7?3++ >%2%%XD"%"&-32-3`K)K&* +* Z_#2_#D*%!7*%Z 5' 5w >=K>s B!!B+*B+