Your IP : 172.28.240.42


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


=Nc@sddlmZddlmZddlmZmZmZmZm	Z	ej
Z
ddlmZdej
fdYZdefdYZd	ejfd
YZdejfdYZd
ejfdYZdejfdYZdS(i(tset(tunittest(t
interfacesttasktreactortdeferterror(tfailuretTestableLoopingCallcBseZdZRS(cOs&tt|j||||_dS(N(tsuperRt__init__tclock(tselfRtatkw((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR
s(t__name__t
__module__R
(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRst
TestExceptioncBseZRS((RR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRst
ClockTestCasecBseZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZd
ZdZdZRS(s<
    Test the non-wallclock based clock implementation.
    cCs&tj}|j|jddS(sV
        Test that the L{seconds} method of the fake clock returns fake time.
        iN(RtClocktassertEqualtseconds(Rtc((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestSeconds scCsptj}|jddddd}|jtjj||j|jd|j|j	dS(s{
        Test that calls can be scheduled for later with the fake clock and
        hands back an L{IDelayedCall}.
        icSsdS(N(tNone(R
tb((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt<lambda>.sRiN(
RRt	callLatert
failUnlessRtIDelayedCallt
providedByRtgetTimetactive(RRtcall((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
testCallLater(s
cCsKtj}|jddddd}|j|j|jdS(s3
        Test that calls can be cancelled.
        icSsdS(N(R(R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR9sRiN(RRRtcanceltfailIfR (RRR!((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestCallLaterCancelled4s
cCs_tj}|jddddd}|jddddd}|j||kd	S(
s[
        Test that the DelayedCall returned is not one previously
        created.
        i
cSsdS(N(R(R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRDsiRicSsdS(N(R(R
R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyREsiiN(RRRR$(RRtcall1tcall2((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_callLaterOrdering>scsgtj}|jdfd}|jd|jg|jd|jdg|j|jdS(sE
        Test that advancing the clock will fire some calls.
        ics
jdS(N(tappendR((tevents(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyROsiN(RRRtadvanceRRR$R (RRR!((R*s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestAdvanceIs

csAtj}fd}|jd||jddS(s
        Test attemping to cancel the call in a callback.

        AlreadyCalled should be raised, not for example a ValueError from
        removing the call from Clock.calls. This requires call.called to be
        set before the callback is called.
        csjtjjdS(N(tassertRaisesRt
AlreadyCalledR#((RR!(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytcb`siN(RRRR+(RRR/((RR!s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestAdvanceCancelWscsgtj}|jdfdddd}|jd|j|jd|jd|jg|jd|jdgdS(	s1
        Test that calls can be delayed.
        icsj||fS(N(R)(R
R(R*(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRlsRig?g?N(ii(RRRtdelayRRR+(RRR!((R*s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestCallLaterDelayedfs$


csgtj}|jdfdddd}|jd|jd|j|jd|jd|jg|jd|jdgdS(	sL
        Test that calls can have their time reset to a later time.
        icsj||fS(N(R)(R
R(R*(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR{siRiiN(ii(RRRR+tresetRR(RRR!((R*s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestCallLaterResetLaterus$



cs}gtj}|jdfdddd}|jd|j|jd|jd|jdgdS(	sO
        Test that calls can have their time reset to an earlier time.
        icsj||fS(N(R)(R
R(R*(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsiRiiN(ii(RRRR3RRR+(RRR!((R*s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestCallLaterResetSooners$

cCshtj}|jdd}|jdd}|j}|jt||gt|dS(sB
        Test that we can get a list of all delayed calls
        icSsdS(N(R(tx((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsicSsdS(N(R(R6((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsN(RRRtgetDelayedCallsRR(RRR!R'tcalls((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_getDelayedCallss
cCs&tj}|j|jgdS(sk
        Test that we get an empty list from getDelayedCalls on a newly
        constructed Clock.
        N(RRRR7(RR((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_getDelayedCallsEmptyscCs,tj}|jtjj|ddS(Ns#Clock does not provide IReactorTime(RRRRtIReactorTimeR(RR((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_providesIReactorTimescsgd
dg}tjfd}jd|d}|jdjd|djdgd|j|d	S(s4
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        adding a new call via calling L{task.Clock.callLater} again.

        For example, if L{task.Clock.callLater} is invoked with a callable "A"
        and a time t0, and then the L{IDelayedCall} which results from that is
        C{reset} to a later time t2 which is greater than t0, and I{then}
        L{task.Clock.callLater} is invoked again with a callable "B", and time
        t1 which is less than t2 but greater than t0, "B" will be invoked before
        "A".
        Rg@R
g@csj|jfS(N(R)R(tn(Rtresult(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsg?iiN(Rg@(R
g@(RRRR3tpumpR(Rtexpectedtlogtimetcall_a((RR>s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_callLaterKeepsCallsOrdereds
csgd
dg}tjfd}jd|d}jd|d|jdjdgd|j|d	S(s:
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        re-scheduling an existing call via L{IDelayedCall.reset} on the result
        of a previous call to C{callLater}.

        For example, if L{task.Clock.callLater} is invoked with a callable "A"
        and a time t0, and then L{task.Clock.callLater} is invoked again with a
        callable "B", and time t1 greater than t0, and finally the
        L{IDelayedCall} for "A" is C{reset} to a later time, t2, which is
        greater than t1, "B" will be invoked before "A".
        Rg@R
g@csj|jfS(N(R)R(R=(RR>(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsg?iiN(Rg@(R
g@(RRRR3R?R(RR@RARB((RR>s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt$test_callLaterResetKeepsCallsOrdereds
csgdd
g}tjfd}jd|dfd}jd|jd|djd	gd
|j|dS(s9
        The order of calls scheduled by L{task.Clock.callLater} is honored when
        re-scheduling an existing call via L{IDelayedCall.reset} on the result
        of a previous call to C{callLater}, even when that call to C{reset}
        occurs within the callable scheduled by C{callLater} itself.
        Rg@Rg@csj|jfS(N(R)R(R=(RR>(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsg@csjddS(Ng@(R3((tcall_b(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR
sg?g?i
N(Rg@(Rg@(RRRR?R(RR@RAR
((RRER>s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt.test_callLaterResetInsideCallKeepsCallsOrdereds(RRt__doc__RR"R%R(R,R0R2R4R5R9R:R<RCRDRF(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRs 			
						
	
					tLoopTestCasecBszeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
dZRS(
s[
    Tests for L{task.LoopingCall} based on a fake L{IReactorTime}
    implementation.
    cCs)tjd}|j|jtdS(sG
        L{LoopingCall}'s default clock should be the reactor.
        cSsdS(N(R(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsN(RtLoopingCallRRR(RR!((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_defaultClockscsIgd	tjfd}tj|}|_d|jd|jdg|jjjd|jdgdjd|jddg|jjdjd|jddgdjd|jdddg|jjdd	S(
s
        When more time than the defined interval passes during the execution
        of a callback, L{LoopingCall} should schedule the next call for the
        next interval which is still in the future.
        cs$jjjdS(N(R)RR+((RtcallDurationttimes(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt	aCallbacksig?iig@g@iN(	RRRRIRtstartRRR+(RRMR!((RRKRLs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_callbackTimeSkipss,	




csgtjfd}tj|}|_|jd|jdgjd|jddgjd|jdddgjd|jdddgdS(s	
        When more time than the defined interval passes between when
        L{LoopingCall} schedules itself to run again and when it actually
        runs again, it should schedule the next call for the next interval
        which is still in the future.
        csjjdS(N(R)R((RRL(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRMAsg?iiiiN(RRRIRRNRR+(RRMR!((RRLs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_reactorTimeSkips8s	



cs,gtjfd}tjj|}|_d}d}|j||jd
gj|||jd||dfgjd|||jd||dfd|d|dfgjd|jd
||dfd|d|dfgd	S(s
        When L{LoopingCall} schedules itself to run again, if more than the
        specified interval has passed, it should schedule the next call for the
        next interval which is still in the future. If it was created
        using L{LoopingCall.withCount}, a positional argument will be
        inserted at the beginning of the argument list, indicating the number
        of calls that should have been made.
        csjj|fdS(N(R)R(tnumCalls(RRL(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRMesg?g{Gz?iiiiiN(ii(ii(ii(ii(RRRIt	withCountRRNRR+(RRMR!tINTERVALtREALISTIC_DELAY((RRLs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_reactorTimeCountSkipsZs&		
 	
	cs
gtjfd}tjj|}|_d}d}|j||jjdj|||jj||dfj|d|jjd||dfj|d|jjd	||dfd
S(s1
        L{LoopingCall.withCount} counts only calls that were expected to be
        made.  So, if more than one, but less than two intervals pass between
        invocations, it won't increase the count above 1.  For example, a
        L{LoopingCall} with interval T expects to be invoked at T, 2T, 3T, etc.
        However, the reactor takes some time to get around to calling it, so in
        practice it will be called at T+something, 2T+something, 3T+something;
        and due to other things going on in the reactor, "something" is
        variable.  It won't increase the count unless "something" is greater
        than T.  So if the L{LoopingCall} is invoked at T, 2.75T, and 3T,
        the count has not increased, even though the distance between
        invocation 1 and invocation 2 is 1.75T.
        csjj|fdS(N(R)R(tcount(RRL(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRMsg?g{Gz?iig?g@g?g@N(ii(	RRRIRRRRNRtpopR+(RRMR!RSRT((RRLs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_countLengthyIntervalCountss	
 $csDdddg}tj}gddfd}t||dddd}|jd}gfd}|j||j||jtdd	tfxZD]R\}}}	}
|j|d|j|d|j|	d|j|
dqW|j	|j
d
||j|jdS(Ng?g?csj||||fdS(N(R)(R
RRtd(tL(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytfoosR
RRYcsj|dS(N(R)(R>(t	theResult(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
saveResultsisgot %d iterations, not 3i(
RRRRRNtaddCallbackR?RtlentstoptassertIdenticalR$R8(RttimingsRR[tlctDR]R
RRRY((R\RZs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestBasicFunctions(


csdddg}tj}g}t||jd}|jddt}gfd}|j||j||j	t
|ddt
|f|j|jd||j
|jdS(Ng?g?tnowcsj|dS(N(R)(R>(R\(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR]sisgot %d iterations, not 2i(RRRR)RRNtFalseR^R?RR_R`RaR$R8(RRbRRZRcRYR]((R\s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestDelayedStarts


cCs,tjd}|jt|jddS(NcSsdS(N(R(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsi(RRIR-t
ValueErrorRN(RRc((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestBadDelayscsngfd}tj}t||}|j|dt|j|j|j|jdS(NcsjddS(N(R)R((tran(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[sRf(RRRRNRgR`R$R8(RR1R[RRc((Rks:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
_stoppingTests

cCs
|jdS(Ni(Rl(R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestStopAtOncescCs
|jdS(Ni
(Rl(R((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestStoppingBeforeDelayedStart	scsgfd}tj}t||}|jddt|jd|j|jd|jg|jd|jdgdS(s8
        Test that L{LoopingCall} can be reset.
        csjddS(N(R)R((Rk(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[siRfiN(	RRRRNRgR+R3RR(RR[RRc((Rks:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
test_reset
s



(RRRGRJRORPRURXReRhRjRlRmRnRo(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRHs		3	"	0	)	'			
		tReactorLoopTestCasecBsPeZdZdZdZdZdZdZdZdZ	RS(cCs4d}tj|d}|j|jdtS(NcSst|dS(N(R(R6((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[%stbarg?(RRIt
assertFailureRNR(RR[Rc((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestFailure$s	cs:fd}tj|d|jjdtS(Ncsjt|dS(N(R`R(R6(Rc(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[-s
Rqg?(RRIRrRNR(RR[((Rcs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestFailAndStop,scsUgfd}tj|jd}fd}|j|S(Ncs0jdtdkr,jndS(Ni(R)RR_R`((RkRc(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[8s
icsjtddS(Ni(RR_(tign(RkR(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytstopped?s(RRIRNR^(RR[RYRv((RkRRcs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestEveryIteration5scs]tjfd}tj||_|jjddttjd|j	S(NcsjtjddS(Ns'This task also should never get called.(terrbackRtDefaultException((RY(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[HsiRfi(
RtDeferredRRIt_lcRNRgRRt!_callback_for_testStopAtOnceLater(RR[((RYs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestStopAtOnceLaterDscCs'|jjtjd|jddS(Nitsuccess(R{R`RRtcallback(RRY((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR|Qs
csgddg}tjfd}t|jdj||jjdS(Ng?g?cs<tj}|jfdjd|jd|S(Ncs
jS(N(R`(t_(Rc(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR]si(RRzR^RRR(RY(RcR(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[[s(RRRRNR?R$R8(RRbR[((RcRs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestWaitDeferredUs

cssdg}tjfd}t|}|jd}|j|tj||jj|S(Ng333333?cs)tj}jd|jt|S(Ng333333?(RRzRRxR(RY(R(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyR[psi(	RRRRNRrRR?R$R8(RRbR[RcRY((Rs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttestFailurePropagationfs	
cstj}tjgfd}tjj|}||_|jddt|j	g|j
ddg|j	tdjd|j
dg|j	td|j	ddgdS(	s?
        In the case that the function passed to L{LoopingCall.withCount}
        returns a deferred, which does not fire before the next interval
        elapses, the function should not be run again. And if a function call
        is skipped in this fashion, the appropriate count should be
        provided.
        cs+j|tdkr#SdSdS(Ni(R)R_R(t
possibleCount(tdeferredCountsRY(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytcountTrackers
g?Rfg?iiiN(RRRRzRIRRRRNRgRR?R_RR(Rt	testClockRRc((RYRs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_deferredWithCount~s	
(
RRRsRtRwR}R|RRR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRp!s					
			tDeferLaterTestscBs)eZdZdZdZdZRS(s'
    Tests for L{task.deferLater}.
    csgtfd}tj}tj|d|ddd}|j|j|jd|jg|jd|jdg|S(s
        The L{Deferred} returned by L{task.deferLater} is called back after
        the specified delay with the result of the function passed in.
        csj||fS(N(R)(R[Rq(tflagtresults(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytcallablesiR[Rqii(sfooRq(tobjectRRt
deferLaterR^RaR+R(RRRRY((RRs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt
test_callbacks	

cCsGd}tj}tj|d|}|jd|j|tS(s
        The L{Deferred} returned by L{task.deferLater} is errbacked if the
        supplied function raises an exception.
        cSs
tdS(N(R(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRsi(RRRR+RrR(RRRRY((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_errbacks
	
cspgtjtjdjd}|jfd}j|tj|j	||S(s
        The L{Deferred} returned by L{task.deferLater} can be
        cancelled to prevent the call from actually being performed.
        ics'jgjjdS(N(RR7tassertFalse(tignored(RtcalledR(s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pytcbCancelledsN(
RRRR)RR#RrRtCancelledErrorR^(RRYR((RRRs:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyttest_cancels

(RRRGRRR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyRs		N(ttwisted.python.compatRt
twisted.trialRttwisted.internetRRRRRRttwisted.pythonRRIRt	ExceptionRtTestCaseRRHRpR(((s:/usr/lib/python2.7/dist-packages/twisted/test/test_task.pyt<module>s(	*