
    hÊ                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SSKJrJrJr  SS	KJr  SS
KJr  SSKJrJr  SSKJr   " S S\5      rSS.S(S jjr " S S\5      r  " S S\5      r! " S S\"5      r# " S S\\#S9r$ " S S\5      r% " S S\5      r&S)S jr' " S  S!\5      r( " S" S#\5      r) " S$ S%\5      r* " S& S'\5      r+g)*z6
Test cases for the L{twisted.python.failure} module.
    )annotationsN)distb)StringIOFrameSummary)TracebackType)Any	Generatorcast)skipIf)raiser)failurereflect)SynchronousTestCasec                  "    \ rS rSrSrSS jrSrg)ComparableException   z+An exception that can be compared by value.c                    U R                   UR                   :H  =(       a'    U R                  [        [        U5      R                  :H  $ N)	__class__argsr   r   )selfothers     `/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_failure.py__eq__ComparableException.__eq__   s6    %//1 
II159>>>	
     N)r   objectreturnbool)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r   r   r   r   r      s
    5
r   r   FcaptureVarsc                r    U (       a  SnU   SS-    W$ ! [          a    [        R                  " U S9n U$ f = f)z.
Make a C{Failure} of a divide-by-zero error.
xyz   r   r(   )BaseExceptionr   Failure)r)   exampleLocalVarfs      r   getDivisionFailurer1   %   sH      	5	A H  5OO4H5s    66c                     \ rS rSrSrS+S jrS+S jrS+S jrS+S jrS,S jr	S-S jr
S.S	 jr S/     S0S
 jjrS1S2S jjrS1S2S jjrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS3S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jr S+S jr!S+S  jr"S+S! jr#S+S" jr$S+S# jr%S+S$ jr&S4S% jr'S+S& jr(S+S' jr)S+S( jr*S)r+g*)5FailureTests6   z
Tests for L{failure.Failure}.
c                    [        S5      e! [         a    [        R                  " 5       n Of = fUR	                  [
        [        5      nU R                  U[        5        U R                  UR                  [         5        g)z
Trapping a L{Failure}.
testN)	NotImplementedErrorr-   r   r.   trap
SystemExitRuntimeErrorassertEqualtype)r   r0   errors      r   test_failAndTrapFailureTests.test_failAndTrap;   sb    	"%f-- 	"!A	"z<0-!45s    //c                    [        5       n Ue! [         a    [        R                  " 5       n Of = fU R	                  [         UR
                  [        5      nU R                  X5        g)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.   assertRaisesr8   OverflowErrorassertIs)r   	exceptionr0   	untrappeds       r   test_trapRaisesWrappedException,FailureTests.test_trapRaisesWrappedExceptionG   sV     L		"O 	"!A	" %%j!&&-H	i+s    00c                    [        5       n[        R                  " U5      n[        R                  " U5      nU R                  UR                  U5        g)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)rA   r   r.   rD   valuer   rE   f1f2s       r   test_failureValueFromFailure)FailureTests.test_failureValueFromFailureV   s9     L	__Y'__R bhh	*r   c                    [        5       n[        R                  " U5      n UR                  [        5        U R                  WR                  U5        g! [
         a    [        R                  " 5       n N>f = f)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)rA   r   r.   r8   rC   r-   rD   rJ   rK   s       r   !test_failureValueFromFoundFailure.FailureTests.test_failureValueFromFoundFailurea   s[     L	__Y'	#GGM" 	bhh	*  	#"B	#s   A A65A6c                T    U R                  UR                  U5      U< SU< 35        g)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   sprefixs      r   assertStartsWithFailureTests.assertStartsWithq   s(     	V,
:OPQu.UVr   c                T    U R                  UR                  U5      U< SU< 35        g)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)rT   endswith)r   rV   suffixs      r   assertEndsWithFailureTests.assertEndsWith|   s'     	

6*vj8KA5,QRr   c                H    U R                  X5        U R                  X5        g)a  
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)rX   r]   )r   tbrW   r\   s       r   assertTracebackFormat"FailureTests.assertTracebackFormat   s      	b)B'r   c                   [        US9n[        5       nU(       a  UR                  5         UR                  U5        UR	                  5       nSUR
                  UR                  =(       a    S=(       d    S4-  nSR                  [        R                  " UR                  5      [        R                  " UR                  5      UR
                  5      nU R                  XVU5        UR                  5        Vs/ s H  oR                  S5      (       d  M  UPM     n	nU(       a0  U R!                  / U	5        U(       a  SnOSnU R#                  X5        g
U R%                  / U	5        U R#                  S	U5        g
s  snf )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/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 #{} ---
z  z  exampleLocalVar : "'xyz'"z  exampleLocalVar : 'xyz'zA [Capture of Locals and Globals disabled (use captureVars=True)]
N)r1   r   cleanFailureprintDetailedTracebackgetvaluecountpickledformatr   qualr<   safe_strrJ   ra   
splitlinesrU   assertNotEqualassertInr;   )
r   r)   re   r0   outr`   startendlinelinesWithVarss
             r   assertDetailedTraceback$FailureTests.assertDetailedTraceback   s)   R ;7jNN	  %\\^)GGYY(=0S-
 
 6<<LL QWW%GG

 	""2c2 +---/S/$__T=R/SM262MM$.R/MMW Ts   6E7E7c                z   U(       a  SnU  [        5       n[        5       nUR                  U5        UR                  5       nSnUR                   H  u  pxpnXh SU	 SU S3-  nM     [        [        5      nU R                  USU S3U 5        U(       a'  U R                  [        R                  " SU5      5        gg)	aT  
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}
abcde :
zTraceback: : zexampleLocalVar.*abcdeN)r1   r   printBriefTracebackrg   framesreprZeroDivisionErrorra   assertIsNoneresearch)r   r)   r/   r0   rp   r`   stackmethodfilenamelineno	localVars
globalVarszdes                r   assertBriefTraceback!FailureTests.assertBriefTraceback   s      %O  j	c"\\^?@xx;Ffz6(!F8266E @H $%""#b!g	
 bii(@"EF r   c           
     8   U(       a  SnU  [        US9n[        5       nUR                  U5        UR                  5       nSnUR                   HA  u  pxpnUSU SU	 SU S3-  nUS[
        R                  " X5      R                  5        S3-  nMC     U R                  US	U< [        R                  " UR                  5      < S
[        R                  " UR                  5      < S35        U(       a'  U R                  [        R                   " SU5      5        gg)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}
xyzzyr(   ry   z  File "z", line z, in r{   z    z"Traceback (most recent call last):r|   zexampleLocalVar.*xyzzyN)r1   r   printTracebackrg   r~   	linecachegetlinestripra   r   rk   r<   rl   rJ   r   r   r   )r   r)   r/   r0   rp   r`   r   r   r   r   r   r   s               r   assertDefaultTraceback#FailureTests.assertDefaultTraceback
  s   " %O ;7j	\\^?@xx;Ffxz&vhbIIEtI--h?EEGHKKE @H 	""0 QVV$  )			
 bii(@"EF r   c                $    U R                  5         g)zZ
L{printDetailedTraceback} returns a detailed traceback including the
L{Failure}'s count.
Nru   r   s    r   test_printDetailedTraceback(FailureTests.test_printDetailedTraceback8  s    
 	$$&r   c                $    U R                  5         g)z3
L{printBriefTraceback} returns a brief traceback.
Nr   r   s    r   test_printBriefTraceback%FailureTests.test_printBriefTraceback?  s     	!!#r   c                $    U R                  5         g)z(
L{printTraceback} returns a traceback.
Nr   r   s    r   test_printTraceback FailureTests.test_printTracebackE  s     	##%r   c                "    U R                  SS9  g)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(   Nr   r   s    r   'test_printDetailedTracebackCapturedVars4FailureTests.test_printDetailedTracebackCapturedVarsK  s     	$$$6r   c                "    U R                  SS9  g)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(   Nr   r   s    r   $test_printBriefTracebackCapturedVars1FailureTests.test_printBriefTracebackCapturedVarsS  s     	!!d!3r   c                "    U R                  SS9  g)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(   Nr   r   s    r   test_printTracebackCapturedVars,FailureTests.test_printTracebackCapturedVars]  s     	###5r   c                $    U R                  SSS9  g)zz
C{printDetailedTraceback} includes information about local variables on
the stack after C{cleanFailure} has been called.
T)r)   re   Nr   r   s    r   .test_printDetailedTracebackCapturedVarsCleaned;FailureTests.test_printDetailedTracebackCapturedVarsCleanedg  s    
 	$$D$Ir   c                N    U R                  [        [        R                  SSSS9  g)z]
L{failure.format_frames} raises a L{ValueError} if the supplied
C{detail} level is unknown.
Nnoisiadetail)rB   rA   r   format_framesr   s    r   test_invalidFormatFramesDetail+FailureTests.test_invalidFormatFramesDetailn  s(    
 	--tT( 	 	
r   c                    [        5       n[        R                  " U5      nUR                  [         5        U R	                  UR
                  U5        g r   )r:   r   r.   r8   r;   rJ   )r   er0   s      r   test_ExplictPassFailureTests.test_ExplictPassw  s7    NOOA	|!$r   c                     UR                  5         [        S5      e! [         a>    [        R                  " [
        R                  " 5       S   5      nUS   R                  s $ f = f)Nz3f.raiseException() didn't raise ZeroDivisionError!?   )raiseException	Exceptionr   	traceback
extract_tbsysexc_infors   )r   r0   r`   s      r   _getInnermostFrameLine#FailureTests._getInnermostFrameLine}  s\    	S
 QRR	 ! 	%%cllnQ&78Bb6;;	s    AA%$A%c                ^    [        5       nU R                  U5      nU R                  US5        g )N1 / 0)r1   r   r;   )r   r0   	innerlines      r   test_RaiseExceptionWithTB&FailureTests.test_RaiseExceptionWithTB  s*     //2	G,r   c                `    U R                  [        R                  [        R                  5        g)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)rB   r   NoCurrentExceptionErrorr.   r   s    r   test_ConstructionFails#FailureTests.test_ConstructionFails  s     	'997??Kr   c                l    [        5       nU R                  UR                  5       UR                  5        g)z
If the C{Failure} has not been cleaned, then C{getTracebackObject}
returns the traceback object that captured in its constructor.
N)r1   r;   getTracebackObjectr`   r   r0   s     r   test_getTracebackObject$FailureTests.test_getTracebackObject  s)    
  --/6r   c                     SS-    U R                  WR	                  5       WR
                  5        g! [          a,    [        R                  " 5       n[        R                  " SS9n N`f = f)zK
C{captureVars=True} has no effect on the result of
C{getTracebackObject}.
r,   r   Tr(   N)r   r   r.   r;   r   r`   )r   noVarsFailurevarsFailures      r   &test_getTracebackObjectFromCaptureVars3FailureTests.test_getTracebackObjectFromCaptureVars  sX    
	<E 	99;[^^L ! 	<#OO-M!//d;K	<s   2 3A('A(c                   [        5       n[        R                  " UR                  5       5      nUR	                  5         [        R                  " UR                  5       5      nU R                  U5        U R                  X#5        g)z
If the Failure has been cleaned, then C{getTracebackObject} returns an
object that looks the same to L{traceback.extract_tb}.
N)r1   r   r   r   re   assertIsNotNoner;   r   r0   expectedobserveds       r    test_getTracebackObjectFromClean-FailureTests.test_getTracebackObjectFromClean  sd    
  ''(<(<(>?	''(<(<(>?X&,r   c                    [        SS9n[        R                  " UR                  5       5      nUR	                  5         [        R                  " UR                  5       5      nU R                  X#5        g)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)r1   r   r   r   re   r;   r   s       r   .test_getTracebackObjectFromCaptureVarsAndClean;FailureTests.test_getTracebackObjectFromCaptureVarsAndClean  sX    
 40''(<(<(>?	''(<(<(>?,r   c                    [         R                  " [        S5      5      nU R                  UR	                  5       5        g)z
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   r   r   r   s     r   'test_getTracebackObjectWithoutTraceback4FailureTests.test_getTracebackObjectWithoutTraceback  s.     OOIl34!..01r   c                     SS-    [        R                  " W5      nU R                  UR                  W5        g! [          a    [        R                  " 5       u  pn NWf = f)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.   rD   r`   )r   klassrE   r`   r0   s        r   $test_tracebackFromExceptionInPython31FailureTests.test_tracebackFromExceptionInPython3  sQ    	2E OOI&addB  	2#&<<> Eb	2s   : "AAc                   [        5       nU R                  UR                  5        U R                  UR                  R
                  UR                  5        UR                  5         U R                  UR                  R
                  5        g)zn
L{failure.Failure.cleanFailure} sets the C{__traceback__} attribute of
the exception to L{None} in Python 3.
N)r1   r   r`   rD   rJ   __traceback__re   r   r   s     r   *test_cleanFailureRemovesTracebackInPython37FailureTests.test_cleanFailureRemovesTracebackInPython3  s\    
  QTT"agg++QTT2	!''//0r   c                    [        5       n[        5       n[        UR                  5       US9  U R	                  SUR                  5       5        g)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)r1   r   r   r   ro   rg   )r   r0   bufs      r   
test_distbFailureTests.test_distb  s<      ja""$3/ 	gs||~.r   c                    [        5       n[        R                  " [        5      nU R	                  [        U5      SU< S35        g)zk
The C{repr} of a L{failure.Failure} shows the type and string
representation of the underlying exception.
z <twisted.python.failure.Failure z: division by zero>N)r1   r   fullyQualifiedNamer   r;   r   )r   r0   typeNames      r   	test_reprFailureTests.test_repr  s8    
  --.?@GJRT	
r   c                    [        5       nUR                  Ul        U R                  5       nU R                  [	        U5      S:  5        USS  H  nU R                  SUS   5        M     g)z<
C{Failure.stack} is gettable and settable, but depreacted.
r,   NzFtwisted.python.failure.Failure.stack was deprecated in Twisted 24.10.0message)r1   r   flushWarningsrT   lenr;   )r   r0   warningsws       r   test_stackDeprecation"FailureTests.test_stackDeprecation  sb      ''%%'H*+"#AX) r   c                   [        S5      n[        R                  " U5      R                  R	                  5       n[        R                  R                  U5      nU R                  U[        R                  5        UR                  R	                  5       nU R                  UR                  S5      S-   UR                  S5      5        U R                  X$5        g)zM
C{Failure._withoutTraceback(exc)} gives the same result as
C{Failure(exc)}.
hellorh   r,   N)	r   r   r.   __dict__copy_withoutTracebackassertIsInstancer;   pop)r   excdict1failure2dict2s        r   test_failureWithoutTraceback)FailureTests.test_failureWithoutTraceback  s    
  ($--224??44S9h8!!&&( 	7+a/71CD 	&r   c                L   [        S5      n[        R                  " U5      nU R                  U5        [        R                  R	                  U5      nU R                  U5         [        S5      e! [
         a    [        R                  " 5       n Of = fU R                  U5        g)zU
C{Failure(exc)} and C{Failure._withoutTraceback(exc)} can be pickled
and unpickled.
r   booN)r   r   r.   assertPicklingRoundtripsr  r-   )r   r  failure1r  failure3s        r   test_failurePickling!FailureTests.test_failurePickling  s    
 "'*??3'%%h/
 ??44S9%%h/	)%e,, 	)(H	)%%h/s   $A/ /BBc                B   [         R                  " [         R                  " U5      5      nUR                  R	                  5       nSUS'   SUS'   UR                  R	                  5       nU R                  X45        U R                  UR                  UR                  5        g)zc
The failure can be pickled and unpickled, and the C{parents} attribute
is included in the pickle.
r,   ri   Nr`   )pickleloadsdumpsr  r  r;   r~   )r   original_failurer  r   results        r   r  %FailureTests.assertPicklingRoundtrips/  s    
 <<-= >?#,,113""'')**:*A*ABr   c                    [         R                  " [        S5      5      nU R                  UR	                  5       S   UR
                  5        g)z/
C{Failure.parents} is included in the pickle.
r   parentsN)r   r.   r   r;   __getstate__r  r   s     r   #test_failurePicklingIncludesParents0FailureTests.test_failurePicklingIncludesParents<  s8     OO/89))4aii@r   c                6   [         R                  " [        5       5      nUR                  SS Ul        [        R
                  " [        R                  " U5      5      nUR                  SS Ul        U R                  UR                  UR                  SS 5        g)z?
C{Failure.frames} can be set, both before and after pickling.
Nr   )r   r.   r1   r~   r  r  r  r;   r   r  r  s      r   test_settableFrames FailureTests.test_settableFramesC  sw     #??+=+?@"2"9"9!"<<<-= >?"//#2.*:*A*A#2*FGr   c                    [         R                  " [        S5      5      nUR                  SS Ul        [        R
                  " [        R                  " U5      5      nUR                  SS Ul        g)z[
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   s      r   test_settableParents!FailureTests.test_settableParentsM  sX     #??+>w+GH#3#;#;A#> <<-= >?#++A.r   r   Nr    None)rV   strrW   r(  r    r'  )rV   r(  r\   r(  r    r'  )r`   r(  rW   r(  r\   r(  r    r'  )FF)r)   r!   re   r!   r    r'  )F)r)   r!   r    r'  )r0   failure.Failurer    z
str | None)r  r)  r    r'  ),r"   r#   r$   r%   r&   r>   rG   rN   rQ   rX   r]   ra   ru   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'   r   r   r   r3   r3   6   s    
6,	++ 	W	S(  ?DJJ7;J	JX&GP,G\'$&746J
%S-
L7
M
-	-	2 	1/

'"0,CAH	/r   r3   c                  "    \ rS rSrSrSS jrSrg)	BrokenStriY  zV
An exception class the instances of which cannot be presented as strings
via L{str}.
c                    U er   r   r   s    r   __str__BrokenStr.__str___  s    
r   r   Nr    r(  r"   r#   r$   r%   r&   r-  r'   r   r   r   r+  r+  Y  s    
r   r+  c                  "    \ rS rSrSrSS jrSrg)BrokenExceptionMetaclassid  zU
A metaclass for an exception type which cannot be presented as a string via
L{str}.
c                    [        S5      e)Nz#You cannot make a string out of me.)rA   r   s    r   r-   BrokenExceptionMetaclass.__str__j  s    >??r   r   Nr/  r0  r   r   r   r2  r2  d  s    
@r   r2  c                      \ rS rSrSrSrg)BrokenExceptionTypein  zU
The aforementioned exception type which cannot be presented as a string via
L{str}.
r   N)r"   r#   r$   r%   r&   r'   r   r   r   r6  r6  n  s    r   r6  )	metaclassc                  h    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSrg)GetTracebackTestsiv  z$
Tests for L{Failure.getTraceback}.
c                    [        5       n[        R                  " U5      nUR                  US9nU R	                  U[
        5        g)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  r(  )r   r   xr0   r   s        r   _brokenValueTest"GetTracebackTests._brokenValueTest{  s9     KOOANN&N1	i-r   c                &    U R                  S5        g)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   s    r   test_brokenValueBriefDetail-GetTracebackTests.test_brokenValueBriefDetail  s     	g&r   c                &    U R                  S5        g)I
Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
defaultNrA  r   s    r   test_brokenValueDefaultDetail/GetTracebackTests.test_brokenValueDefaultDetail       	i(r   c                &    U R                  S5        g)rE  verboseNrA  r   s    r   test_brokenValueVerboseDetail/GetTracebackTests.test_brokenValueVerboseDetail  rI  r   c                    [         R                  " [        5       5      nUR                  US9nU R	                  U[
        5        g)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.   r6  r;  r  r(  )r   r   r0   r   s       r   _brokenTypeTest!GetTracebackTests._brokenTypeTest  s6     OO/12NN&N1	i-r   c                &    U R                  S5        g)a  
        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rO  r   s    r   test_brokenTypeBriefDetail,GetTracebackTests.test_brokenTypeBriefDetail  s     	W%r   c                &    U R                  S5        g)zH
Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
rF  NrR  r   s    r   test_brokenTypeDefaultDetail.GetTracebackTests.test_brokenTypeDefaultDetail       	Y'r   c                &    U R                  S5        g)zH
Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
rK  NrR  r   s    r   test_brokenTypeVerboseDetail.GetTracebackTests.test_brokenTypeVerboseDetail  rX  r   r   N)r   r(  r    r'  r&  )r"   r#   r$   r%   r&   r=  rB  rG  rL  rO  rS  rV  rZ  r'   r   r   r   r9  r9  v  s/    	.')).	&((r   r9  c                  >    \ rS rSrSr\" \SL S5      SS j5       rSrg)FindFailureTestsi  z@
Tests for functionality related to identifying the C{Failure}.
Nzraiser extension not availablec                    [         R                  " 5         U R                  S5        g! [         R                   aF    [        R
                  " 5       nU R                  UR                  [         R                  5      5         gf = f)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   failRaiserExceptionr   r.   rT   checkr   s     r   /test_failureConstructionWithMungedStackSucceeds@FindFailureTests.test_failureConstructionWithMungedStackSucceeds  s`    	>!!#
 II<=	 %% 	=!AOOAGGF$:$:;<	=s   ) ABBr   r&  )	r"   r#   r$   r%   r&   r   r   rb  r'   r   r   r   r]  r]    s'     FdN<=> >>r   r]  c                    [        XU5      $ r   r   )fnr   nametexts       r   _tbrh    s    D))r   c                  ,    \ rS rSrSrSS jrSS jrSrg)FormattableTracebackTestsi  z
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.
c           	         [         R                  " SSS0 0 //5      nU R                  [        R                  " U5      [        SSSS5      /5        g)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.
r   filename.py{   N)r   
_Tracebackr;   r   r   rh  r   r`   s     r   test_singleFrame*FormattableTracebackTests.test_singleFrame  sP     (M3B!G HI 	  $s=#x'N&O	
r   c           
     B   [         R                  " SSS0 0 /SSS0 0 //5      nU R                  [        R                  " U5      [        SSSS5      [        SSSS5      /5        U R                  [        R                  " UR                  5      [        SSSS5      /5        g)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.
method1rl  rm  method2   N)r   rn  r;   r   r   rh  extract_stacktb_framero  s     r   test_manyFrames)FormattableTracebackTests.test_manyFrames  s     M3B7M3B7
 	  $M3	48M3	48	
 	##BKK0M3	48	
r   r   Nr&  )r"   r#   r$   r%   r&   rp  rx  r'   r   r   r   rj  rj    s    

r   rj  c                  6    \ rS rSrSrSS jrSS jrSS jrSrg)	FakeAttributesTestsi  a:  
_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).
c                x   [         R                  " SS5      nSS0nSS0n[         R                  " SSSUU4U5      nU R                  UR                  U5        U R                  UR                  U5        U R                  UR                  [         R                  5        U R                  UR                  U5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  S5        U R                  UR                  [        S5      5        g)	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.
)dummyparentdummyparentfileo   NNN	local_var*   
global_vard   	dummynamedummyfilename)r   _Framer;   	f_globalsf_localsr  f_code_Codef_back
f_builtinsdictf_lastiintf_linenof_tracer<   )r   
back_framefake_localsfake_globalsframes        r   test_fakeFrameAttributes,FakeAttributesTests.test_fakeFrameAttributes  s    ^^ 	

 #B'$c* 	
 	,75ellGMM:z2e..5emmS1,emmT$Z8r   c                j   [         R                  " SS5      nU R                  UR                  S5        U R                  UR                  S5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                  [        5        U R                  UR                   [        5        U R                  UR"                  [        5        U R                  UR$                  [        5        U R                  UR&                  [        5        U R                  UR(                  [        5        U R                  UR*                  [        5        U R                  UR,                  [.        5        U R                  UR1                  5       [        5        g)>
See L{FakeAttributesTests} for more details about this test.
r  r  N)r   r  r;   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listco_positions)r   codes     r   test_fakeCodeAttributes+FakeAttributesTests.test_fakeCodeAttributes;  s    }}[/:{3))?;d..4dllE2d..6dnne4d1137dmmS1dnne4d..6d55s;d44c:dmmU3doos3d//5d..5d//159r   c                N   [         R                  " SSS0 0 4S5      n[         R                  " U5      nU R                  UR                  U5        U R                  UR
                  S5        U R                  UR                  [        5        U R                  [        US5      5        g)r  r  r  r  Ntb_next)r   r  _TracebackFramer;   rw  	tb_linenor  tb_lastir  rT   hasattr)r   r  traceback_frames      r   test_fakeTracebackFrame+FakeAttributesTests.test_fakeTracebackFrameR  s     /2r26
 "11%8115922B7o66<;<r   r   Nr&  )	r"   r#   r$   r%   r&   r  r  r  r'   r   r   r   r{  r{    s    #9J:.=r   r{  c                  6    \ rS rSrSrSS jrSS jrSS jrSrg)	DebugModeTestsia  z>
Failure's debug mode should allow jumping into the debugger.
c                   ^ ^^ [         R                  m[        R                  R                  mSUU4S jjnT R                  U5        / T l        SSU 4S jjjnU[         l        [        R                  " 5         g)z;
Override pdb.post_mortem so we can make sure it's called.
c                 F   > T[         l        T [        R                  l        g r   )pdbpost_mortemr   r.   __init__)origInitr  s   r   restore%DebugModeTests.setUp.<locals>.restoren  s    )CO'/GOO$r   Nc                <   > TR                   R                  U 5        g r   )r  append)tr   s    r   logging_post_mortem1DebugModeTests.setUp.<locals>.logging_post_mortemv  s    KKq!r   r&  r   )r  zTracebackType | Noner    r'  )r  r  r   r.   r  
addCleanupr  startDebugMode)r   r  r  r  r  s   `  @@r   setUpDebugModeTests.setUpf  s[    
 oo??++	0 	0 	 24	" 	" . r   c                     SS-    U R                  U R                  W/5        U R                  WR                  5        g! [          a0    [        R                  " 5       u  pn[        R                  " 5       n Nrf = f)zf
If startDebugMode() is called, calling Failure() will first call
pdb.post_mortem with the traceback.
r,   r   N)	r-   r   r   r   r.   r;   r  assertFalser)   r   typr  r`   r0   s        r   test_regularFailure"DebugModeTests.test_regularFailure|  sd    
	"E 	rd+'	  	"<<>LCb!A	"s   A   7A:9A:c                     SS-    U R                  U R                  W/5        U R                  WR                  5        g! [          a/    [        R                  " 5       u  pn[        R                  " SS9n Nqf = f)zS
If startDebugMode() is called, passing captureVars to Failure() will
not blow up.
r,   r   Tr(   N)	r-   r   r   r   r.   r;   r  rT   r)   r  s        r   test_captureVarsDebugModeTests.test_captureVars  sd    
	2E 	rd+&	  	2<<>LCbD1A	2s   A   6A98A9)r  Nr&  )	r"   r#   r$   r%   r&   r  r  r  r'   r   r   r   r  r  a  s    !,('r   r  c                  V    \ rS rSrSr      S
S jrSS jrSS jrSS jrSS jr	Sr
g	)ExtendedGeneratorTestsi  zM
Tests C{failure.Failure} support for generator features added in Python 2.5
c                j     UR                  U5        U R                  S5        g ! [         a     g f = f)Nz<throwExceptionIntoGenerator should have raised StopIteration)throwExceptionIntoGeneratorr_  StopIteration)r   r0   gs      r   _throwIntoGenerator*ExtendedGeneratorTests._throwIntoGenerator  s9    	Y))!, IIWX  		s   % 
22c                L  ^ ^ / mSU U4S jjnU" 5       n[        5       n[        U5        T R                  X25        T R                  TS   S   [        5        T R                  TS   S   [        5        T R                  [        R                  " TS   S   5      S   S   S5        g)	zZ
It should be possible to throw the exception that a Failure
represents into a generator.
c               3     >#     S v   T R                  S5        g ! [         a'    TR                  [        R                  " 5       5         g f = f7f)Nz$Yield should have yielded exception.)r_  r-   r  r   r   )r   stuffs   r   	generatorJExtendedGeneratorTests.test_throwExceptionIntoGenerator.<locals>.generator  s@     B 		@A ! -S\\^,-%   A A.A	AAAr   r,   r   r   r   Nr    zGenerator[None, None, None])r1   nextr  r;   r   r  r   r   )r   r  r  r0   r  s   `   @r    test_throwExceptionIntoGenerator7ExtendedGeneratorTests.test_throwExceptionIntoGenerator  s    
 	B 	B K Q  &q!&78eAhqk+<=--eAhqk:2>rBGLr   c                  ^ ^ [        5       nUR                  5         UR                  5       n/ mSUU 4S jjnU" 5       n[        U5        T R	                  X5        T R                  [        T5      S5        T R                  X!R                  5       5        T R                  TS   R                  5       UR                  5       5        T R                  STS   R                  5       5        T R                  SUR                  5       5        g)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.
c               3     >#     S v   TR                  S5        g ! [         a'    T R                  [        R                  " 5       5         g f = f7f)NzNo exception sent to generator)r_  r-   r  r   r.   )newFailuresr   s   r   r  VExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure.<locals>.generator  sB     < 		:; ! 6""7??#456r  r,   r   r  Nr  )
r1   re   r;  r  r  r;   r   rn   ro   assertNotIn)r   r0   original_failure_strr  r  r  s   `    @r   ,test_failureConstructionFindsOriginalFailureCExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure  s      	 ~~/	< 	< KQ  &[)1- 	-~~/?@ 	KN7791>>;KLk;q>#>#>#@Aann&67r   c                p   ^  SU 4S jjnU" 5       n[        U5        [        5       nT R                  X25        g)z
When a generator reraises a different exception, creating a L{Failure}
inside the generator should find the reraised exception rather than
original one.
c               3     >#      S v   g ! [          a    / S      g f = f! [          a6    T R                  [        R                  " 5       R                  [
        5         g f = f7fNr,   )r-   r  r   r.   rJ   
IndexErrorr   s   r   r  JExtendedGeneratorTests.test_ambiguousFailureInGenerator.<locals>.generator  sV     K$ qE  K%%goo&7&=&=zJKs:   A# A#  A#  =A A#A  A#Nr  )r  r1   r  r   r  r  r0   s   `   r    test_ambiguousFailureInGenerator7ExtendedGeneratorTests.test_ambiguousFailureInGenerator  s/    	K KQ   &r   c                    SS jnU" 5       n[        U5        [        5       n U R                  X25        g! [         a6    U R	                  [
        R                  " 5       R                  [        5         gf = f)z
When a generator reraises a different exception, creating a L{Failure}
above the generator should find the reraised exception rather than
original one.
c               3  @   #     S v   g ! [          a    / S      g f = f7fr  )r-   r   r   r   r  LExtendedGeneratorTests.test_ambiguousFailureFromGenerator.<locals>.generator  s"       1s   	 Nr  )	r  r1   r  r-   r  r   r.   rJ   r  r  s       r   "test_ambiguousFailureFromGenerator9ExtendedGeneratorTests.test_ambiguousFailureFromGenerator  sa    	 KQ 	G$$Q* 	G!!'//"3"9"9:F	Gs   5 =A54A5r   N)r0   r)  r  zGenerator[Any, Any, Any]r    r'  r&  )r"   r#   r$   r%   r&   r  r  r  r  r  r'   r   r   r   r  r    s?    Y Y%=Y	YM2"8H'*Gr   r  )r)   r!   r    r)  )
re  r(  r   r  rf  r(  rg  r'  r    r   ),r&   
__future__r   r   r  r  r   r   r   disr   ior   r   typesr   typingr	   r
   r   unittestr   cython_test_exception_raiserr   twisted.pythonr   r   twisted.trial.unittestr   r   r   r1   r3   r+  r<   r2  r6  r9  r]  rh  rj  r{  r  r  r   r   r   <module>r     s    #  
  	 
    "  ' '  / + 6
) 
 /4 "`/& `/F	 @t @)/G C(+ C(L>* >2*1
 3 1
hQ=- Q=h3'( 3'ltG0 tGr   