HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_failure.cpython-38.pyc
U

��W[ ~�@svdZddlmZmZddlZddlZddlZddlZddlZddl	m
Z
mZddlm
Z
ddlmZddlmZmZzddlmZWnek
r�dZYnXd	d
�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�dee�ZGdd�de�ZGdd�de�Zejdk�rdd�Z nddlm!Z!dd�Z Gdd�de�Z"Gdd�de�Z#Gd d!�d!e�Z$Gd"d#�d#e�Z%dS)$z6
Test cases for the L{twisted.python.failure} module.
�)�division�absolute_importN)�_PY3�NativeStringIO)�reflect)�failure)�SkipTest�SynchronousTestCase)�raisercOs*zddWntj||�}YnX|S)z�
    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.
    �r)r�Failure)�args�kwargs�f�r�;/usr/lib/python3/dist-packages/twisted/test/test_failure.py�getDivisionFailures
rc@s4eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdFdd�ZdGdd�Z
dHdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"e#e$dAdB�dBk�r(dCe!_%dCe"_%dDdE�Z&dBS)I�FailureTestsz'
    Tests for L{failure.Failure}.
    cCsLztd��Wnt��}YnX|�tt�}|�|t�|�|jt�dS)z(
        Trapping a L{Failure}.
        ZtestN)�NotImplementedErrorrr�trap�
SystemExit�RuntimeError�assertEqual�type)�selfr�errorrrr�test_failAndTrap1szFailureTests.test_failAndTrapcCsPtstd��t�}z|�Wnt��}YnX|�t|jt�}|�||�dS)z�
        If the wrapped C{Exception} is not a subclass of one of the
        expected types, L{failure.Failure.trap} raises the wrapped
        C{Exception}.
        z�
                Only expected behaviour on Python 3.
                @see U{http://twisted.readthedocs.io/en/latest/core/howto/python3.html#twisted-python-failure}
                N�	rr�
ValueErrorrr�assertRaisesr�
OverflowError�assertIs�r�	exceptionrZ	untrappedrrr�test_trapRaisesWrappedException>s�z,FailureTests.test_trapRaisesWrappedExceptioncCsRtrtd��t�}z|�Wnt��}YnX|�tj|jt�}|�||�dS)z�
        If the wrapped C{Exception} is not a subclass of one of the
        expected types, L{failure.Failure.trap} raises itself.
        z�
                Only expected behaviour on Python 2.
                @see U{http://twisted.readthedocs.io/en/latest/core/howto/python3.html#twisted-python-failure}
                Nrr"rrr�test_trapRaisesSelfVs�z FailureTests.test_trapRaisesSelfcCs,t�}t�|�}t�|�}|�|j|�dS)z�
        A L{failure.Failure} constructed from another
        L{failure.Failure} instance, has its C{value} property set to
        the value of that L{failure.Failure} instance.
        N)rrrr!�value�rr#�f1�f2rrr�test_failureValueFromFailurems

z)FailureTests.test_failureValueFromFailurecCsFt�}t�|�}z|�t�Wnt��}YnX|�|j|�dS)z�
        A L{failure.Failure} constructed without a C{exc_value}
        argument, will search for an "original" C{Failure}, and if
        found, its value will be used as the value for the new
        C{Failure}.
        N)rrrrr r!r&r'rrr�!test_failureValueFromFoundFailureys
z.FailureTests.test_failureValueFromFoundFailurecCs|�|�|�d||f�dS)z�
        Assert that C{s} starts with a particular C{prefix}.

        @param s: The input string.
        @type s: C{str}
        @param prefix: The string that C{s} should start with.
        @type prefix: C{str}
        z%r is not the start of %rN)�
assertTrue�
startswith)r�s�prefixrrr�assertStartsWith�s	
�zFailureTests.assertStartsWithcCs|�|�|�d||f�dS)z�
        Assert that C{s} end with a particular C{suffix}.

        @param s: The input string.
        @type s: C{str}
        @param suffix: The string that C{s} should end with.
        @type suffix: C{str}
        z%r is not the end of %rN)r,�endswith)rr.�suffixrrr�assertEndsWith�s	
�zFailureTests.assertEndsWithcCs|�||�|�||�dS)ac
        Assert that the C{tb} traceback contains a particular C{prefix} and
        C{suffix}.

        @param tb: The traceback string.
        @type tb: C{str}
        @param prefix: The string that C{tb} should start with.
        @type prefix: C{str}
        @param suffix: The string that C{tb} should end with.
        @type suffix: C{str}
        N)r0r3)r�tbr/r2rrr�assertTracebackFormat�sz"FailureTests.assertTracebackFormatFcCs�|rd}|t|d�}t�}|r(|��|�|�|��}d|j|jrJdpLdf}dt�|j	�t�
|j�|jf}|�|||�dd�|�
�D�}	|r�|�g|	�|r�d	}
nd
}
|�|
|	�n|�g|	�|�d|�dS)
a�
        Assert that L{printDetailedTraceback} produces and prints a detailed
        traceback.

        The detailed traceback consists of a header::

          *--- Failure #20 ---

        The body contains the stacktrace::

          /twisted/trial/_synctest.py:1180: _run(...)
          /twisted/python/util.py:1076: runWithWarningsSuppressed(...)
          --- <exception caught here> ---
          /twisted/test/test_failure.py:39: getDivisionFailure(...)

        If C{captureVars} is enabled the body also includes a list of
        globals and locals::

           [ Locals ]
             exampleLocalVar : 'xyz'
             ...
           ( Globals )
             ...

        Or when C{captureVars} is disabled::

           [Capture of Locals and Globals disabled (use captureVars=True)]

        When C{cleanFailure} is enabled references to other objects are removed
        and replaced with strings.

        And finally the footer with the L{Failure}'s value::

          exceptions.ZeroDivisionError: float division
          *--- End of Failure #20 ---

        @param captureVars: Enables L{Failure.captureVars}.
        @type captureVars: C{bool}
        @param cleanFailure: Enables L{Failure.cleanFailure}.
        @type cleanFailure: C{bool}
        Zxyz��captureVarsz*--- Failure #%d%s---
z (pickled) � z#%s: %s
*--- End of Failure #%s ---
cSsg|]}|�d�r|�qS)z  )r-)�.0�linerrr�
<listcomp>�s
�z8FailureTests.assertDetailedTraceback.<locals>.<listcomp>z  exampleLocalVar : "'xyz'"z  exampleLocalVar : 'xyz'zA [Capture of Locals and Globals disabled (use captureVars=True)]
N)rr�cleanFailureZprintDetailedTraceback�getvalue�countZpickledr�qualr�safe_strr&r5�
splitlines�assertNotEqual�assertInr)rr7r<�exampleLocalVarr�outr4�start�endZ
linesWithVarsr:rrr�assertDetailedTraceback�s8*

�
��z$FailureTests.assertDetailedTracebackc
Cs�|rd}|t�}t�}|�|�|��}d}|jD] \}}}	}
}|d||	|f7}q4tt�}|�|d|fdtj	|f�|r�|�
t�d|��dS)a`
        Assert that L{printBriefTraceback} produces and prints a brief
        traceback.

        The brief traceback consists of a header::

          Traceback: <type 'exceptions.ZeroDivisionError'>: float division

        The body with the stacktrace::

          /twisted/trial/_synctest.py:1180:_run
          /twisted/python/util.py:1076:runWithWarningsSuppressed

        And the footer::

          --- <exception caught here> ---
          /twisted/test/test_failure.py:39:getDivisionFailure

        @param captureVars: Enables L{Failure.captureVars}.
        @type captureVars: C{bool}
        Zabcde�z	%s:%s:%s
zTraceback: %s: z%s
%szexampleLocalVar.*abcdeN)
rrZprintBriefTracebackr=�frames�repr�ZeroDivisionErrorr5r�EXCEPTION_CAUGHT_HERE�assertIsNone�re�search)
rr7rDrrEr4�stack�method�filename�lineno�	localVars�
globalVarsZzderrr�assertBriefTracebacks"
�z!FailureTests.assertBriefTracebackcCs�|rd}|t|d�}t�}|�|�|��}d}|jD]:\}}}	}
}|d||	|f7}|dt�||	���f7}q8|�|ddt	j
|t�|j
�t�|j�f�|r�|�t�d|��d	S)
a�
        Assert that L{printTraceback} produces and prints a default traceback.

        The default traceback consists of a header::

          Traceback (most recent call last):

        The body with traceback::

          File "/twisted/trial/_synctest.py", line 1180, in _run
             runWithWarningsSuppressed(suppress, method)

        And the footer::

          --- <exception caught here> ---
            File "twisted/test/test_failure.py", line 39, in getDivisionFailure
              1/0
            exceptions.ZeroDivisionError: float division

        @param captureVars: Enables L{Failure.captureVars}.
        @type captureVars: C{bool}
        Zxyzzyr6rIz  File "%s", line %s, in %s
z    %s
z"Traceback (most recent call last):z%s
%s%s: %s
zexampleLocalVar.*xyzzyN)rrZprintTracebackr=rJ�	linecache�getline�stripr5rrMrr?rr@r&rNrOrP)rr7rDrrEr4rQrRrSrTrUrVrrr�assertDefaultTraceback/s2

��

��z#FailureTests.assertDefaultTracebackcCs|��dS)zr
        L{printDetailedTraceback} returns a detailed traceback including the
        L{Failure}'s count.
        N�rH�rrrr�test_printDetailedTraceback`sz(FailureTests.test_printDetailedTracebackcCs|��dS)zC
        L{printBriefTraceback} returns a brief traceback.
        N�rWr]rrr�test_printBriefTracebackhsz%FailureTests.test_printBriefTracebackcCs|��dS)z8
        L{printTraceback} returns a traceback.
        N�r[r]rrr�test_printTracebackosz FailureTests.test_printTracebackcCs|jdd�dS)z�
        L{printDetailedTraceback} captures the locals and globals for its
        stack frames and adds them to the traceback, when called on a
        L{Failure} constructed with C{captureVars=True}.
        Tr6Nr\r]rrr�'test_printDetailedTracebackCapturedVarsvsz4FailureTests.test_printDetailedTracebackCapturedVarscCs|jdd�dS)z�
        L{printBriefTraceback} returns a brief traceback when called on a
        L{Failure} constructed with C{captureVars=True}.

        Local variables on the stack can not be seen in the resulting
        traceback.
        Tr6Nr_r]rrr�$test_printBriefTracebackCapturedVarssz1FailureTests.test_printBriefTracebackCapturedVarscCs|jdd�dS)z�
        L{printTraceback} returns a traceback when called on a L{Failure}
        constructed with C{captureVars=True}.

        Local variables on the stack can not be seen in the resulting
        traceback.
        Tr6Nrar]rrr�test_printTracebackCapturedVars�sz,FailureTests.test_printTracebackCapturedVarscCs|jddd�dS)z�
        C{printDetailedTraceback} includes information about local variables on
        the stack after C{cleanFailure} has been called.
        T)r7r<Nr\r]rrr�.test_printDetailedTracebackCapturedVarsCleaned�sz;FailureTests.test_printDetailedTracebackCapturedVarsCleanedcCs|jttjdddd�dS)zu
        L{failure.format_frames} raises a L{ValueError} if the supplied
        C{detail} level is unknown.
        NZnoisia��detail)rrrZ
format_framesr]rrr�test_invalidFormatFramesDetail�s�z+FailureTests.test_invalidFormatFramesDetailcCs,t�}t�|�}|�t�|�|j|�dS�N)rrrrrr&)r�errrr�test_ExplictPass�s

zFailureTests.test_ExplictPasscCsLz|��Wn2tk
r>t�t��d�}|ddYSXtd��dS)N����z3f.raiseException() didn't raise ZeroDivisionError!?)�raiseExceptionrL�	traceback�
extract_tb�sys�exc_info�	Exception)rrr4rrr�_getInnermostFrameLine�s�z#FailureTests._getInnermostFrameLinecCs t�}|�|�}|�|d�dS)N�1/0)rrur)rrZ	innerlinerrr�test_RaiseExceptionWithTB�s
z&FailureTests.test_RaiseExceptionWithTBcCs$|�ttjd�}|�dt|��dS)z�
        Constructing a C{Failure} with a string as its exception value raises
        a C{TypeError}, as this is no longer supported as of Python 2.6.
        zono!z$Strings are not supported by FailureN)r�	TypeErrorrrrC�str)r�excrrr� test_stringExceptionConstruction�sz-FailureTests.test_stringExceptionConstructioncCs&tjdkrt��|�tjtj�dS)z�
        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.
        ��rN)rr�version_info�	exc_clearrrZNoCurrentExceptionErrorrr]rrr�test_ConstructionFails�s
z#FailureTests.test_ConstructionFailscCst�}|�|��|j�dS)z�
        If the C{Failure} has not been cleaned, then C{getTracebackObject}
        returns the traceback object that captured in its constructor.
        N)rr�getTracebackObjectr4�rrrrr�test_getTracebackObject�sz$FailureTests.test_getTracebackObjectcCsLzddWn(tk
r4t��}tjdd�}YnX|�|��|j�dS)zc
        C{captureVars=True} has no effect on the result of
        C{getTracebackObject}.
        rrTr6N)rLrrrr�r4)rZ
noVarsFailureZvarsFailurerrr�&test_getTracebackObjectFromCaptureVars�sz3FailureTests.test_getTracebackObjectFromCaptureVarscCsDt�}t�|���}|��t�|���}|�|�|�||�dS)z�
        If the Failure has been cleaned, then C{getTracebackObject} returns an
        object that looks the same to L{traceback.extract_tb}.
        N)rrprqr�r<�assertIsNotNoner�rrZexpectedZobservedrrr� test_getTracebackObjectFromClean�s
z-FailureTests.test_getTracebackObjectFromCleancCs>tdd�}t�|���}|��t�|���}|�||�dS)z�
        If the Failure was created with captureVars, then C{getTracebackObject}
        returns an object that looks the same to L{traceback.extract_tb}.
        Tr6N)rrprqr�r<rr�rrr�.test_getTracebackObjectFromCaptureVarsAndClean�s

z;FailureTests.test_getTracebackObjectFromCaptureVarsAndCleancCs t�td��}|�|���dS)a
        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) -> [].
        z
some errorN)rrrtrNr�r�rrr�'test_getTracebackObjectWithoutTracebacksz4FailureTests.test_getTracebackObjectWithoutTracebackcCsDzddWnt��\}}}YnXt�|�}|�|j|�dS)z�
        If a L{failure.Failure} is constructed with an exception but no
        traceback in Python 3, the traceback will be extracted from the
        exception's C{__traceback__} attribute.
        rrN)rrrsrrr!r4)r�klassr#r4rrrr�$test_tracebackFromExceptionInPython3
s
z1FailureTests.test_tracebackFromExceptionInPython3cCs>t�}|�|j�|�|jj|j�|��|�|jj�dS)z�
        L{failure.Failure.cleanFailure} sets the C{__traceback__} attribute of
        the exception to L{None} in Python 3.
        N)rr�r4r!r&�
__traceback__r<rNr�rrr�*test_cleanFailureRemovesTracebackInPython3s
z7FailureTests.test_cleanFailureRemovesTracebackInPython3r�NzPython 3 only.cCs*t�}t�t�}|�t|�d|f�dS)z�
        The C{repr} of a L{failure.Failure} shows the type and string
        representation of the underlying exception.
        z5<twisted.python.failure.Failure %s: division by zero>N)rrZfullyQualifiedNamerLrrK)rrZtypeNamerrr�	test_repr+s
��zFailureTests.test_repr)FF)F)F)'�__name__�
__module__�__qualname__�__doc__rr$r%r*r+r0r3r5rHrWr[r^r`rbrcrdrerfrirlrurwr{r�r�r�r�r�r�r�r��getattr�
BaseException�skipr�rrrrr,sH



N
-
1				

rc@seZdZdZdd�ZdS)�	BrokenStrzb
    An exception class the instances of which cannot be presented as strings via
    C{str}.
    cCs|�dSrjrr]rrr�__str__>szBrokenStr.__str__N�r�r�r�r�r�rrrrr�9sr�c@seZdZdZdd�ZdS)�BrokenExceptionMetaclassza
    A metaclass for an exception type which cannot be presented as a string via
    C{str}.
    cCstd��dS)Nz#You cannot make a string out of me.)rr]rrrr�Isz BrokenExceptionMetaclass.__str__Nr�rrrrr�Dsr�c@seZdZdZeZdS)�BrokenExceptionTypeza
    The aforementioned exception type which cnanot be presented as a string via
    C{str}.
    N)r�r�r�r�r�Z
__metaclass__rrrrr�Nsr�c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�GetTracebackTestsz,
    Tests for L{Failure.getTraceback}.
    cCs,t�}t�|�}|j|d�}|�|t�dS)z�
        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.
        rgN)r�rr�getTraceback�assertIsInstancery)rrh�xrrprrr�_brokenValueTest[s
z"GetTracebackTests._brokenValueTestcCs|�d�dS)z�
        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.
        �briefN�r�r]rrr�test_brokenValueBriefDetailgsz-GetTracebackTests.test_brokenValueBriefDetailcCs|�d�dS)�Y
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        �defaultNr�r]rrr�test_brokenValueDefaultDetailpsz/GetTracebackTests.test_brokenValueDefaultDetailcCs|�d�dS)r��verboseNr�r]rrr�test_brokenValueVerboseDetailwsz/GetTracebackTests.test_brokenValueVerboseDetailcCs(t�t��}|j|d�}|�|t�dS)z�
        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.
        rgN)rrr�r�r�ry)rrhrrprrr�_brokenTypeTest~sz!GetTracebackTests._brokenTypeTestcCs|�d�dS)a
        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.
        r�N�r�r]rrr�test_brokenTypeBriefDetail�sz,GetTracebackTests.test_brokenTypeBriefDetailcCs|�d�dS)zX
        Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
        r�Nr�r]rrr�test_brokenTypeDefaultDetail�sz.GetTracebackTests.test_brokenTypeDefaultDetailcCs|�d�dS)zX
        Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
        r�Nr�r]rrr�test_brokenTypeVerboseDetail�sz.GetTracebackTests.test_brokenTypeVerboseDetailN)r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�Ws	
r�c@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Ze	dkrFd
Z
e
e_dS)�FindFailureTestszE
    Tests for functionality related to L{Failure._findFailure}.
    cCs8zddWn|�tj���YnX|�d�dS)z�
        Within an exception handler, _findFailure should return
        L{None} in case no Failure is associated with the current
        exception.
        rrzNo exception raised from 1/0!?N)rNrr�_findFailure�failr]rrr�$test_findNoFailureInExceptionHandler�s
z5FindFailureTests.test_findNoFailureInExceptionHandlercCs8tjdkrt��|�t��d�|�tj���dS)zS
        Outside of an exception handler, _findFailure should return None.
        r|rnN)rrr~rrNrsrrr�r]rrr�test_findNoFailure�s
z#FindFailureTests.test_findNoFailurecCsHt�}|��z|��Wn|�tj��|�YnX|�d�dS)z�
        Within an exception handler, it should be possible to find the
        original Failure that caused the current exception (if it was
        caused by raiseException).
        �)No exception raised from raiseException!?N)rr<rorrrr�r�r�rrr�test_findFailure�sz!FindFailureTests.test_findFailurec	Cs~t�}|��z|��WnTt��}|����}|����}|�||�|�|dd�|dd��YnX|�	d�dS)ax
        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.
        Means the new failure should still show the same origin frame,
        but with different complete stack trace (as not thrown at same place).
        ���Nr�)
rr<rorrr�rArBrr�)rrZnewFr4Znew_tbrrr�,test_failureConstructionFindsOriginalFailure�s	"z=FindFailureTests.test_failureConstructionFindsOriginalFailurecCsLzt��Wn0tjk
r<t��}|�|�tj��YnX|�d�dS)z�
        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.
        z$No exception raised from extension?!N)r
roZRaiserExceptionrrr,Zcheckr�r�rrr�/test_failureConstructionWithMungedStackSucceeds�sz@FindFailureTests.test_failureConstructionWithMungedStackSucceedsNzraiser extension not available)r�r�r�r�r�r�r�r�r�r
ZskipMsgr�rrrrr��s
r�)r}�cCs||||fSrjr��fnrT�name�textrrr�<lambda>�r���FrameSummarycCst|||�Srjr�r�rrrr�r�c@s eZdZdZdd�Zdd�ZdS)�FormattableTracebackTestsa
    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.
    cCs8t�dddiigg�}|�t�|�tdddd�g�dS)z�
        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.
        rR�filename.py�{N�rZ
_Tracebackrrprq�_tb�rr4rrr�test_singleFrames�z*FormattableTracebackTests.test_singleFramec	CsPt�dddiigdddiigg�}|�t�|�tdddd�tdddd�g�dS)z�
        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.
        Zmethod1r�r�Zmethod2��Nr�r�rrr�test_manyFramess���z)FormattableTracebackTests.test_manyFramesN)r�r�r�r�r�r�rrrrr�sr�c@seZdZdZdd�ZdS)�FrameAttributesTestszq
    _Frame objects should possess some basic attributes that qualify them as
    fake python Frame objects.
    cCs<t�dd�}|�|jt�|�|jt�|�|jtj�dS)z�
        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.
        Z	dummynameZ
dummyfilenameN)rZ_Framer��	f_globals�dict�f_locals�f_codeZ_Code)r�framerrr�test_fakeFrameAttributes3sz-FrameAttributesTests.test_fakeFrameAttributesN)r�r�r�r�r�rrrrr�-sr�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�DebugModeTestszF
    Failure's debug mode should allow jumping into the debugger.
    csBtj�tjj���fdd�}|�|�g|_|jjt_t��dS)zK
        Override pdb.post_mortem so we can make sure it's called.
        cs�t_�tj_dSrj)�pdb�post_mortemrr�__init__r�ZorigInitr�rr�restoreLsz%DebugModeTests.setUp.<locals>.restoreN)	r�r�rrr�Z
addCleanup�result�appendZstartDebugMode)rr�rr�r�setUpEs

zDebugModeTests.setUpcCsPzddWn"t��\}}}t��}YnX|�|j|g�|�|j�dS)z~
        If startDebugMode() is called, calling Failure() will first call
        pdb.post_mortem with the traceback.
        rrN)rrrsrrrr�ZassertFalser7�r�typrzr4rrrr�test_regularFailureVsz"DebugModeTests.test_regularFailurecCsTzddWn&t��\}}}tjdd�}YnX|�|j|g�|�|j�dS)zk
        If startDebugMode() is called, passing captureVars to Failure() will
        not blow up.
        rrTr6N)rrrsrrrr�r,r7r�rrr�test_captureVarsdszDebugModeTests.test_captureVarsN)r�r�r�r�r�r�r�rrrrr�@sr�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ExtendedGeneratorTestszU
    Tests C{failure.Failure} support for generator features added in Python 2.5
    cCs2z|�|�Wntk
r"YnX|�d�dS)Nz<throwExceptionIntoGenerator should have raised StopIteration)ZthrowExceptionIntoGenerator�
StopIterationr�)rr�grrr�_throwIntoGeneratorxs
z*ExtendedGeneratorTests._throwIntoGeneratorcs�g���fdd�}|�}t�}t|���||����ddt����ddt���t��dd�ddd�dS)	zr
        It should be possible to throw the exception that a Failure
        represents into a generator.
        c3s4z
dVWn��t���YnX��d�dS)Nz$Yield should have yielded exception.)r�rrrsr�r�rZstuffrr�	generator�s

zJExtendedGeneratorTests.test_throwExceptionIntoGenerator.<locals>.generatorrrrmrnrvN)r�nextr�rrLr�rprq�rr�r�rrr�r� test_throwExceptionIntoGenerator�sz7ExtendedGeneratorTests.test_throwExceptionIntoGeneratorcsLt�}|��g���fdd�}|�}t|���||����|g�dS)z�
        Within an exception handler, it should be possible to find the
        original Failure that caused the current exception (if it was
        caused by throwExceptionIntoGenerator).
        c3s6z
dVWn��tj���YnX��d�dS�NzNo exception sent to generator)r�rrr�r�r�Z
foundFailuresrrrr��s

zEExtendedGeneratorTests.test_findFailureInGenerator.<locals>.generatorN)rr<r�r�r)rrr�r�rr�r�test_findFailureInGenerator�sz2ExtendedGeneratorTests.test_findFailureInGeneratorcs�t�}|��|��}g���fdd�}|�}t|���||���t��d���||������d��|�����d�d�����	d|���dS)z�
        When a Failure is constructed in the context of an exception
        handler that is handling an exception raised by
        throwExceptionIntoGenerator, the new Failure should be chained to that
        original Failure.
        c3s4z
dVWn��t���YnX��d�dSr�)r�rrr�r�ZnewFailuresrrrr��s

zVExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure.<locals>.generatorrrr�N)
rr<r�r�r�r�lenrBrCZassertNotIn)rrZoriginal_failure_strr�r�rr�rr��szCExtendedGeneratorTests.test_failureConstructionFindsOriginalFailurecs0�fdd�}|�}t|�t�}��||�dS)z�
        When a generator reraises a different exception,
        L{Failure._findFailure} inside the generator should find the reraised
        exception rather than original one.
        c3sHz$z
dVWngdYnXWn��t��jt�YnXdS�Nr)r�rrr&�
IndexErrorrr]rrr��s
zJExtendedGeneratorTests.test_ambiguousFailureInGenerator.<locals>.generatorN)r�rr�r�rr]r� test_ambiguousFailureInGenerator�s
z7ExtendedGeneratorTests.test_ambiguousFailureInGeneratorcCsPdd�}|�}t|�t�}z|�||�Wn|�t��jt�YnXdS)z�
        When a generator reraises a different exception,
        L{Failure._findFailure} above the generator should find the reraised
        exception rather than original one.
        css$z
dVWngdYnXdSr�rrrrrr��s
zLExtendedGeneratorTests.test_ambiguousFailureFromGenerator.<locals>.generatorN)r�rr�r�rrr&r�r�rrr�"test_ambiguousFailureFromGenerator�sz9ExtendedGeneratorTests.test_ambiguousFailureFromGeneratorN)
r�r�r�r�r�r�r�r�r�r�rrrrr�ss	#r�)&r�Z
__future__rrrOrrrpr�rXZtwisted.python.compatrrZtwisted.pythonrrZtwisted.trial.unittestrr	Ztwisted.testr
�ImportErrorrrrtr�rr��objectr�r�r�r~r�r�r�r�r�r�rrrr�<module>sB

	K]
&3