Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/twisted/internet/test/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyc


=Nc@sHdZddlmZddlmZddlmZddlmZm	Z	ddl
mZdZ
yddlmZWnek
rdZ
nXdd	lmZdd
lmZddlmZdefd
YZdefdYZdefdYZdefdYZdefdYZdefdYZdS(s>
Tests for L{twisted.internet.posixbase} and supporting code.
i(tset(tTestCase(tDeferred(tPosixReactorBaset_Waker(t
ServerFactory(tunixs)Platform does not support AF_UNIX sockets(tPort(treactor(tClientPrototTrivialReactorcBs5eZdZdZdZdZdZRS(cCs#i|_i|_tj|dS(N(t_readerst_writersRt__init__(tself((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR
s		cCst|j|<dS(N(tTrueR(Rtreader((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt	addReader scCs|j|=dS(N(R(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytremoveReader$scCst|j|<dS(N(RR(Rtwriter((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt	addWriter(scCs|j|=dS(N(R(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytremoveWriter,s(t__name__t
__module__R
RRRR(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR
s
				tPosixReactorBaseTestscBsMeZdZdZdZdZdZdZdZdZ	RS(s(
    Tests for L{PosixReactorBase}.
    cCsC|j|jt|j|j|j|j|j|jdS(N(tassertIsInstancetwakerRtassertInt_internalReadersR(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt_checkWaker6scCst}|j|dS(s
        When L{PosixReactorBase} is instantiated, it creates a waker and adds
        it to its internal readers set.
        N(R
R(RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_wakerIsInternalReader<s	cCs|t}t}|jj||j||j|j|j|j||j	||j|j	||jdS(s
        Any L{IReadDescriptors} in L{PosixReactorBase._internalReaders} are
        left alone by L{PosixReactorBase._removeAll}.
        N(
R
tobjectRtaddRt
_removeAllRRRR(RRtextra((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt"test_removeAllSkipsInternalReadersEs		

cCst}t}t}|j||j||j|j|j}|jt|t||g|j	||j|j	||jdS(s
        L{PosixReactorBase._removeAll} returns a list of removed
        L{IReadDescriptor} and L{IWriteDescriptor} objects.
        N(
R
RRRR!RRtassertEqualRtassertNotIn(RRRRtremoved((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt'test_removeAllReturnsRemovedDescriptorsTs			

"cCsvddlm}|j|j|jg}|jt|d|j|ddt|jd|dddS(	s
        L{twisted.internet.interfaces.IReactorArbitrary} is redundant with
        L{twisted.internet.interfaces.IReactorFDSet} and is deprecated.
        i(t
interfacesiitcategorysbtwisted.internet.interfaces.IReactorArbitrary was deprecated in Twisted 10.1.0: See IReactorFDSet.tmessageN(ttwisted.internetR(tIReactorArbitraryt
flushWarningst"test_IReactorArbitraryIsDeprecatedR$tlentDeprecationWarning(RR(t
warningsShown((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR.escCsdd	dY}t}|j||j|jg}|jt|d|j|ddt|jd|dddS(
s
        L{PosixReactorBase} implements the deprecated L{IReactorArbitrary}, and
        L{PosixReactorBase.listenWith} is a part of that interface. To avoid
        unnecessary deprecation warnings when importing posixbase, the
        L{twisted.internet.interfaces._IReactorArbitrary} alias that doesn't
        have the deprecation warning is imported, and instead
        L{PosixReactorBase.listenWith} generates its own deprecation warning.
        tfakePortcBseZdZdZRS(c_sdS(N((Rtargstkw((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR
scSsdS(N((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytstartListenings(RRR
R5(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR2s	iiR)s@listenWith is deprecated since Twisted 10.1.  See IReactorFDSet.R*N((R
t
listenWithR-ttest_listenWithIsDeprecatedR$R/R0(RR2Rtwarnings((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR7ws		
cCsdd	dY}t}|j||j|jg}|jt|d|j|ddt|jd|dddS(
s
        L{PosixReactorBase} implements the deprecated L{IReactorArbitrary}, and
        L{PosixReactorBase.connectWith} is a part of that interface. To avoid
        unnecessary deprecation warnings when importing posixbase, the
        L{twisted.internet.interfaces._IReactorArbitrary} alias that doesn't
        have the deprecation warning is imported, and instead
        L{PosixReactorBase.connectWith} generates its own deprecation warning.
        t
fakeConnectorcBseZdZdZRS(c_sdS(N((RR3R4((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR
scSsdS(N((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytconnects(RRR
R:(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR9s	iiR)sAconnectWith is deprecated since Twisted 10.1.  See IReactorFDSet.R*N((R
tconnectWithR-ttest_connectWithIsDeprecatedR$R/R0(RR9RR8((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR<s		
(
RRt__doc__RRR#R'R.R7R<(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR1s							tTCPPortTestscBs/eZdZeees$dZndZRS(s1
    Tests for L{twisted.internet.tcp.Port}.
    sNon-posixbase reactorcCs=tdt}t|_d|_|j|jtS(s
        L{Port.stopListening} returns a L{Deferred} which errbacks if
        L{Port.connectionLost} raises an exception.
        i90cSsddS(Nii((treason((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt<lambda>s(RRRt	connectedtconnectionLostt
assertFailuret
stopListeningtZeroDivisionError(Rtport((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_connectionLostFaileds	(RRR=t
isinstanceRRtskipRG(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR>s	tTimeoutReportReactorcBs;eZdZdZdZdZdZdZRS(s
    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.
    cCs&tj|t|_d|_dS(Nid(RR
RtiterationTimeouttnow(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR
s
cCsdS(s
        Ignore the reader.  This is necessary because the waker will be
        added.  However, we won't actually monitor it for any events.
        N((RR((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyRscCsgS(s
        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.
        ((R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt	removeAllscCs|jS(sx
        Override the real clock with a deterministic one that can be easily
        controlled in a unit test.
        (RL(R((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytsecondsscCs2|j}|dk	r.d|_|j|ndS(N(RKtNonetcallback(Rttimeouttd((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytdoIterations		(RRR=R
RRMRNRS(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyRJs					tIterationTimeoutTestscBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s
    Tests for the timeout argument L{PosixReactorBase.run} calls
    L{PosixReactorBase.doIteration} with in the presence of various delayed
    calls.
    csDg}jj|jjjfdj|dS(Ncs
jS(N(tstop(tignored(R(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@si(RKtaddCallbacktappendtrun(RRRQ((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt_checkIterationTimeouts

cCs,t}|j|}|j|ddS(sl
        If there are no delayed calls, C{doIteration} is called with a
        timeout of C{None}.
        N(RJRZR$RO(RRRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_noCallss	cCs?t}|jdd|j|}|j|ddS(s
        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.
        idcSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@sN(RJt	callLaterRZR$(RRRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_delayedCalls	cCsNt}|jdd|jd7_|j|}|j|ddS(s
        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.
        idcSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@siiKN(RJR\RLRZR$(RRRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_timePassess
	cCset}|jdd|jdd|jdd|j|}|j|ddS(s
        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.
        i2cSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@(si
cSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@)sidcSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@*sN(RJR\RZR$(RRRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_multipleDelayedCalls!s	cCs]t}|jdd}|jd7_|jd|j|}|j|ddS(s
        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.
        i2cSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@6siiN(RJR\RLtresetRZR$(RRtcallRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_resetDelayedCall/s	
cCs]t}|jdd}|jd7_|jd|j|}|j|ddS(s
        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.
        i2cSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@Esi
ii<N(RJR\RLtdelayRZR$(RRRaRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_delayDelayedCall=s	
cCsKt}|jdd}|j|j|}|j|ddS(sp
        If the only delayed call is canceled, C{None} is the timeout passed
        to C{doIteration}.
        i2cSsdS(N(RO(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyR@RsN(RJR\tcancelRZR$RO(RRRaRQ((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyttest_cancelDelayedCallLs
	
(RRR=RZR[R]R^R_RbRdRf(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyRTs		
		
			tConnectedDatagramPortTestCasecBs5eZdZedk	r!eZndZdZRS(s/
    Test connected datagram UNIX sockets.
    cs>fd}tjdt}||_|jddS(s
        L{ConnectedDatagramPort} does not call the deprecated C{loseConnection}
        in L{ConnectedDatagramPort.connectionFailed}.
        csjddS(s
            Dummy C{loseConnection} method. C{loseConnection} is deprecated and
            should not get called.
            s7loseConnection is deprecated and should not get called.N(tfail((R(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pytloseConnectionfstgoodbyeN(RtConnectedDatagramPortROR	RitconnectionFailed(RRiRF((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt-test_connectionFailedDoesntCallLoseConnectionas	csZt_fd}tjdt}||_|jdjjt	dS(s
        L{ConnectedDatagramPort} calls L{ConnectedDatagramPort.stopListening}
        instead of the deprecated C{loseConnection} in
        L{ConnectedDatagramPort.connectionFailed}.
        cs
t_dS(s8
            Dummy C{stopListening} method.
            N(Rtcalled((R(sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyRDzsRjN(
tFalseRnRRkROR	RDRlR$R(RRDRF((RsH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt'test_connectionFailedCallsStopListeningrs		
N(RRR=tskipSocketsRORIRmRp(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyRgYs
		N(R=ttwisted.python.compatRttwisted.trial.unittestRttwisted.internet.deferRttwisted.internet.posixbaseRRttwisted.internet.protocolRRORqR+RtImportErrorttwisted.internet.tcpRRttwisted.test.test_unixR	R
RR>RJRTRg(((sH/usr/lib/python2.7/dist-packages/twisted/internet/test/test_posixbase.pyt<module>s&

,i