Your IP : 172.28.240.42


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


=Nc@sOdZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZmZdd
lmZdefdYZd
efdYZdejfdYZdefdYZdefdYZdefdYZdefdYZdefdYZdS(s!
Tests for L{twisted.trial.util}
iN(t
implements(tIProcessTransport(tdefer(tDelayedCall(tTestCase(tutil(tDirtyReactorAggregateErrort_Janitor(tpackagest
TestMktempcBs,eZdZdZdZdZRS(cCsK|j}tjj|jtjd }|j|dddgdS(Nistwisted.trial.test.test_utilR	t	test_name(tmktemptostpathtdirnametsplittseptassertEqual(tselftnametdirs((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR
s"cCs&|j}|j||jdS(N(RtfailIfEqual(RR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_uniquescCsT|j}tjj|}|jtjj||jtjj|dS(N(RRR
Rt
failUnlesstexiststfailIf(RRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_created#scCs8tjj|j}|j|jtjdS(N(RR
tabspathRRt
startswithtgetcwd(RR
((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt
test_location)s(t__name__t
__module__R
RRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR	s			tTestIntrospectioncBseZdZRS(cCsdddl}tj|jj}|j|g}x-t||D]\}}|j||q@WdS(Ni(tsuppressionRtgetPythonContainerstTestSuppression2ttestSuppressModuletzipR(RR"tparentstexpectedtatb((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_containers/s(RR R+(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR!.stTestFindObjectcBs_eZdZdZdZdZdZdZdZdZ	dZ
d	ZRS(
s4
    Tests for L{twisted.trial.util.findObject}
    cCsctjd|j}|jt|d|j|ddt|j|ddddS(sH
        Calling L{findObject} results in a deprecation warning
        tiitcategorytmessagesstwisted.trial.util.findObject was deprecated in Twisted 10.1.0: Please use twisted.python.reflect.namedAny instead.N(Rt
findObjectt
flushWarningsRtlentassertIdenticaltDeprecationWarning(Rt
warningsShown((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_deprecation=s
cCs5tjd}ddl}|j|t|fdS(Ntpackagei(RR0R7RtTrue(Rtpackage1tpackage2((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_importPackageKscCs9tjd}ddlm}|jt|f|dS(Nsgoodpackage.test_samplei(ttest_sample(RR0tgoodpackageR<RR8(Rttest_sample2R<((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_importModulePscCs|jttjddS(Nspackage.test_bad_module(tfailUnlessRaisestZeroDivisionErrorRR0(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_importErrorUs	cCs|jttjddS(Nspackage2.test_module(R@tImportErrorRR0(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_sophisticatedImportErrorYs	cCs!|jtjddtdS(Ntdoesntexisti(RRR0tFalse(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_importNonexistentPackage]scCs!|jtjddtdS(Nspackage.doesntexisti(RRR0RF(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_findNonexistentModule`scCs>|jtjddt|jtjddtdS(Nsgoodpackage.test_sample.doesntis0goodpackage.test_sample.AlphabetTest.doesntexist(RRR0RF(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_findNonexistentObjectcscCs<tjd}ddlm}|j|t|jfdS(Ns$goodpackage.test_sample.AlphabetTesti(R<(RR0R=R<RR8tAlphabetTest(Rtalpha1R<((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_findObjectExistis(RR t__doc__R6R;R?RBRDRGRHRIRL(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR,8s								tTestRunSequentiallycBsheZdZdZdZdZdZdZdZdZ	dZ
d	Zd
e_RS(s
    Sometimes it is useful to be able to run an arbitrary list of callables,
    one after the other.

    When some of those callables can return Deferreds, things become complex.
    cCs&tjg}|j|jg|S(s
        When asked to run an empty list of callables, runSequentially returns a
        successful Deferred that fires an empty list.
        (Rt_runSequentiallytaddCallbackR(Rtd((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_emptyListxscCs8tjdg}|j|jtjdfg|S(s
        When given a callable that succeeds without returning a Deferred,
        include the return value in the results list, tagged with a SUCCESS
        flag.
        cSsdS(N(tNone(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt<lambda>sN(RRORPRRtSUCCESSRS(RRQ((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_singleSynchronousSuccessscs7tjfdg}fd}|j|S(s
        When given a callable that raises an exception, include a Failure for
        that exception in the results list, tagged with a FAILURE flag.
        cs
jdS(Ntfoo(tfail((R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscsL|\\}}|jjj|jdj|tjdS(NRW(ttraptfailureExceptionRtgetErrorMessageRtFAILURE(tresultstflagRX(R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pytchecks(RRORP(RRQR_((Rs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_singleSynchronousFailurescCs8tjdg}|j|jtjdfg|S(s
        When given a callable that returns a successful Deferred, include the
        result of the Deferred in the results list, tagged with a SUCCESS flag.
        cSs
tjdS(N(RtsucceedRS(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsN(RRORPRRRURS(RRQ((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_singleAsynchronousSuccessscs1tjdg}fd}|j|S(s
        When given a callable that returns a failing Deferred, include the
        failure the results list, tagged with a FAILURE flag.
        cSstjtdS(NRW(RRXt
ValueError(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscsI|\\}}|jtj|jdj|tjdS(NRW(RYRcRR[RR\(R]R^RX(R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR_s
(RRORP(RRQR_((Rs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_singleAsynchronousFailurescsggfdtjfdfdg}|jdgdjd|jddgdjd|S(sf
        Check that the callables are called in the given order, one after the
        other.
        cs*tj}j|j||S(N(RtDeferredtappend(tvalueRQ(t	deferredstlog(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRfs

cs
dS(NRW(((Rf(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscs
dS(Ntbar(((Rf(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRWiRjN(RRORtcallbackRS(RRQ((RiRhRfs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_callablesCalledInOrderscs=tjfddg}fd}|j|S(s
        If one of the callables raises an error, then runSequentially continues
        to run the remaining callables.
        cs
jdS(NRW(RX((R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(NRj((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscsx|\\}}\}}|jjj|tjj|jdj|tjj|ddS(NRWRj(RYRZRRR\R[RU(R]tflag1RXtflag2tresult(R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR_s(RRORP(RRQR_((Rs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_continuesAfterErrors!csCtjfddgdt}fd}|j|S(s
        If the C{stopOnFirstError} option is passed to C{runSequentially}, then
        no further callables are called after the first exception is raised.
        cs
jdS(NRW(RX((R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(NRj((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTststopOnFirstErrorcsL|\\}}|jjj|tjj|jddS(NRW(RYRZRRR\R[(R]RmRX(R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR_s(RROR8RP(RRQR_((Rs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_stopOnFirstErrors	csCtjfddgdt}fd}|j|S(s
        If the C{stripFlags} option is passed to C{runSequentially} then the
        SUCCESS / FAILURE flags are stripped from the output. Instead, the
        Deferred fires a flat list of results containing only the results and
        failures.
        cs
jdS(NRW(RX((R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(NRj((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTst
stripFlagscsF|\}}|jjj|jdj|ddS(NRWRj(RYRZRR[(R]RXRo(R(s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR_s(RROR8RP(RRQR_((Rs@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_stripFlagss	tYAGNI(
RR RMRRRVR`RbRdRlRpRrRtttodo(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRNps	
			
					tDirtyReactorAggregateErrorTestcBs)eZdZdZdZdZRS(s6
    Tests for the L{DirtyReactorAggregateError}.
    cCs,tddg}|jt|ddS(s5
        Delayed calls are formatted nicely.
        tFooRjshReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
Foo
barN(RRtstr(Rterror((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_formatDelayedCallscCs/tgddg}|jt|ddS(s3
        Selectables are formatted nicely.
        sselectable 1sselectable 2s;Reactor was unclean.
Selectables:
selectable 1
selectable 2N(RRRy(RRz((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_formatSelectablesscCs5tddgddg}|jt|ddS(sR
        Both delayed calls and selectables can appear in the same error.
        tblecktBoozotSel1tSel2sReactor was unclean.
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
bleck
Boozo
Selectables:
Sel1
Sel2N(RRRy(RRz((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt%test_formatDelayedCallsAndSelectables s(RR RMR{R|R(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRws	
	
tStubReactorcBs8eZdZddZddZdZdZRS(s~
    A reactor stub which contains enough functionality to be used with the
    L{_Janitor}.

    @ivar iterations: A list of the arguments passed to L{iterate}.
    @ivar removeAllCalled: Number of times that L{removeAll} was called.
    @ivar selectables: The value that will be returned from L{removeAll}.
    @ivar delayedCalls: The value to return from L{getDelayedCalls}.
    cCs7||_g|_d|_|s*g}n||_dS(s
        @param delayedCalls: See L{StubReactor.delayedCalls}.
        @param selectables: See L{StubReactor.selectables}.
        iN(tdelayedCallst
iterationstremoveAllCalledtselectables(RRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt__init__=s				cCs|jj|dS(s/
        Increment C{self.iterations}.
        N(RRf(Rttimeout((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pytiterateJscCs|jS(s.
        Return C{self.delayedCalls}.
        (R(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pytgetDelayedCallsQscCs|jd7_|jS(sS
        Increment C{self.removeAllCalled} and return C{self.selectables}.
        i(RR(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt	removeAllXsN(RR RMRSRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyR2s
	
	tStubErrorReportercBs eZdZdZdZRS(s
    A subset of L{twisted.trial.itrial.IReporter} which records L{addError}
    calls.

    @ivar errors: List of two-tuples of (test, error) which were passed to
        L{addError}.
    cCs
g|_dS(N(terrors(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRjscCs|jj||fdS(s6
        Record parameters in C{self.errors}.
        N(RRf(RttestRz((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pytaddErrorns(RR RMRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRas	tJanitorTestscBsqeZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
RS(s 
    Tests for L{_Janitor}!
    cCsHtg}tddd|}|j|j|jddgdS(s
        During pending-call cleanup, the reactor will be spun twice with an
        instant timeout. This is not a requirement, it is only a test for
        current behavior. Hopefully Trial will eventually not do this kind of
        reactor stuff.
        treactoriN(RRRSt
_cleanPendingRR(RRtjan((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_cleanPendingSpinsReactor{s
cCsud}g}td|di|jd}t|g}tddd|}|j|j||gdS(sW
        During pending-call cleanup, the janitor cancels pending timed calls.
        cSsdS(NtLulz((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pytfuncsi,cSsdS(N(RS(tx((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRN((RRfRRRSRR(RRt	cancelledtdelayedCallRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_cleanPendingCancelsCallss	
c	Cstdddidddd}t|}t|g}tddd|}|j}|j||gdS(	sK
        The Janitor produces string representations of delayed calls from the
        delayed call cleanup method. It gets the string representations
        *before* cancelling the calls; this is important because cancelling the
        call removes critical debugging information from the string
        representation.
        i,cSsdS(N(RS(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(N(RS(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTstsecondscSsdS(Ni((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRN((RRyRRRSRR(RRtdelayedCallStringRRtstrings((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt*test_cleanPendingReturnsDelayedCallStringsscCsBtg}tddd|}|j|j|jddS(sM
        The Janitor will remove selectables during reactor cleanup.
        RiN(RRRSt
_cleanReactorRR(RRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt#test_cleanReactorRemovesSelectabless
cCsjdtfdY}|}tg|g}tddd|}|j|j|jdgdS(sI
        The Janitor will kill processes during reactor cleanup.
        tStubProcessTransportcBs*eZdZeedZdZRS(s
            A stub L{IProcessTransport} provider which records signals.
            @ivar signals: The signals passed to L{signalProcess}.
            cSs
g|_dS(N(tsignals(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRscSs|jj|dS(sF
                Append C{signal} to C{self.signals}.
                N(RRf(Rtsignal((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt
signalProcesss(RR RMRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRs
	RtKILLN(tobjectRRRSRRR(RRtptRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_cleanReactorKillsProcessess	
cCs]dtfdY}tg|g}tddd|}|j|jdgdS(s
        The Janitor returns string representations of the selectables that it
        cleaned up from the reactor cleanup method.
        t
SelectablecBseZdZdZRS(sl
            A stub Selectable which only has an interesting string
            representation.
            cSsdS(Ns
(SELECTABLE!)((R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt__repr__s(RR RMR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRsRs
(SELECTABLE!)N(RRRRSRR(RRRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt)test_cleanReactorReturnsSelectableStringsscCs]tg}t}t}t||d|}|j|j|j|jgdS(s
        The post-case cleanup method will return True and not call C{addError}
        on the result if there are no pending calls.
        RN(RRRRt
assertTruetpostCaseCleanupRR(RRRtreporterR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_postCaseCleanupNoErrorss		c	Cstddd
idddd}t|}t|gg}t}t}t||d|}|j|j|jt	|j
d|j|j
ddjj|gd	S(s
        The post-case cleanup method will return False and call C{addError} on
        the result with a L{DirtyReactorAggregateError} Failure if there are
        pending calls.
        i,cSsdS(N(RS(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(N(RS(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRcSsdS(Ni((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRiiN((
RRyRRRRtassertFalseRRR2RRgR(RRRRRRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_postCaseCleanupWithErrorss		cCsTtg}t}t}t||d|}|j|j|jgdS(s
        The post-class cleanup method will not call C{addError} on the result
        if there are no pending calls or selectables.
        RN(RRRRtpostClassCleanupRR(RRRRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyttest_postClassCleanupNoErrorss		
c	Cstddd
idddd}t|}t|gg}t}t}t||d|}|j|jt|j	d|j|j	ddj
j|gd	S(s
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are pending calls.
        i,cSsdS(N(RS(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTscSsdS(N(RS(R((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRcSsdS(Ni((((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRTsRiiN((RRyRRRRRRR2RRgR(RRRRRRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt*test_postClassCleanupWithPendingCallErrorss		
cCsd}tg|g}t}t}t||d|}|j|jt|jd|j|jddjj	t
|gdS(s
        The post-class cleanup method call C{addError} on the result with a
        L{DirtyReactorAggregateError} Failure if there are selectables.
        sSELECTABLE HERERiiN(RRRRRRR2RRgRtrepr(Rt
selectableRRRR((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt)test_postClassCleanupWithSelectableErrors!s		
(RR RMRRRRRRRRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyRvs	
			
			
		
	(RMRtzope.interfaceRttwisted.internet.interfacesRttwisted.internetRttwisted.internet.baseRttwisted.trial.unittestRt
twisted.trialRttwisted.trial.utilRRttwisted.trial.testRR	R!tSysPathManglingTestR,RNRwRRRR(((s@/usr/lib/python2.7/dist-packages/twisted/trial/test/test_util.pyt<module>s"
81/