+
    DfjÊ                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt  ! R R]4      tRR/R R llt ! R R]4      t  ! R R]4      t! ! R R]"4      t# ! R R]]#R7      t$ ! R R]4      t% ! R R]4      t&R R  lt' ! R! R"]4      t( ! R# R$]4      t) ! R% R&]4      t* ! R' R(]4      t+R# ))z6
Test cases for the L{twisted.python.failure} module.
)annotationsN)distb)StringIOFrameSummary)TracebackType)Any	Generatorcast)skipIf)raiser)failurereflect)SynchronousTestCasec                  &    ] tR t^tRtR R ltRtR# )ComparableExceptionz+An exception that can be compared by value.c                    V ^8  d   QhRRRR/# )   otherobjectreturnbool )formats   "B/usr/lib/python3/dist-packages/twisted/test/ignore_test_failure.py__annotate__ ComparableException.__annotate__   s     
 
F 
t 
    c                	    V P                   VP                   8H  ;'       d(    V P                  \        \        V4      P                  8H  # N)	__class__argsr
   r   )selfr   s   &&r   __eq__ComparableException.__eq__   s;    %//1 
 
II159>>>	
r   r   N)__name__
__module____qualname____firstlineno____doc__r#   __static_attributes__r   r   r   r   r      s    5
 
r   r   captureVarsFc                    V ^8  d   QhRRRR/# )r   r+   r   r   failure.Failurer   )r   s   "r   r   r   %   s      t  r   c                    V '       d   RpV  ^^ ,           X#   \          d    \        P                  ! T R7      p T# i ; i)z.
Make a C{Failure} of a divide-by-zero error.
xyzr+   )BaseExceptionr   Failure)r+   exampleLocalVarfs   $  r   getDivisionFailurer5   %   sH      	5	A H  5OO4H5s   	 "??c                     ] tR t^6tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
R R ltRPR R lltRQR R lltRQR R lltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 ltR4 R5 ltR6 R7 ltR8 R9 lt R: R; lt!R< R= lt"R> R? lt#R@ RA lt$RB RC lt%RD RE lt&RF RG lt'RH RI lt(RJ RK lt)RL RM lt*RNt+RO# )RFailureTestsz
Tests for L{failure.Failure}.
c                   V ^8  d   QhRR/# r   r   Noner   )r   s   "r   r   FailureTests.__annotate__;   s     
6 
6$ 
6r   c                
    \        R4      h  \         d    \        P                  ! 4       p Mi ; iTP	                  \
        \        4      pT P                  T\        4       T P                  TP                  \         4       R# )z
Trapping a L{Failure}.
testN)	NotImplementedErrorr1   r   r2   trap
SystemExitRuntimeErrorassertEqualtype)r"   r4   errors   &  r   test_failAndTrapFailureTests.test_failAndTrap;   sb    	"%f-- 	"!A	"z<0-!45s     00c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   G   s     , , ,r   c                    \        4       p Vh  \         d    \        P                  ! 4       p Mi ; iT P	                  \         TP
                  \        4      pT P                  Y4       R# )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)
ValueErrorr1   r   r2   assertRaisesr?   OverflowErrorassertIs)r"   	exceptionr4   	untrappeds   &   r   test_trapRaisesWrappedException,FailureTests.test_trapRaisesWrappedExceptionG   sV     L		"O 	"!A	" %%j!&&-H	i+s     11c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   V   s     	+ 	+d 	+r   c                    \        4       p\        P                  ! V4      p\        P                  ! V4      pV P                  VP                  V4       R# )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)rI   r   r2   rL   valuer"   rM   f1f2s   &   r   test_failureValueFromFailure)FailureTests.test_failureValueFromFailureV   s9     L	__Y'__R bhh	*r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   a   s     + +4 +r   c                    \        4       p\        P                  ! V4      p VP                  \        4       V P                  XP                  V4       R#   \
         d    \        P                  ! 4       p L@i ; i)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)rI   r   r2   r?   rK   r1   rL   rS   rT   s   &   r   !test_failureValueFromFoundFailure.FailureTests.test_failureValueFromFoundFailurea   s[     L	__Y'	#GGM" 	bhh	*  	#"B	#s   A  A87A8c               $    V ^8  d   QhRRRRRR/# )r   sstrprefixr   r:   r   )r   s   "r   r   r;   q   s&     	W 	W# 	Ws 	Wt 	Wr   c                V    V P                  VP                  V4      V: RV: 24       R# )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^   r`   s   &&&r   assertStartsWithFailureTests.assertStartsWithq   s(     	V,
:OPQu.UVr   c               $    V ^8  d   QhRRRRRR/# )r   r^   r_   suffixr   r:   r   )r   s   "r   r   r;   |   s&     	S 	S 	SS 	ST 	Sr   c                V    V P                  VP                  V4      V: RV: 24       R# )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)rb   endswith)r"   r^   rg   s   &&&r   assertEndsWithFailureTests.assertEndsWith|   s'     	

6*vj8KA5,QRr   c               (    V ^8  d   QhRRRRRRRR/# )r   tbr_   r`   rg   r   r:   r   )r   s   "r   r   r;      s(     ( ( (S (# ($ (r   c                J    V P                  W4       V P                  W4       R# )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)rd   rj   )r"   rm   r`   rg   s   &&&&r   assertTracebackFormat"FailureTests.assertTracebackFormat   s      	b)B'r   c               $    V ^8  d   QhRRRRRR/# )r   r+   r   cleanFailurer   r:   r   )r   s   "r   r   r;      s)     J JJ7;J	Jr   c                   \        VR7      p\        4       pV'       d   VP                  4        VP                  V4       VP	                  4       pRVP
                  VP                  ;'       d    R;'       g    R3,          pRP                  \        P                  ! VP                  4      \        P                  ! VP                  4      VP
                  4      pV P                  WVV4       VP                  4        Uu. uF  qP                  R4      '       g   K  VNK  	  p	pV'       d3   V P!                  . V	4       V'       d   RpMRpV P#                  W4       R
# V P%                  . V	4       V P#                  R	V4       R
# u upi )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}
r0   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)r5   r   rr   printDetailedTracebackgetvaluecountpickledr   r   qualrC   safe_strrS   ro   
splitlinesrc   assertNotEqualassertInrB   )
r"   r+   rr   r4   outrm   startendlinelinesWithVarss
   &&&       r   assertDetailedTraceback$FailureTests.assertDetailedTraceback   s1   R ;7jNN	  %\\^)GGYY((=00S-
 
 6<<LL QWW%GG

 	""2c2 +---/S/$__T=R/SM262MM$.R/MMW Ts    FFc                    V ^8  d   QhRRRR/# r   r+   r   r   r:   r   )r   s   "r   r   r;      s     &G &G &G &Gr   c                   V'       d   RpV \        4       p\        4       pVP                  V4       VP                  4       pRpVP                   F  w  rxrpWh RV	 RV R2,          pK  	  \        \        4      pV P                  VRV R2V 4       V'       d)   V P                  \        P                  ! RV4      4       R# R# )	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)r5   r   printBriefTracebackrv   framesreprZeroDivisionErrorro   assertIsNoneresearch)r"   r+   r3   r4   r~   rm   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                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r;   
  s     ,G ,G$ ,G4 ,Gr   c           
     V   V'       d   RpV \        VR7      p\        4       pVP                  V4       VP                  4       pRpVP                   FI  w  rxrpVRV RV	 RV R2,          pVR\
        P                  ! W4      P                  4        R2,          pKK  	  V P                  VR	V: \        P                  ! VP                  4      : R
\        P                  ! VP                  4      : R24       V'       d)   V P                  \        P                   ! RV4      4       R# R# )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}
xyzzyr0   r   z  File "z", line z, in r   z    z"Traceback (most recent call last):r   zexampleLocalVar.*xyzzyN)r5   r   printTracebackrv   r   	linecachegetlinestripro   r   ry   rC   rz   rS   r   r   r   )r"   r+   r3   r4   r~   rm   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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   8  s     ' 'T 'r   c                &    V P                  4        R# )zZ
L{printDetailedTraceback} returns a detailed traceback including the
L{Failure}'s count.
Nr   r"   s   &r   test_printDetailedTraceback(FailureTests.test_printDetailedTraceback8  s    
 	$$&r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   ?  s     $ $$ $r   c                &    V P                  4        R# )z3
L{printBriefTraceback} returns a brief traceback.
Nr   r   s   &r   test_printBriefTraceback%FailureTests.test_printBriefTraceback?  s     	!!#r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   E  s     & &T &r   c                &    V P                  4        R# )z(
L{printTraceback} returns a traceback.
Nr   r   s   &r   test_printTraceback FailureTests.test_printTracebackE  s     	##%r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   K  s     7 7 7r   c                *    V P                  RR7       R# )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}.
Tr0   Nr   r   s   &r   'test_printDetailedTracebackCapturedVars4FailureTests.test_printDetailedTracebackCapturedVarsK  s     	$$$6r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   S  s     4 4d 4r   c                *    V P                  RR7       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.
Tr0   Nr   r   s   &r   $test_printBriefTracebackCapturedVars1FailureTests.test_printBriefTracebackCapturedVarsS  s     	!!d!3r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   ]  s     6 6 6r   c                *    V P                  RR7       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.
Tr0   Nr   r   s   &r   test_printTracebackCapturedVars,FailureTests.test_printTracebackCapturedVars]  s     	###5r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   g  s     J J Jr   c                ,    V P                  RRR7       R# )zz
C{printDetailedTraceback} includes information about local variables on
the stack after C{cleanFailure} has been called.
T)r+   rr   Nr   r   s   &r   .test_printDetailedTracebackCapturedVarsCleaned;FailureTests.test_printDetailedTracebackCapturedVarsCleanedg  s    
 	$$D$Ir   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   n  s     
 
 
r   c                V    V P                  \        \        P                  RRRR7       R# )z]
L{failure.format_frames} raises a L{ValueError} if the supplied
C{detail} level is unknown.
Nnoisiadetail)rJ   rI   r   format_framesr   s   &r   test_invalidFormatFramesDetail+FailureTests.test_invalidFormatFramesDetailn  s(    
 	--tT( 	 	
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   w  s     % %$ %r   c                	    \        4       p\        P                  ! V4      pVP                  \         4       V P	                  VP
                  V4       R # r   )rA   r   r2   r?   rB   rS   )r"   er4   s   &  r   test_ExplictPassFailureTests.test_ExplictPassw  s7    NOOA	|!$r   c                    V ^8  d   QhRRRR/# )r   r4   r-   r   z
str | Noner   )r   s   "r   r   r;   }  s     S S SJ Sr   c                	     VP                  4        \        R 4      h  \         dG    \        P                  ! \
        P                  ! 4       ^,          4      pTR,          P                  u # i ; i)z3f.raiseException() didn't raise ZeroDivisionError!?)raiseException	Exceptionr   	traceback
extract_tbsysexc_infor   )r"   r4   rm   s   && r   _getInnermostFrameLine#FailureTests._getInnermostFrameLine}  s\    	S
 QRR	 ! 	%%cllnQ&78Bb6;;	s    AA.-A.c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     - -4 -r   c                	`    \        4       pV P                  V4      pV P                  VR 4       R# )1 / 0N)r5   r   rB   )r"   r4   	innerlines   &  r   test_RaiseExceptionWithTB&FailureTests.test_RaiseExceptionWithTB  s*     //2	G,r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     L L Lr   c                b    V P                  \        P                  \        P                  4       R# )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)rJ   r   NoCurrentExceptionErrorr2   r   s   &r   test_ConstructionFails#FailureTests.test_ConstructionFails  s     	'997??Kr   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     7 7 7r   c                n    \        4       pV P                  VP                  4       VP                  4       R# )z
If the C{Failure} has not been cleaned, then C{getTracebackObject}
returns the traceback object that captured in its constructor.
N)r5   rB   getTracebackObjectrm   r"   r4   s   & r   test_getTracebackObject$FailureTests.test_getTracebackObject  s)    
  --/6r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     
M 
M 
Mr   c                     ^^ ,           V P                  XP	                  4       XP
                  4       R#   \          d0    \        P                  ! 4       p\        P                  ! RR7      p Lei ; i)zK
C{captureVars=True} has no effect on the result of
C{getTracebackObject}.
Tr0   N)r   r   r2   rB   r   rm   )r"   noVarsFailurevarsFailures   &  r   &test_getTracebackObjectFromCaptureVars3FailureTests.test_getTracebackObjectFromCaptureVars  sX    
	<E 	99;[^^L ! 	<#OO-M!//d;K	<s   	7 7A10A1c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     
- 
-$ 
-r   c                   \        4       p\        P                  ! VP                  4       4      pVP	                  4        \        P                  ! VP                  4       4      pV P                  V4       V P                  W#4       R# )z
If the Failure has been cleaned, then C{getTracebackObject} returns an
object that looks the same to L{traceback.extract_tb}.
N)r5   r   r   r   rr   assertIsNotNonerB   r"   r4   expectedobserveds   &   r    test_getTracebackObjectFromClean-FailureTests.test_getTracebackObjectFromClean  sd    
  ''(<(<(>?	''(<(<(>?X&,r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     	- 	- 	-r   c                    \        RR7      p\        P                  ! VP                  4       4      pVP	                  4        \        P                  ! VP                  4       4      pV P                  W#4       R# )z
If the Failure was created with captureVars, then C{getTracebackObject}
returns an object that looks the same to L{traceback.extract_tb}.
Tr0   N)r5   r   r   r   rr   rB   r   s   &   r   .test_getTracebackObjectFromCaptureVarsAndClean;FailureTests.test_getTracebackObjectFromCaptureVarsAndClean  sX    
 40''(<(<(>?	''(<(<(>?,r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     	2 	2 	2r   c                    \         P                  ! \        R4      4      pV P                  VP	                  4       4       R# )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   r2   r   r   r   r   s   & r   'test_getTracebackObjectWithoutTraceback4FailureTests.test_getTracebackObjectWithoutTraceback  s.     OOIl34!..01r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s        d  r   c                     ^^ ,           \        P                  ! X4      pV P                  VP                  X4       R#   \          d    \        P                  ! 4       w  rp LYi ; i)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.
N)r1   r   r   r   r2   rL   rm   )r"   klassrM   rm   r4   s   &    r   $test_tracebackFromExceptionInPython31FailureTests.test_tracebackFromExceptionInPython3  sQ    	2E OOI&addB  	2#&<<> Eb	2s   	? #A%$A%c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     	1 	1D 	1r   c                   \        4       pV P                  VP                  4       V P                  VP                  P
                  VP                  4       VP                  4        V P                  VP                  P
                  4       R# )zn
L{failure.Failure.cleanFailure} sets the C{__traceback__} attribute of
the exception to L{None} in Python 3.
N)r5   r   rm   rL   rS   __traceback__rr   r   r   s   & r   *test_cleanFailureRemovesTracebackInPython37FailureTests.test_cleanFailureRemovesTracebackInPython3  s\    
  QTT"agg++QTT2	!''//0r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     / /D /r   c                    \        4       p\        4       p\        VP                  4       VR7       V P	                  RVP                  4       4       R# )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)r5   r   r   r   r}   rv   )r"   r4   bufs   &  r   
test_distbFailureTests.test_distb  s<      ja""$3/ 	gs||~.r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     

 

4 

r   c                    \        4       p\        P                  ! \        4      pV P	                  \        V4      RV: R24       R# )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)r5   r   fullyQualifiedNamer   rB   r   )r"   r4   typeNames   &  r   	test_reprFailureTests.test_repr  s8    
  --.?@GJRT	
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s      t r   c                    \        4       pVP                  Vn        V P                  4       pV P                  \	        V4      ^8  4       VRR  F  pV P                  RVR,          4       K  	  R# )z<
C{Failure.stack} is gettable and settable, but depreacted.
NzFtwisted.python.failure.Failure.stack was deprecated in Twisted 24.10.0message)r5   r   flushWarningsrb   lenrB   )r"   r4   warningsws   &   r   test_stackDeprecation"FailureTests.test_stackDeprecation  sb      ''%%'H*+"#AX) r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     ' 'd 'r   c                   \        R4      p\        P                  ! V4      P                  P	                  4       p\        P                  P                  V4      pV P                  V\        P                  4       VP                  P	                  4       pV P                  VP                  R4      ^,           VP                  R4      4       V P                  W$4       R# )zM
C{Failure._withoutTraceback(exc)} gives the same result as
C{Failure(exc)}.
hellorw   N)	r   r   r2   __dict__copy_withoutTracebackassertIsInstancerB   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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;     s     0 0d 0r   c                P   \        R4      p\        P                  ! V4      pV P                  V4       \        P                  P	                  V4      pV P                  V4        \        R4      h  \
         d    \        P                  ! 4       p Mi ; iT P                  T4       R# )zU
C{Failure(exc)} and C{Failure._withoutTraceback(exc)} can be pickled
and unpickled.
r'  booN)r   r   r2   assertPicklingRoundtripsr*  r1   )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                    V ^8  d   QhRRRR/# )r   original_failurer-   r   r:   r   )r   s   "r   r   r;   /  s     C C CT Cr   c                D   \         P                  ! \         P                  ! V4      4      pVP                  P	                  4       p^VR&   RVR&   VP                  P	                  4       pV P                  W44       V P                  VP                  VP                  4       R# )zc
The failure can be pickled and unpickled, and the C{parents} attribute
is included in the pickle.
rx   Nrm   )pickleloadsdumpsr(  r)  rB   r   )r"   r<  r/  r   results   &&   r   r6  %FailureTests.assertPicklingRoundtrips/  s    
 <<-= >?#,,113""'')**:*A*ABr   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   <  s     A AT Ar   c                    \         P                  ! \        R4      4      pV P                  VP	                  4       R,          VP
                  4       R# )z/
C{Failure.parents} is included in the pickle.
r'  parentsN)r   r2   r   rB   __getstate__rE  r   s   & r   #test_failurePicklingIncludesParents0FailureTests.test_failurePicklingIncludesParents<  s8     OO/89))4aii@r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   C  s     H HT Hr   c                @   \         P                  ! \        4       4      pVP                  R,          Vn        \        P
                  ! \        P                  ! V4      4      pVP                  RR Vn        V P                  VP                  VP                  RR 4       R# )z?
C{Failure.frames} can be set, both before and after pickling.
NNNNr   )r   r2   r5   r   r>  r?  r@  rB   r"   r<  r/  s   &  r   test_settableFrames FailureTests.test_settableFramesC  sw     #??+=+?@"2"9"9!"<<<-= >?"//#2.*:*A*A#2*FGr   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r;   M  s     	/ 	/d 	/r   c                    \         P                  ! \        R4      4      pVP                  R,          Vn        \        P
                  ! \        P                  ! V4      4      pVP                  R,          Vn        R# )z[
C{Failure.parents} can be set, both before and after pickling.

This is used by Foolscap.
r'  rK  N)r   r2   r   rE  r>  r?  r@  rL  s   &  r   test_settableParents!FailureTests.test_settableParentsM  sX     #??+>w+GH#3#;#;A#> <<-= >?#++A.r   r   N)FF)F),r%   r&   r'   r(   r)   rE   rO   rW   r[   rd   rj   ro   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#  r1  r9  r6  rG  rM  rQ  r*   r   r   r   r7   r7   6   s    
6,	++ 	W	S(JX&GP,G\'$&746J
%S-
L7
M
-	-	2 	1/

'"0,CAH	/ 	/r   r7   c                  &    ] tR tRtRtR R ltRtR# )	BrokenStriY  zV
An exception class the instances of which cannot be presented as strings
via L{str}.
c                   V ^8  d   QhRR/# r   r   r_   r   )r   s   "r   r   BrokenStr.__annotate___  s       r   c                	    V hr   r   r   s   &r   __str__BrokenStr.__str___  s    
r   r   Nr%   r&   r'   r(   r)   rY  r*   r   r   r   rT  rT  Y  s    
 r   rT  c                  &    ] tR tRtRtR R ltRtR# )BrokenExceptionMetaclassid  zU
A metaclass for an exception type which cannot be presented as a string via
L{str}.
c                   V ^8  d   QhRR/# rV  r   )r   s   "r   r   %BrokenExceptionMetaclass.__annotate__j  s     @ @ @r   c                	    \        R 4      h)z#You cannot make a string out of me.)rI   r   s   &r   rY   BrokenExceptionMetaclass.__str__j  s    >??r   r   Nr[  r   r   r   r]  r]  d  s    
@ @r   r]  c                      ] tR tRtRtRtR# )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   rc  rc  n  s    r   rc  )	metaclassc                  z    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltRtR# )GetTracebackTestsiv  z$
Tests for L{Failure.getTraceback}.
c                    V ^8  d   QhRRRR/# r   r   r_   r   r:   r   )r   s   "r   r   GetTracebackTests.__annotate__{  s     	. 	.s 	.t 	.r   c                    \        4       p\        P                  ! V4      pVP                  VR7      pV P	                  V\
        4       R# )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)rT  r   r2   getTracebackr+  r_   )r"   r   xr4   r   s   &&   r   _brokenValueTest"GetTracebackTests._brokenValueTest{  s9     KOOANN&N1	i-r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri    s     ' 'T 'r   c                (    V P                  R4       R# )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rm  r   s   &r   test_brokenValueBriefDetail-GetTracebackTests.test_brokenValueBriefDetail  s     	g&r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri         ) )t )r   c                (    V P                  R4       R# )I
Like test_brokenValueBriefDetail, but for the C{"default"} detail case.
defaultNrr  r   s   &r   test_brokenValueDefaultDetail/GetTracebackTests.test_brokenValueDefaultDetail       	i(r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri    rv  r   c                (    V P                  R4       R# )rx  verboseNrr  r   s   &r   test_brokenValueVerboseDetail/GetTracebackTests.test_brokenValueVerboseDetail  r|  r   c                    V ^8  d   QhRRRR/# rh  r   )r   s   "r   r   ri    s     . .c .d .r   c                    \         P                  ! \        4       4      pVP                  VR7      pV P	                  V\
        4       R# )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   r2   rc  rk  r+  r_   )r"   r   r4   r   s   &&  r   _brokenTypeTest!GetTracebackTests._brokenTypeTest  s6     OO/12NN&N1	i-r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri    s     	& 	&D 	&r   c                (    V P                  R4       R# )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.
rq  Nr  r   s   &r   test_brokenTypeBriefDetail,GetTracebackTests.test_brokenTypeBriefDetail  s     	W%r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri         ( (d (r   c                (    V P                  R4       R# )zH
Like test_brokenTypeBriefDetail, but for the C{"default"} detail case.
ry  Nr  r   s   &r   test_brokenTypeDefaultDetail.GetTracebackTests.test_brokenTypeDefaultDetail       	Y'r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   ri    r  r   c                (    V P                  R4       R# )zH
Like test_brokenTypeBriefDetail, but for the C{"verbose"} detail case.
r  Nr  r   s   &r   test_brokenTypeVerboseDetail.GetTracebackTests.test_brokenTypeVerboseDetail  r  r   r   N)r%   r&   r'   r(   r)   rm  rs  rz  r  r  r  r  r  r*   r   r   r   rf  rf  v  s4    	.')).	&(( (r   rf  c                  B    ] tR tRtRt]! ]RJ R4      R R l4       tRtR# )FindFailureTestsi  z@
Tests for functionality related to identifying the C{Failure}.
Nzraiser extension not availablec                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   FindFailureTests.__annotate__  s     > > >r   c                    \         P                  ! 4        V P                  R4       R#   \         P                   dH    \        P
                  ! 4       pT P                  TP                  \         P                  4      4        R# i ; i)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   r2   rb   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  r*   r   r   r   r  r    s'     FdN<=> >>r   r  c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   fnr_   r   intnametextr:   r   r   r   )r   s   "r   r   r     s/     * *C * *C *t * *r   c                    \        WV4      # r   r   )r  r   r  r  s   &&&&r   _tbr    s    D))r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   &FormattableTracebackTests.__annotate__  s     
 
$ 
r   c           	         \         P                  ! RR^{/ / ..4      pV P                  \        P                  ! V4      \        R^{RR4      .4       R# )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.pyN)r   
_TracebackrB   r   r   r  r"   rm   s   & r   test_singleFrame*FormattableTracebackTests.test_singleFrame  sP     (M3B!G HI 	  $s=#x'N&O	
r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r    s     
 
 
r   c           
     D   \         P                  ! RR^{/ / .RR^/ / ..4      pV P                  \        P                  ! V4      \        R^{RR4      \        R^RR4      .4       V P                  \        P                  ! VP                  4      \        R^{RR4      .4       R# )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.
method1r  method2N)r   r  rB   r   r   r  extract_stacktb_framer  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   N)r%   r&   r'   r(   r)   r  r  r*   r   r   r   r  r    s    

 
r   r  c                  >    ] tR tRtRtR R ltR R ltR R ltR	tR
# )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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r    FakeAttributesTests.__annotate__  s     #9 #9$ #9r   c                z   \         P                  ! RR4      pR^*/pR^d/p\         P                  ! RR^*VV3V4      pV P                  VP                  V4       V P                  VP                  V4       V P                  VP                  \         P                  4       V P                  VP                  V4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  ^*4       V P                  VP                  \        R4      4       R# )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.
N	local_var
global_var	dummynamedummyfilename)dummyparentdummyparentfileo   NN)r   _FramerB   	f_globalsf_localsr+  f_code_Codef_back
f_builtinsdictf_lastir  f_linenof_tracerC   )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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r  ;  s     : : :r   c                l   \         P                  ! RR4      pV P                  VP                  R4       V P                  VP                  R4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                  \        4       V P                  VP                   \        4       V P                  VP"                  \        4       V P                  VP$                  \        4       V P                  VP&                  \        4       V P                  VP(                  \        4       V P                  VP*                  \        4       V P                  VP,                  \.        4       V P                  VP1                  4       \        4       R# )>
See L{FakeAttributesTests} for more details about this test.
r  r  N)r   r  rB   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                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r  R  s     = = =r   c                P   \         P                  ! RR^*/ / 3R4      p\         P                  ! V4      pV P                  VP                  V4       V P                  VP
                  ^*4       V P                  VP                  \        4       V P                  \        VR4      4       R# )r  r  r  Ntb_next)r   r  _TracebackFramerB   r  	tb_linenor+  tb_lastir  rb   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   N)	r%   r&   r'   r(   r)   r  r  r  r*   r   r   r   r  r    s    #9J:.= =r   r  c                  >    ] tR tRtRtR R ltR R ltR R ltR	tR
# )DebugModeTestsia  z>
Failure's debug mode should allow jumping into the debugger.
c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   DebugModeTests.__annotate__f  s     ! !t !r   c                   a aa \         P                  o\        P                  P                  oR VV3R llpS P                  V4       . S n        RR V 3R lllpV\         n        \        P                  ! 4        R# )z;
Override pdb.post_mortem so we can make sure it's called.
c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   *DebugModeTests.setUp.<locals>.__annotate__n  s     	0 	0 	0r   c                 H   < S\         n        S \        P                  n        R # r   )pdbpost_mortemr   r2   __init__)origInitr  s   r   restore%DebugModeTests.setUp.<locals>.restoren  s    )CO'/GOO$r   Nc                    V ^8  d   QhRRRR/# )r   tzTracebackType | Noner   r:   r   )r   s   "r   r   r  v  s     	" 	"#7 	"4 	"r   c                >   < SP                   P                  V 4       R # r   )rA  append)r  r"   s   &r   logging_post_mortem1DebugModeTests.setUp.<locals>.logging_post_mortemv  s    KKq!r   r   )r  r  r   r2   r  
addCleanuprA  startDebugMode)r"   r  r  r  r  s   f  @@r   setUpDebugModeTests.setUpf  s[    
 oo??++	0 	0 	 24	" 	" . r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r  |  s     ( (T (r   c                    ^^ ,           V P                  V P                  X.4       V P                  XP                  4       R#   \          d1    \        P                  ! 4       w  rp\        P                  ! 4       p Lti ; i)zf
If startDebugMode() is called, calling Failure() will first call
pdb.post_mortem with the traceback.
N)	r1   r   r   r   r2   rB   rA  assertFalser+   r"   typr-  rm   r4   s   &    r   test_regularFailure"DebugModeTests.test_regularFailure|  sd    
	"E 	rd+'	  	"<<>LCb!A	"s   	A 8B ?B c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r    s     ' '$ 'r   c                
    ^^ ,           V P                  V P                  X.4       V P                  XP                  4       R#   \          d3    \        P                  ! 4       w  rp\        P                  ! RR7      p Lvi ; i)zS
If startDebugMode() is called, passing captureVars to Failure() will
not blow up.
Tr0   N)	r1   r   r   r   r2   rB   rA  rb   r+   r  s   &    r   test_captureVarsDebugModeTests.test_captureVars  sd    
	2E 	rd+&	  	2<<>LCbD1A	2s   	A :BB)rA  N)	r%   r&   r'   r(   r)   r  r  r  r*   r   r   r   r  r  a  s    !,(' 'r   r  c                  V    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	Rt
R# )ExtendedGeneratorTestsi  zM
Tests C{failure.Failure} support for generator features added in Python 2.5
c               $    V ^8  d   QhRRRRRR/# )r   r4   r-   gzGenerator[Any, Any, Any]r   r:   r   )r   s   "r   r   #ExtendedGeneratorTests.__annotate__  s)     Y Y Y%=Y	Yr   c                	p     VP                  V4       V P                  R 4       R#   \         d     R# i ; i)z<throwExceptionIntoGenerator should have raised StopIterationN)throwExceptionIntoGeneratorr  StopIteration)r"   r4   r  s   &&&r   _throwIntoGenerator*ExtendedGeneratorTests._throwIntoGenerator  s9    	Y))!, IIWX  		s   & 55c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r     s     M M$ Mr   c                  a a . oR V V3R llpV! 4       p\        4       p\        V4       S P                  W24       S P                  S^ ,          ^ ,          \        4       S P                  S^ ,          ^,          \        4       S P                  \        P                  ! S^ ,          ^,          4      R,          R,          R4       R# )zZ
It should be possible to throw the exception that a Failure
represents into a generator.
c                   V ^8  d   QhRR/# r   r   zGenerator[None, None, None]r   )r   s   "r   r   MExtendedGeneratorTests.test_throwExceptionIntoGenerator.<locals>.__annotate__  s     	B 	B6 	Br   c               3     <"    R x  S P                  R4       R #   \         d)    SP                  \        P                  ! 4       4        R # i ; i5i)Nz$Yield should have yielded exception.)r  r1   r
  r   r   )r"   stuffs   r   	generatorJExtendedGeneratorTests.test_throwExceptionIntoGenerator.<locals>.generator  s@     B 		@A ! -S\\^,-%   A A/AAAAr   Nr   )r5   nextr$  rB   r   r+  r   r   )r"   r-  r  r4   r,  s   f   @r    test_throwExceptionIntoGenerator7ExtendedGeneratorTests.test_throwExceptionIntoGenerator  s    
 	B 	B K Q  &q!&78eAhqk+<=--eAhqk:2>rBGLr   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r     s     "8 "8d "8r   c                (  a a \        4       pVP                  4        VP                  4       p. oR VV 3R llpV! 4       p\        V4       S P	                  W4       S P                  \        S4      ^4       S P                  W!P                  4       4       S P                  S^ ,          P                  4       VP                  4       4       S P                  RS^ ,          P                  4       4       S P                  RVP                  4       4       R# )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                   V ^8  d   QhRR/# r)  r   )r   s   "r   r   YExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure.<locals>.__annotate__  s     	< 	<6 	<r   c               3     <"    R x  SP                  R4       R #   \         d)    S P                  \        P                  ! 4       4        R # i ; i5i)NzNo exception sent to generator)r  r1   r
  r   r2   )newFailuresr"   s   r   r-  VExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure.<locals>.generator  sB     < 		:; ! 6""7??#456r/  r-  N)
r5   rr   rk  r0  r$  rB   r   r|   r}   assertNotIn)r"   r4   original_failure_strr-  r  r8  s   f    @r   ,test_failureConstructionFindsOriginalFailureCExtendedGeneratorTests.test_failureConstructionFindsOriginalFailure  s      	 ~~/	< 	< KQ  &[)1- 	-~~/?@ 	KN7791>>;KLk;q>#>#>#@Aann&67r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r     s     ' '$ 'r   c                t   a  R V 3R llpV! 4       p\        V4       \        4       pS P                  W24       R# )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                   V ^8  d   QhRR/# r)  r   )r   s   "r   r   MExtendedGeneratorTests.test_ambiguousFailureInGenerator.<locals>.__annotate__  s     	K 	K6 	Kr   c               3     <"     R x  R #   \          d    . ^,            R # i ; i  \          d8    S P                  \        P                  ! 4       P                  \
        4        R # i ; i5ir   )r1   r+  r   r2   rS   
IndexErrorr   s   r   r-  JExtendedGeneratorTests.test_ambiguousFailureInGenerator.<locals>.generator  sX     K$ qEE  K%%goo&7&=&=zJKs:   A, A,$' A,$' >A)%A,(A))A,N)r0  r5   r$  r"   r-  r  r4   s   f   r    test_ambiguousFailureInGenerator7ExtendedGeneratorTests.test_ambiguousFailureInGenerator  s5    	K 	K KQ   &r   c                   V ^8  d   QhRR/# r9   r   )r   s   "r   r   r     s     G GD Gr   c                    R R lpV! 4       p\        V4       \        4       p V P                  W24       R#   \         d8    T P	                  \
        P                  ! 4       P                  \        4        R# i ; i)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                   V ^8  d   QhRR/# r)  r   )r   s   "r   r   OExtendedGeneratorTests.test_ambiguousFailureFromGenerator.<locals>.__annotate__  s     	 	6 	r   c               3  N   "    R x  R #   \          d    . ^,            R # i ; i5ir   )r1   r   r   r   r-  LExtendedGeneratorTests.test_ambiguousFailureFromGenerator.<locals>.generator  s$       1s   %
 %"%"%N)	r0  r5   r$  r1   r+  r   r2   rS   rC  rE  s   &   r   "test_ambiguousFailureFromGenerator9ExtendedGeneratorTests.test_ambiguousFailureFromGenerator  sa    	 KQ 	G$$Q* 	G!!'//"3"9"9:F	Gs   7 >A98A9r   N)r%   r&   r'   r(   r)   r$  r1  r<  rF  rN  r*   r   r   r   r  r    s*    YM2"8H'*G G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   r5   r7   rT  rC   r]  rc  rf  r  r  r  r  r  r  r   r   r   <module>rY     s    #  
  	 
    "  ' '  / + 6
) 
e "`/& `/F	 @t @)/G C(+ C(L>* >2*1
 3 1
hQ=- Q=h3'( 3'ltG0 tGr   