o
    Óó·iÃŠ  ã                   @  sŠ  d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ G dd„ deƒZddœd6dd„ZG dd„ deƒZ G dd„ deƒZ!G dd„ de"ƒZ#G dd„ dee#d�Z$G d d!„ d!eƒZ%G d"d#„ d#eƒZ&d7d,d-„Z'G d.d/„ d/eƒZ(G d0d1„ d1eƒZ)G d2d3„ d3eƒZ*G d4d5„ d5eƒZ+dS )8z6
Test cases for the L{twisted.python.failure} module.
é    )ÚannotationsN)Údistb)ÚStringIO©ÚFrameSummary)ÚTracebackType)ÚAnyÚ	GeneratorÚcast)ÚskipIf)Úraiser)ÚfailureÚreflect)ÚSynchronousTestCasec                   @  s   e Zd ZdZd	dd„ZdS )
ÚComparableExceptionz+An exception that can be compared by value.ÚotherÚobjectÚreturnÚboolc                 C  s   | j |j ko| jtt|ƒjkS ©N)Ú	__class__Úargsr
   r   )Úselfr   © r   ú_C:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\twisted/test/test_failure.pyÚ__eq__   s   ÿzComparableException.__eq__N)r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s    r   F©ÚcaptureVarsr!   r   r   úfailure.Failurec                 C  s<   | rd}| zdd  W |S  t y   tj| d�}Y |S w )z6
    Make a C{Failure} of a divide-by-zero error.
    Zxyzé   r   r    N)ÚBaseExceptionr   ÚFailure)r!   ÚexampleLocalVarÚfr   r   r   ÚgetDivisionFailure%   s   
þþr(   c                   @  s”  e Zd ZdZd^dd„Zd^dd„Zd^dd	„Zd^d
d„Zd_dd„Zd`dd„Z	dadd„Z
	dbdcdd„Zdddedd„Zdddedd „Zd^d!d"„Zd^d#d$„Zd^d%d&„Zd^d'd(„Zd^d)d*„Zd^d+d,„Zd^d-d.„Zd^d/d0„Zd^d1d2„Zdfd6d7„Zd^d8d9„Zd^d:d;„Zd^d<d=„Zd^d>d?„Zd^d@dA„Zd^dBdC„Zd^dDdE„Zd^dFdG„Zd^dHdI„Z d^dJdK„Z!d^dLdM„Z"d^dNdO„Z#d^dPdQ„Z$d^dRdS„Z%dgdUdV„Z&d^dWdX„Z'd^dYdZ„Z(d^d[d\„Z)d]S )hÚFailureTestsz'
    Tests for L{failure.Failure}.
    r   ÚNonec                 C  sN   zt dƒ‚ ty   t ¡ }Y nw | tt¡}|  |t¡ |  |jt ¡ dS )z(
        Trapping a L{Failure}.
        ÚtestN)	ÚNotImplementedErrorr$   r   r%   ÚtrapÚ
SystemExitÚRuntimeErrorÚassertEqualÚtype)r   r'   Úerrorr   r   r   Útest_failAndTrap;   s   ÿzFailureTests.test_failAndTrapc                 C  sF   t ƒ }z|‚ ty   t ¡ }Y nw |  t |jt¡}|  ||¡ dS )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}.
        N)Ú
ValueErrorr$   r   r%   ÚassertRaisesr-   ÚOverflowErrorÚassertIs)r   Ú	exceptionr'   Z	untrappedr   r   r   Útest_trapRaisesWrappedExceptionG   s   ÿz,FailureTests.test_trapRaisesWrappedExceptionc                 C  s,   t ƒ }t |¡}t |¡}|  |j|¡ dS )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)r4   r   r%   r7   Úvalue©r   r8   Úf1Úf2r   r   r   Útest_failureValueFromFailureV   s   

z)FailureTests.test_failureValueFromFailurec                 C  sL   t ƒ }t |¡}z| t¡ W n ty   t ¡ }Y nw |  |j|¡ dS )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)r4   r   r%   r-   r6   r$   r7   r:   r;   r   r   r   Ú!test_failureValueFromFoundFailurea   s   
ÿz.FailureTests.test_failureValueFromFoundFailureÚsÚstrÚprefixc                 C  ó    |   | |¡|›d|›�¡ dS )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 is not the start of N)Ú
assertTrueÚ
startswith)r   r@   rB   r   r   r   ÚassertStartsWithq   ó    	zFailureTests.assertStartsWithÚsuffixc                 C  rC   )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 is not the end of N)rD   Úendswith)r   r@   rH   r   r   r   ÚassertEndsWith|   rG   zFailureTests.assertEndsWithÚtbc                 C  s   |   ||¡ |  ||¡ dS )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)rF   rJ   )r   rK   rB   rH   r   r   r   ÚassertTracebackFormat‡   s   z"FailureTests.assertTracebackFormatFr!   r   ÚcleanFailurec           
      C  sÐ   t |d�}tƒ }|r| ¡  | |¡ | ¡ }d|j|jrdp df }d t 	|j
¡t |j¡|j¡}|  |||¡ dd„ | ¡ D ƒ}|rZ|  g |¡ |rPd}	nd	}	|  |	|¡ dS |  g |¡ |  d
|¡ dS )aV  
        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/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}
        r    z*--- Failure #%d%s---
z (pickled) ú z#{}: {}
*--- End of Failure #{} ---
c                 S  s   g | ]	}|  d ¡r|‘qS )z  )rE   )Ú.0Úliner   r   r   Ú
<listcomp>Ò   s    z8FailureTests.assertDetailedTraceback.<locals>.<listcomp>z  exampleLocalVar : "'xyz'"z  exampleLocalVar : 'xyz'zA [Capture of Locals and Globals disabled (use captureVars=True)]
N)r(   r   rM   ZprintDetailedTracebackÚgetvalueÚcountÚpickledÚformatr   Úqualr1   Úsafe_strr:   rL   Ú
splitlinesÚassertNotEqualÚassertInr0   )
r   r!   rM   r'   ÚoutrK   ÚstartÚendZlinesWithVarsrP   r   r   r   ÚassertDetailedTraceback–   s8   
)
þ

ýþz$FailureTests.assertDetailedTracebackc                 C  sœ   |rd}| t ƒ }tƒ }| |¡ | ¡ }d}|jD ]\}}}	}
}||› d|	› d|› d�7 }qttƒ}|  |d|› d�|› ¡ |rL|  t	 
d|¡¡ dS dS )	aœ  
        Assert that L{printBriefTraceback} produces and prints a brief
        traceback.

        The brief traceback consists of a header::

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

        And the footer::

          /twisted/test/test_failure.py:39:getDivisionFailure

        @param captureVars: Enables L{Failure.captureVars}.
        @type captureVars: C{bool}
        ZabcdeÚ ú:Ú
zTraceback: z: zexampleLocalVar.*abcdeN)r(   r   ZprintBriefTracebackrR   ÚframesÚreprÚZeroDivisionErrorrL   ÚassertIsNoneÚreÚsearch)r   r!   r&   r'   r[   rK   ÚstackÚmethodÚfilenameÚlinenoÚ	localVarsÚ
globalVarsZzder   r   r   ÚassertBriefTracebackâ   s&   

ýÿz!FailureTests.assertBriefTracebackc              
   C  sÆ   |rd}| t |d�}tƒ }| |¡ | ¡ }d}|jD ]#\}}}	}
}|d|› d|	› d|› d�7 }|dt ||	¡ ¡ › d�7 }q|  |d	d
|t	 
|j¡t	 |j¡f ¡ |ra|  t d|¡¡ dS 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):

        And the footer::

            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}
        Zxyzzyr    r_   z  File "z", line z, in ra   z    z"Traceback (most recent call last):z	%s%s: %s
zexampleLocalVar.*xyzzyN)r(   r   ZprintTracebackrR   rb   Ú	linecacheÚgetlineÚstriprL   r   rV   r1   rW   r:   re   rf   rg   )r   r!   r&   r'   r[   rK   rh   ri   rj   rk   rl   rm   r   r   r   ÚassertDefaultTraceback
  s0   



ýÿýÿz#FailureTests.assertDefaultTracebackc                 C  ó   |   ¡  dS )zr
        L{printDetailedTraceback} returns a detailed traceback including the
        L{Failure}'s count.
        N©r^   ©r   r   r   r   Útest_printDetailedTraceback8  s   z(FailureTests.test_printDetailedTracebackc                 C  rs   )zC
        L{printBriefTraceback} returns a brief traceback.
        N©rn   ru   r   r   r   Útest_printBriefTraceback?  ó   z%FailureTests.test_printBriefTracebackc                 C  rs   )z8
        L{printTraceback} returns a traceback.
        N©rr   ru   r   r   r   Útest_printTracebackE  ry   z FailureTests.test_printTracebackc                 C  ó   | j dd� dS )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}.
        Tr    Nrt   ru   r   r   r   Ú'test_printDetailedTracebackCapturedVarsK  s   z4FailureTests.test_printDetailedTracebackCapturedVarsc                 C  r|   )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.
        Tr    Nrw   ru   r   r   r   Ú$test_printBriefTracebackCapturedVarsS  ó   z1FailureTests.test_printBriefTracebackCapturedVarsc                 C  r|   )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.
        Tr    Nrz   ru   r   r   r   Útest_printTracebackCapturedVars]  r   z,FailureTests.test_printTracebackCapturedVarsc                 C  s   | j ddd� dS )z’
        C{printDetailedTraceback} includes information about local variables on
        the stack after C{cleanFailure} has been called.
        T)r!   rM   Nrt   ru   r   r   r   Ú.test_printDetailedTracebackCapturedVarsCleanedg  s   z;FailureTests.test_printDetailedTracebackCapturedVarsCleanedc                 C  s   | j ttjdddd� dS )zu
        L{failure.format_frames} raises a L{ValueError} if the supplied
        C{detail} level is unknown.
        NZnoisia©Údetail)r5   r4   r   Zformat_framesru   r   r   r   Útest_invalidFormatFramesDetailn  s   
ÿz+FailureTests.test_invalidFormatFramesDetailc                 C  s,   t ƒ }t |¡}| t ¡ |  |j|¡ d S r   )r/   r   r%   r-   r0   r:   )r   Úer'   r   r   r   Útest_ExplictPassw  s   

zFailureTests.test_ExplictPassr'   r"   ú
str | Nonec                 C  sB   z	|  ¡  W tdƒ‚ ty    t t ¡ d ¡}|d j Y S w )Né   éÿÿÿÿz3f.raiseException() didn't raise ZeroDivisionError!?)ÚraiseExceptionrd   Ú	tracebackÚ
extract_tbÚsysÚexc_inforP   Ú	Exception)r   r'   rK   r   r   r   Ú_getInnermostFrameLine}  s   
üþz#FailureTests._getInnermostFrameLinec                 C  s    t ƒ }|  |¡}|  |d¡ d S )Nú1 / 0)r(   r�   r0   )r   r'   Z	innerliner   r   r   Útest_RaiseExceptionWithTB†  s   
z&FailureTests.test_RaiseExceptionWithTBc                 C  s   |   tjtj¡ dS )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.
        N)r5   r   ZNoCurrentExceptionErrorr%   ru   r   r   r   Útest_ConstructionFails‹  s   z#FailureTests.test_ConstructionFailsc                 C  s   t ƒ }|  | ¡ |j¡ dS )z›
        If the C{Failure} has not been cleaned, then C{getTracebackObject}
        returns the traceback object that captured in its constructor.
        N)r(   r0   ÚgetTracebackObjectrK   ©r   r'   r   r   r   Útest_getTracebackObject“  s   z$FailureTests.test_getTracebackObjectc                 C  sJ   zdd  W n t y   t ¡ }tjdd�}Y nw |  | ¡ |j¡ dS )zc
        C{captureVars=True} has no effect on the result of
        C{getTracebackObject}.
        r#   r   Tr    N)rd   r   r%   r0   r”   rK   )r   ZnoVarsFailureZvarsFailurer   r   r   Ú&test_getTracebackObjectFromCaptureVars›  s   þz3FailureTests.test_getTracebackObjectFromCaptureVarsc                 C  sD   t ƒ }t | ¡ ¡}| ¡  t | ¡ ¡}|  |¡ |  ||¡ dS )z—
        If the Failure has been cleaned, then C{getTracebackObject} returns an
        object that looks the same to L{traceback.extract_tb}.
        N)r(   r‹   rŒ   r”   rM   ÚassertIsNotNoner0   ©r   r'   ÚexpectedZobservedr   r   r   Ú test_getTracebackObjectFromClean§  s   
z-FailureTests.test_getTracebackObjectFromCleanc                 C  s>   t dd�}t | ¡ ¡}| ¡  t | ¡ ¡}|  ||¡ dS )z£
        If the Failure was created with captureVars, then C{getTracebackObject}
        returns an object that looks the same to L{traceback.extract_tb}.
        Tr    N)r(   r‹   rŒ   r”   rM   r0   r™   r   r   r   Ú.test_getTracebackObjectFromCaptureVarsAndClean³  s
   
z;FailureTests.test_getTracebackObjectFromCaptureVarsAndCleanc                 C  s    t  tdƒ¡}|  | ¡ ¡ dS )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)r   r%   r�   re   r”   r•   r   r   r   Ú'test_getTracebackObjectWithoutTraceback¾  s   z4FailureTests.test_getTracebackObjectWithoutTracebackc                 C  sJ   zdd  W n t y   t ¡ \}}}Y nw t |¡}|  |j|¡ dS )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.
        r#   r   N)r$   r�   rŽ   r   r%   r7   rK   )r   Úklassr8   rK   r'   r   r   r   Ú$test_tracebackFromExceptionInPython3É  s   ÿ
z1FailureTests.test_tracebackFromExceptionInPython3c                 C  s>   t ƒ }|  |j¡ |  |jj|j¡ | ¡  |  |jj¡ dS )z†
        L{failure.Failure.cleanFailure} sets the C{__traceback__} attribute of
        the exception to L{None} in Python 3.
        N)r(   r˜   rK   r7   r:   Ú__traceback__rM   re   r•   r   r   r   Ú*test_cleanFailureRemovesTracebackInPython3Ö  s
   z7FailureTests.test_cleanFailureRemovesTracebackInPython3c                 C  s0   t ƒ }tƒ }t| ¡ |d� |  d| ¡ ¡ dS )zâ
        The traceback captured by a L{Failure} is compatible with the stdlib
        L{dis.distb} function as used in post-mortem debuggers. Specifically,
        it doesn't cause that function to raise an exception.
        )Úfilez --> N)r(   r   r   r”   rZ   rR   )r   r'   Úbufr   r   r   Ú
test_distbá  s   zFailureTests.test_distbc                 C  s*   t ƒ }t t¡}|  t|ƒd|f ¡ dS )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)r(   r   ZfullyQualifiedNamerd   r0   rc   )r   r'   ZtypeNamer   r   r   Ú	test_reprî  s   
þzFailureTests.test_reprc                 C  sN   t ƒ }|j|_|  ¡ }|  t|ƒdk¡ |dd… D ]
}|  d|d ¡ qdS )zL
        C{Failure.stack} is gettable and settable, but depreacted.
        r#   éþÿÿÿNzFtwisted.python.failure.Failure.stack was deprecated in Twisted 24.10.0Úmessage)r(   rh   ZflushWarningsrD   Úlenr0   )r   r'   ÚwarningsÚwr   r   r   Útest_stackDeprecationú  s   þÿz"FailureTests.test_stackDeprecationc                 C  sh   t dƒ}t |¡j ¡ }tj |¡}|  |tj¡ |j ¡ }|  | d¡d | d¡¡ |  ||¡ dS )ze
        C{Failure._withoutTraceback(exc)} gives the same result as
        C{Failure(exc)}.
        ÚhellorS   r#   N)	rd   r   r%   Ú__dict__ÚcopyÚ_withoutTracebackÚassertIsInstancer0   Úpop)r   ÚexcZdict1Úfailure2Zdict2r   r   r   Útest_failureWithoutTraceback  s   
z)FailureTests.test_failureWithoutTracebackc                 C  sd   t dƒ}t |¡}|  |¡ tj |¡}|  |¡ zt dƒ‚ ty*   t ¡ }Y nw |  |¡ dS )zm
        C{Failure(exc)} and C{Failure._withoutTraceback(exc)} can be pickled
        and unpickled.
        r¬   ZbooN)r   r   r%   ÚassertPicklingRoundtripsr¯   r$   )r   r²   Zfailure1r³   Zfailure3r   r   r   Útest_failurePickling  s   


ÿz!FailureTests.test_failurePicklingÚoriginal_failurec                 C  sT   t  t  |¡¡}|j ¡ }d|d< d|d< |j ¡ }|  ||¡ |  |j|j¡ dS )z{
        The failure can be pickled and unpickled, and the C{parents} attribute
        is included in the pickle.
        r#   rT   NrK   )ÚpickleÚloadsÚdumpsr­   r®   r0   rb   )r   r·   r³   rš   Úresultr   r   r   rµ   /  s   

z%FailureTests.assertPicklingRoundtripsc                 C  s(   t  tdƒ¡}|  | ¡ d |j¡ dS )z?
        C{Failure.parents} is included in the pickle.
        r¬   ÚparentsN)r   r%   r   r0   Ú__getstate__r¼   r•   r   r   r   Ú#test_failurePicklingIncludesParents<  s   z0FailureTests.test_failurePicklingIncludesParentsc                 C  sX   t  tƒ ¡}|jdd… |_t t |¡¡}|jdd… |_|  |j|jdd… ¡ dS )zO
        C{Failure.frames} can be set, both before and after pickling.
        Nr‰   )r   r%   r(   rb   r¸   r¹   rº   r0   ©r   r·   r³   r   r   r   Útest_settableFramesC  s
   z FailureTests.test_settableFramesc                 C  sB   t  tdƒ¡}|jdd… |_t t |¡¡}|jdd… |_dS )zs
        C{Failure.parents} can be set, both before and after pickling.

        This is used by Foolscap.
        r¬   N)r   r%   r   r¼   r¸   r¹   rº   r¿   r   r   r   Útest_settableParentsM  s   z!FailureTests.test_settableParentsN©r   r*   )r@   rA   rB   rA   r   r*   )r@   rA   rH   rA   r   r*   )rK   rA   rB   rA   rH   rA   r   r*   )FF)r!   r   rM   r   r   r*   )F)r!   r   r   r*   )r'   r"   r   r‡   )r·   r"   r   r*   )*r   r   r   r   r3   r9   r>   r?   rF   rJ   rL   r^   rn   rr   rv   rx   r{   r}   r~   r€   r�   r„   r†   r�   r’   r“   r–   r—   r›   rœ   r�   rŸ   r¡   r¤   r¥   r«   r´   r¶   rµ   r¾   rÀ   rÁ   r   r   r   r   r)   6   sR    






ÿL(
.









	

	
















r)   c                   @  ó   e Zd ZdZddd„ZdS )Ú	BrokenStrzb
    An exception class the instances of which cannot be presented as strings
    via L{str}.
    r   rA   c                 C  s   | ‚r   r   ru   r   r   r   Ú__str___  s   zBrokenStr.__str__N©r   rA   ©r   r   r   r   rÅ   r   r   r   r   rÄ   Y  ó    rÄ   c                   @  rÃ   )ÚBrokenExceptionMetaclassza
    A metaclass for an exception type which cannot be presented as a string via
    L{str}.
    r   rA   c                 C  s   t dƒ‚)Nz#You cannot make a string out of me.)r4   ru   r   r   r   rÅ   j  s   z BrokenExceptionMetaclass.__str__NrÆ   rÇ   r   r   r   r   rÉ   d  rÈ   rÉ   c                   @  s   e Zd ZdZdS )ÚBrokenExceptionTypeza
    The aforementioned exception type which cannot be presented as a string via
    L{str}.
    N)r   r   r   r   r   r   r   r   rÊ   n  s    rÊ   )Ú	metaclassc                   @  s`   e Zd ZdZddd„Zddd	„Zdd
d„Zddd„Zddd„Zddd„Z	ddd„Z
ddd„ZdS )ÚGetTracebackTestsz,
    Tests for L{Failure.getTraceback}.
    rƒ   rA   r   r*   c                 C  s,   t ƒ }t |¡}|j|d�}|  |t¡ dS )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.
        r‚   N)rÄ   r   r%   ÚgetTracebackr°   rA   )r   rƒ   Úxr'   r‹   r   r   r   Ú_brokenValueTest{  s   
z"GetTracebackTests._brokenValueTestc                 C  ó   |   d¡ dS )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Ï   ru   r   r   r   Útest_brokenValueBriefDetail†  s   z-GetTracebackTests.test_brokenValueBriefDetailc                 C  rÐ   )úY
        Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
        ÚdefaultNrÒ   ru   r   r   r   Útest_brokenValueDefaultDetailŽ  ó   z/GetTracebackTests.test_brokenValueDefaultDetailc                 C  rÐ   )rÔ   ÚverboseNrÒ   ru   r   r   r   Útest_brokenValueVerboseDetail”  r×   z/GetTracebackTests.test_brokenValueVerboseDetailc                 C  s(   t  tƒ ¡}|j|d�}|  |t¡ dS )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.
        r‚   N)r   r%   rÊ   rÍ   r°   rA   )r   rƒ   r'   r‹   r   r   r   Ú_brokenTypeTestš  s   z!GetTracebackTests._brokenTypeTestc                 C  rÐ   )aQ  
                A L{Failure} might wrap an
                newPublisher(evt)
        xception 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Ú   ru   r   r   r   Útest_brokenTypeBriefDetail¤  s   	z,GetTracebackTests.test_brokenTypeBriefDetailc                 C  rÐ   )zX
        Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
        rÕ   NrÛ   ru   r   r   r   Útest_brokenTypeDefaultDetail¯  r×   z.GetTracebackTests.test_brokenTypeDefaultDetailc                 C  rÐ   )zX
        Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
        rØ   NrÛ   ru   r   r   r   Útest_brokenTypeVerboseDetailµ  r×   z.GetTracebackTests.test_brokenTypeVerboseDetailN)rƒ   rA   r   r*   rÂ   )r   r   r   r   rÏ   rÓ   rÖ   rÙ   rÚ   rÜ   rÝ   rÞ   r   r   r   r   rÌ   v  s    







rÌ   c                   @  s(   e Zd ZdZeedu dƒddd„ƒZdS )	ÚFindFailureTestszH
    Tests for functionality related to identifying the C{Failure}.
    Nzraiser extension not availabler   r*   c                 C  sL   zt  ¡  W n t jy   t ¡ }|  | t j¡¡ Y dS w |  d¡ dS )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   rŠ   ZRaiserExceptionr   r%   rD   ÚcheckÚfailr•   r   r   r   Ú/test_failureConstructionWithMungedStackSucceedsÁ  s   þz@FindFailureTests.test_failureConstructionWithMungedStackSucceedsrÂ   )r   r   r   r   r   r   râ   r   r   r   r   rß   ¼  s    rß   ÚfnrA   rk   ÚintÚnameÚtextr*   r   c                 C  s   t | ||ƒS r   r   )rã   rk   rå   ræ   r   r   r   Ú_tbÕ  s   rç   c                   @  s$   e Zd ZdZd	dd„Zd	dd„ZdS )
Ú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.
    r   r*   c                 C  s8   t  dddi i gg¡}|  t |¡tddddƒg¡ dS )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.
        ri   úfilename.pyé{   N)r   Ú
_Tracebackr0   r‹   rŒ   rç   ©r   rK   r   r   r   Útest_singleFrameâ  s   ÿz*FormattableTracebackTests.test_singleFramec              	   C  sp   t  dddi i gdddi i gg¡}|  t |¡tddddƒtddddƒg¡ |  t |j¡tddddƒg¡ dS )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.
        Zmethod1ré   rê   Zmethod2éë   N)r   rë   r0   r‹   rŒ   rç   Úextract_stackÚtb_framerì   r   r   r   Útest_manyFramesð  s    þÿþþ	
ÿþz)FormattableTracebackTests.test_manyFramesNrÂ   )r   r   r   r   rí   rñ   r   r   r   r   rè   Ù  s    
rè   c                   @  ó.   e Zd ZdZddd„Zddd„Zddd	„Zd
S )ÚFakeAttributesTestsaR  
    _Frame, _Code and _TracebackFrame objects should possess some basic
    attributes that qualify them as fake python objects, allowing the return of
    _Traceback to be used as a fake traceback. The attributes that have zero or
    empty values are there so that things expecting them find them (e.g. post
    mortem debuggers).
    r   r*   c                 C  s¬   t  dd¡}ddi}ddi}t  ddd||f|¡}|  |j|¡ |  |j|¡ |  |jt j¡ |  |j|¡ |  |j	t
¡ |  |jt¡ |  |jd¡ |  |jtdƒ¡ dS )	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dummyparentZdummyparentfileéo   NNNZ	local_varé*   Z
global_varéd   Ú	dummynameÚdummyfilename)r   Ú_Framer0   Ú	f_globalsÚf_localsr°   Úf_codeÚ_CodeÚf_backÚ
f_builtinsÚdictÚf_lastirä   Úf_linenoÚf_tracer1   )r   Z
back_frameZfake_localsZfake_globalsÚframer   r   r   Útest_fakeFrameAttributes  s.   ø
ûø
z,FakeAttributesTests.test_fakeFrameAttributesc                 C  s   t  dd¡}|  |jd¡ |  |jd¡ |  |jt¡ |  |jt	¡ |  |j
t¡ |  |jt¡ |  |jt¡ |  |jt¡ |  |jt	¡ |  |jt¡ |  |jt¡ |  |jt¡ |  |jt¡ |  |jt¡ |  |jt¡ |  |jt¡ |  | ¡ t¡ dS )úN
        See L{FakeAttributesTests} for more details about this test.
        r÷   rø   N)r   rý   r0   Úco_nameÚco_filenamer°   Úco_argcounträ   Úco_codeÚbytesÚco_cellvarsÚtupleÚ	co_constsÚco_firstlinenoÚco_flagsÚ	co_lnotabÚco_freevarsÚco_posonlyargcountÚco_kwonlyargcountÚco_namesÚ
co_nlocalsÚco_stacksizeÚco_varnamesÚlistZco_positions)r   Úcoder   r   r   Útest_fakeCodeAttributes;  s$   z+FakeAttributesTests.test_fakeCodeAttributesc                 C  s^   t  dddi i fd¡}t  |¡}|  |j|¡ |  |jd¡ |  |jt¡ |  	t
|dƒ¡ dS )r  r÷   rø   rõ   NÚtb_next)r   rù   Z_TracebackFramer0   rð   Ú	tb_linenor°   Útb_lastirä   rD   Úhasattr)r   r  Ztraceback_framer   r   r   Útest_fakeTracebackFrameR  s   þ
z+FakeAttributesTests.test_fakeTracebackFrameNrÂ   )r   r   r   r   r  r  r   r   r   r   r   ró     s
    

%ró   c                   @  rò   )ÚDebugModeTestszF
    Failure's debug mode should allow jumping into the debugger.
    r   r*   c                   sP   t j‰tjj‰ d
‡ ‡fdd„}ˆ |¡ g ˆ_dd‡fdd	„}|t _t ¡  dS )zK
        Override pdb.post_mortem so we can make sure it's called.
        r   r*   c                     s   ˆt _ˆ tj_d S r   )ÚpdbÚpost_mortemr   r%   Ú__init__r   )ÚorigInitr#  r   r   Úrestoren  s   z%DebugModeTests.setUp.<locals>.restoreNÚtúTracebackType | Nonec                   s   ˆ j  | ¡ d S r   )r»   Úappend)r'  ru   r   r   Úlogging_post_mortemv  s   z1DebugModeTests.setUp.<locals>.logging_post_mortemrÂ   r   )r'  r(  r   r*   )r"  r#  r   r%   r$  Z
addCleanupr»   ZstartDebugMode)r   r&  r*  r   )r%  r#  r   r   ÚsetUpf  s   
zDebugModeTests.setUpc                 C  sV   zdd  W n t y   t ¡ \}}}t ¡ }Y nw |  | j|g¡ |  |j¡ dS )z~
        If startDebugMode() is called, calling Failure() will first call
        pdb.post_mortem with the traceback.
        r#   r   N)	r$   r�   rŽ   r   r%   r0   r»   ZassertFalser!   ©r   Útypr²   rK   r'   r   r   r   Útest_regularFailure|  s   þz"DebugModeTests.test_regularFailurec                 C  sZ   zdd  W n t y   t ¡ \}}}tjdd�}Y nw |  | j|g¡ |  |j¡ dS )zk
        If startDebugMode() is called, passing captureVars to Failure() will
        not blow up.
        r#   r   Tr    N)	r$   r�   rŽ   r   r%   r0   r»   rD   r!   r,  r   r   r   Útest_captureVars‰  s   þzDebugModeTests.test_captureVarsNrÂ   )r   r   r   r   r+  r.  r/  r   r   r   r   r!  a  s
    

r!  c                   @  sB   e Zd ZdZddd	„Zdd
d„Zddd„Zddd„Zddd„ZdS )ÚExtendedGeneratorTestszU
    Tests C{failure.Failure} support for generator features added in Python 2.5
    r'   r"   ÚgúGenerator[Any, Any, Any]r   r*   c                 C  s2   z|  |¡ W n
 ty   Y d S w |  d¡ d S )Nz<throwExceptionIntoGenerator should have raised StopIteration)ZthrowExceptionIntoGeneratorÚStopIterationrá   )r   r'   r1  r   r   r   Ú_throwIntoGeneratorœ  s   ÿz*ExtendedGeneratorTests._throwIntoGeneratorc                   s‚   g ‰d‡ ‡fdd„}|ƒ }t ƒ }t|ƒ ˆ  ||¡ ˆ  ˆd d t¡ ˆ  ˆd d t¡ ˆ  t ˆd d ¡d d d	¡ d
S )zr
        It should be possible to throw the exception that a Failure
        represents into a generator.
        r   úGenerator[None, None, None]c                   3  s>   � zd V  W n t y   ˆ t ¡ ¡ Y d S w ˆ  d¡ d S )Nz$Yield should have yielded exception.)r$   r)  r�   rŽ   rá   r   ©r   Ústuffr   r   Ú	generator­  ó   €
ÿzJExtendedGeneratorTests.test_throwExceptionIntoGenerator.<locals>.generatorr   r#   rˆ   r‰   r‘   N©r   r5  )r(   Únextr4  r0   rd   r°   r‹   rŒ   ©r   r8  r1  r'   r   r6  r   Ú test_throwExceptionIntoGenerator¦  s   &z7ExtendedGeneratorTests.test_throwExceptionIntoGeneratorc                   s¤   t ƒ }| ¡  | ¡ }g ‰ d	‡ ‡fdd„}|ƒ }t|ƒ ˆ ||¡ ˆ tˆ ƒd¡ ˆ || ¡ ¡ ˆ ˆ d  ¡ | ¡ ¡ ˆ dˆ d  ¡ ¡ ˆ 	d| ¡ ¡ dS )
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.
        r   r5  c                   3  s>   � zd V  W n t y   ˆ  t ¡ ¡ Y d S w ˆ d¡ d S )NzNo exception sent to generator)r$   r)  r   r%   rá   r   ©ZnewFailuresr   r   r   r8  Ì  r9  zVExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure.<locals>.generatorr#   r   r8  Nr:  )
r(   rM   rÍ   r;  r4  r0   r¨   rY   rZ   ZassertNotIn)r   r'   Zoriginal_failure_strr8  r1  r   r>  r   Ú,test_failureConstructionFindsOriginalFailure¿  s   zCExtendedGeneratorTests.test_failureConstructionFindsOriginalFailurec                   s2   d‡ fdd„}|ƒ }t |ƒ tƒ }ˆ  ||¡ dS )zº
        When a generator reraises a different exception, creating a L{Failure}
        inside the generator should find the reraised exception rather than
        original one.
        r   r5  c                   3  sX   � zzd V  W W d S  t y   g d  Y W d S w  t y+   ˆ  t ¡ jt¡ Y d S w ©Nr#   )r$   r°   r   r%   r:   Ú
IndexErrorr   ru   r   r   r8  ê  s   €ÿÿzJExtendedGeneratorTests.test_ambiguousFailureInGenerator.<locals>.generatorNr:  )r;  r(   r4  r<  r   ru   r   Ú test_ambiguousFailureInGeneratorã  s
   	z7ExtendedGeneratorTests.test_ambiguousFailureInGeneratorc                 C  sX   ddd„}|ƒ }t |ƒ tƒ }z	|  ||¡ W dS  ty+   |  t ¡ jt¡ Y dS w )z¹
        When a generator reraises a different exception, creating a L{Failure}
        above the generator should find the reraised exception rather than
        original one.
        r   r5  c                   s  s,   � zd V  W d S  t y   g d  Y d S w r@  )r$   r   r   r   r   r8  ÿ  s   €ÿzLExtendedGeneratorTests.test_ambiguousFailureFromGenerator.<locals>.generatorNr:  )	r;  r(   r4  r$   r°   r   r%   r:   rA  r<  r   r   r   Ú"test_ambiguousFailureFromGeneratorø  s   
ÿz9ExtendedGeneratorTests.test_ambiguousFailureFromGeneratorN)r'   r"   r1  r2  r   r*   rÂ   )	r   r   r   r   r4  r=  r?  rB  rC  r   r   r   r   r0  —  s    




$r0  )r!   r   r   r"   )
rã   rA   rk   rä   rå   rA   ræ   r*   r   r   ),r   Ú
__future__r   ro   r"  r¸   rf   r�   r‹   Údisr   Úior   r   Útypesr   Útypingr   r	   r
   Zunittestr   Zcython_test_exception_raiserr   Ztwisted.pythonr   r   Ztwisted.trial.unittestr   r�   r   r(   r)   rÄ   r1   rÉ   rÊ   rÌ   rß   rç   rè   ró   r!  r0  r   r   r   r   Ú<module>   sD   	    '
F
4T6