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_failure.pyc


=Nc@sdZddlZddlZddlZddlZddlZddlmZmZddl	m
Z
yddlmZWne
k
reZnXdZdejfdYZd	efd
YZdefdYZd
eefdYZdejfdYZdejfdYZdejfdYZdejfdYZdejfdYZejd ddfkrddlmZndS(s 
Test cases for failure module.
iN(tunittesttutil(tfailure(traisercOs,yddWntj||}nX|S(s
    Make a C{Failure} of a divide-by-zero error.

    @param args: Any C{*args} are passed to Failure's constructor.
    @param kwargs: Any C{**kwargs} are passed to Failure's constructor.
    ii(RtFailure(targstkwargstf((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pytgetDivisionFailures
tFailureTestCasecBs2eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZ
de
_d
ZdZdZejddge_dZejddge_ejd dkrdZee_ee_ndZdZdZdZdZdZRS(cCs_ytdWntj}nX|jtt}|j|t|j|jtdS(sTrapping a failure.ttestN(tNotImplementedErrorRRttrapt
SystemExittRuntimeErrortassertEqualttype(tselfRterror((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttestFailAndTrap(scCs@y
tWntj}nX|jtj|jtdS(s0Making sure trap doesn't trap what it shouldn't.N(t
ValueErrorRRtassertRaisesRt
OverflowError(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_notTrapped3s

cCs'|j|j|d||fdS(s@
        Assert that s starts with a particular prefix.
        s%r is not the start of %rN(t
assertTruet
startswith(Rtstprefix((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pytassertStartsWith<scCst}tj}|j||j|jdtj}|j||j|jdtj}|j||j|jddS(s>
        None of the print* methods fail when called.
        s*--- Failuret	TracebackN(RtStringIOtprintDetailedTracebackRtgetvaluetprintBriefTracebacktprintTraceback(RRtout((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_printingSmokeTestDs	


cCsd}tdt}tj}|j||j|jd|jdtj	d|jtj}|j
||j|jdtj}|j||j|jddS(s
        None of the print* methods fail when called on a L{Failure} constructed
        with C{captureVars=True}.

        Local variables on the stack can be seen in the detailed traceback.
        txyzzytcaptureVarss*--- FailuresexampleLocalVar.*xyzzyRN(RtTrueRRRR tassertNotEqualtNonetretsearchR!R"(RtexampleLocalVarRR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt"test_printingCapturedVarsSmokeTestTs


cCs^d}tdt}|jtj}|j||jdtjd|j	dS(s
        C{printDetailedTraceback} includes information about local variables on
        the stack after C{cleanFailure} has been called.
        R%R&sexampleLocalVar.*xyzzyN(
RR'tcleanFailureRRR(R)R*R+R (RR,RR#((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt)test_printingCapturedVarsCleanedSmokeTestjs

cCstj}t}|j|g|jjD]}|jdr5|^q5}|jg||jd|jdS(s
        Calling C{Failure()} with no arguments does not capture any locals or
        globals, so L{printDetailedTraceback} cannot show them in its output.
        s  s&Capture of Locals and Globals disabledN(RRRR t
splitlinesRRtassertSubstring(RR#Rtlinet
linesWithVars((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_printingNoVarsxs	
cCsptj}tdt}|j|g|jjD]}|jdr;|^q;}|jg|dS(s
        Calling C{Failure(captureVars=True)} captures the locals and globals
        for its stack frames, so L{printDetailedTraceback} will show them in
        its output.
        R&s  N(RRR'RR R0RR((RR#RR2R3((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_printingCaptureVarss
cCs<t}tj|}|jt|j|j|dS(N(RRRRRtvalue(RteR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttestExplictPasss	
cCsTy|jWn3tk
rCtjtjd}|ddSXtddS(Niis3f.raiseException() didn't raise ZeroDivisionError!?(traiseExceptiontZeroDivisionErrort	tracebackt
extract_tbtsystexc_infot	Exception(RRttb((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt_getInnermostFrameLines

cCs,t}|j|}|j|ddS(Ns1/0(RRAR(RRt	innerline((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttestRaiseExceptionWithTBs	cCs6t}|j|j|}|j|ddS(Ns1/0(RR.RAR(RRRB((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttestLackOfTBs	
sQthe traceback is not preserved, exarkun said he'll try to fix this! god knows hows
bugger offcCs'y
|jWntj}nX|S(N(t_stringExceptionRR(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt_getStringFailures

cCsQ|j}y|jWn$|jtjd|jn
XtddS(NisShould have raised(RFR9RR=R>REtAssertionError(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_raiseStringExceptionss!tmessages(raising a string exception is deprecatedcCsU|j}tj}|jd||jj}|j|d|jdS(s
        L{Failure.printTraceback} should write out stack and exception
        information, even for string exceptions.
        tfileiN(RFRR"R R0RRE(RRtoutputtlines((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_printStringExceptionss
iis>String exceptions aren't supported anymore starting Python 2.6cCs|jtjtjdS(s
        Creating a Failure with no arguments causes it to try to discover the
        current interpreter exception state.  If no such state exists, creating
        the Failure should raise a synchronous exception.
        N(RRtNoCurrentExceptionErrorR(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttestConstructionFailsscCs&t}|j|j|jdS(s
        If the C{Failure} has not been cleaned, then C{getTracebackObject}
        returns the traceback object that captured in its constructor.
        N(RRtgetTracebackObjectR@(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_getTracebackObjects	cCs[yddWn/tk
r=tj}tjdt}nX|j|j|jdS(sc
        C{captureVars=True} has no effect on the result of
        C{getTracebackObject}.
        iiR&N(R:RRR'RRPR@(Rt
noVarsFailuretvarsFailure((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt&test_getTracebackObjectFromCaptureVarss
cCsat}tj|j}|jtj|j}|jd||j||dS(s
        If the Failure has been cleaned, then C{getTracebackObject} returns an
        object that looks the same to L{traceback.extract_tb}.
        N(RR;R<RPR.R(R)R(RRtexpectedtobserved((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt test_getTracebackObjectFromCleans	
cCsWtdt}tj|j}|jtj|j}|j||dS(s
        If the Failure was created with captureVars, then C{getTracebackObject}
        returns an object that looks the same to L{traceback.extract_tb}.
        R&N(RR'R;R<RPR.R(RRRURV((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt.test_getTracebackObjectFromCaptureVarsAndCleans

cCs/tjtd}|j|jddS(s
        L{failure.Failure}s need not be constructed with traceback objects. If
        a C{Failure} has no traceback information at all, C{getTracebackObject}
        just returns None.

        None is a good value, because traceback.extract_tb(None) -> [].
        s
some errorN(RRR?RRPR)(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt'test_getTracebackObjectWithoutTracebacks(ii(t__name__t
__module__RRRR$R-R/R4R5R8RARCRDttodoRERFRHRtsuppressRMR=tversion_infotskipMsgtskipRORQRTRWRXRY(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyR	&s:																
	
						
	
	t	BrokenStrcBseZdZdZRS(sb
    An exception class the instances of which cannot be presented as strings via
    C{str}.
    cCs
|dS(N((R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt__str__/s(RZR[t__doc__Rb(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRa*stBrokenExceptionMetaclasscBseZdZdZRS(sa
    A metaclass for an exception type which cannot be presented as a string via
    C{str}.
    cCstddS(Ns#You cannot make a string out of me.(R(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRb:s(RZR[RcRb(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRd5stBrokenExceptionTypecBseZdZeZRS(sa
    The aforementioned exception type which cnanot be presented as a string via
    C{str}.
    (RZR[RcRdt
__metaclass__(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRe?stGetTracebackTestscBsVeZdZdZdZdZdZdZdZdZ	dZ
RS(	s,
    Tests for L{Failure.getTraceback}.
    cCs>t}tj|}|jd|}|j|tdS(s
        Construct a L{Failure} with an exception that raises an exception from
        its C{__str__} method and then call C{getTraceback} with the specified
        detail and verify that it returns a string.
        tdetailN(RaRRtgetTracebacktassertIsInstancetstr(RRhtxRR;((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt_brokenValueTestLs	cCs|jddS(s
        A L{Failure} might wrap an exception with a C{__str__} method which
        raises an exception.  In this case, calling C{getTraceback} on the
        failure with the C{"brief"} detail does not raise an exception.
        tbriefN(Rm(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenValueBriefDetailXscCs|jddS(sY
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        tdefaultN(Rm(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenValueDefaultDetailascCs|jddS(sY
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        tverboseN(Rm(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenValueVerboseDetailhscCs8tjt}|jd|}|j|tdS(s
        Construct a L{Failure} with an exception type that raises an exception
        from its C{__str__} method and then call C{getTraceback} with the
        specified detail and verify that it returns a string.
        RhN(RRReRiRjRk(RRhRR;((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt_brokenTypeTestoscCs|jddS(s
        A L{Failure} might wrap an exception the type object of which has a
        C{__str__} method which raises an exception.  In this case, calling
        C{getTraceback} on the failure with the C{"brief"} detail does not raise
        an exception.
        RnN(Rt(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenTypeBriefDetailzscCs|jddS(sX
        Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
        RpN(Rt(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenTypeDefaultDetailscCs|jddS(sX
        Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
        RrN(Rt(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_brokenTypeVerboseDetails(RZR[RcRmRoRqRsRtRuRvRw(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRgHs							
	tFindFailureTestscBsYeZdZdZdZdZdZdZedkrWdZ
e
e_nRS(sE
    Tests for functionality related to L{Failure._findFailure}.
    cCs@yddWn |jtjjdnX|jddS(s
        Within an exception handler, _findFailure should return
        C{None} in case no Failure is associated with the current
        exception.
        iisNo exception raised from 1/0!?N(RRRt_findFailureR)tfail(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt$test_findNoFailureInExceptionHandlers
cCs7|jtjdd|jtjjddS(sS
        Outside of an exception handler, _findFailure should return None.
        iN(RR=R>R)RRRy(R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_findNoFailurescCsUt}|jy|jWn |jtjj|nX|jddS(s
        Within an exception handler, it should be possible to find the
        original Failure that caused the current exception (if it was
        caused by raiseException).
        s)No exception raised from raiseException!?N(RR.R9RRRRyRz(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_findFailures	
cCsdt}|jy|jWn/tj}|j|j|jnX|jddS(s
        When a Failure is constructed in the context of an exception
        handler that is handling an exception raised by
        raiseException, the new Failure should be chained to that
        original Failure.
        s)No exception raised from raiseException!?N(RR.R9RRRRiRz(RRtnewF((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt,test_failureConstructionFindsOriginalFailures	
 cCs[ytjWn9tjk
rItj}|j|jtjnX|jddS(s
        Pyrex and Cython are known to insert fake stack frames so as to give
        more Python-like tracebacks. These stack frames with empty code objects
        should not break extraction of the exception.
        s$No exception raised from extension?!N(RR9tRaiserExceptionRRRtcheckRz(RR((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt/test_failureConstructionWithMungedStackSucceedsssraiser extension not availableN(RZR[RcR{R|R}RRRR)R_R`(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRxs					tTestFormattableTracebackcBs eZdZdZdZRS(s
    Whitebox tests that show that L{failure._Traceback} constructs objects that
    can be used by L{traceback.extract_tb}.

    If the objects can be used by L{traceback.extract_tb}, then they can be
    formatted using L{traceback.format_tb} and friends.
    cCsAtjdddiigg}|jtj|dgdS(s
        A C{_Traceback} object constructed with a single frame should be able
        to be passed to L{traceback.extract_tb}, and we should get a singleton
        list containing a (filename, lineno, methodname, line) tuple.
        tmethodsfilename.pyi{N(sfilename.pyi{smethodN(Rt
_TracebackRR;R<R)(RR@((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_singleFrames!cCsVtjdddiigdddiigg}|jtj|ddgdS(	s
        A C{_Traceback} object constructed with multiple frames should be able
        to be passed to L{traceback.extract_tb}, and we should get a list
        containing a tuple for each frame.
        tmethod1sfilename.pyi{tmethod2iN(sfilename.pyi{RN(sfilename.pyiRN(RRRR;R<R)(RR@((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_manyFramess(RZR[RcRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRs	tTestFrameAttributescBseZdZdZRS(sq
    _Frame objects should possess some basic attributes that qualify them as
    fake python Frame objects.
    cCsRtjdd}|j|jt|j|jt|j|jtjdS(s
        L{_Frame} instances have the C{f_globals} and C{f_locals} attributes
        bound to C{dict} instance.  They also have the C{f_code} attribute
        bound to something like a code object.
        t	dummynamet
dummyfilenameN(Rt_FrameRjt	f_globalstdicttf_localstf_codet_Code(Rtframe((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_fakeFrameAttributess(RZR[RcR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRst
TestDebugModecBs)eZdZdZdZdZRS(sF
    Failure's debug mode should allow jumping into the debugger.
    cs^tjtjjdfd}|j|g|_|jjt_tjdS(sK
        Override pdb.post_mortem so we can make sure it's called.
        t__init__cst_tjjd<dS(NR(tpdbtpost_mortemRRt__dict__((RtorigInit(s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pytrestore*s	N(	RRRRRt
addCleanuptresulttappendtstartDebugMode(RR((RRs=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pytsetUp#s	
	cCsdyddWn(tj\}}}tj}nX|j|j|g|j|jtdS(s~
        If startDebugMode() is called, calling Failure() will first call
        pdb.post_mortem with the traceback.
        iiN(R=R>RRRRR&tFalse(RttyptexcR@R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_regularFailure4scCsjyddWn.tj\}}}tjdt}nX|j|j|g|j|jtdS(sk
        If startDebugMode() is called, passing captureVars to Failure() will
        not blow up.
        iiR&N(R=R>RRR'RRR&(RRRR@R((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyttest_captureVarsBs(RZR[RcRRR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyRs		ii(tTwoPointFiveFailureTests( RcR*R=RR;Rt
twisted.trialRRttwisted.pythonRttwisted.testRtImportErrorR)RtTestCaseR	R?RaRRdtobjectReRgRxRRRR^t$twisted.test.generator_failure_testsR(((s=/usr/lib/python2.7/dist-packages/twisted/test/test_failure.pyt<module>s0

	
	KR&3