
    ;e%                        	 d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlT d dlm	Z	 d dl
mZ d dlZ G d dej                  Z G d dej                  Z G d	 d
ej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d de          Z G d dej                  Z G d d          Z G d deej                  Z G d d          Z G d deej                  Z G d deej                  Z G d d ej                  Z G d! d"ej                  Zed#k    r ej                     dS dS )$    N)*)support)	os_helperc                        e Zd Zd Zd Zd ZdS )TestAbstractContextManagerc                      G d dt                     } |            }|                     |                                |           d S )Nc                        e Zd Z fdZ xZS );TestAbstractContextManager.test_enter.<locals>.DefaultEnterc                 4     t                      j        |  d S Nsuper__exit__selfargs	__class__s     +/usr/lib/python3.11/test/test_contextlib.pyr   zDTestAbstractContextManager.test_enter.<locals>.DefaultEnter.__exit__         $''''    __name__
__module____qualname__r   __classcell__r   s   @r   DefaultEnterr
      8        ( ( ( ( ( ( ( ( (r   r   )AbstractContextManagerassertIs	__enter__)r   r   managers      r   
test_enterz%TestAbstractContextManager.test_enter   s`    	( 	( 	( 	( 	(1 	( 	( 	( ,..g''))733333r   c                      G d dt                     }|                     t                    5   |             d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )ETestAbstractContextManager.test_exit_is_abstract.<locals>.MissingExitNr   r   r    r   r   MissingExitr&              Dr   r)   )r   assertRaises	TypeError)r   r)   s     r   test_exit_is_abstractz0TestAbstractContextManager.test_exit_is_abstract   s    	 	 	 	 	0 	 	 	 y)) 	 	KMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA
A
c                     G d d          }|                      t          |t                                G d dt                    }|                      t          |t                                G d d|          }|                     t          |t                                G d d|          }|                     t          |t                               d S )	Nc                       e Zd Zd Zd ZdS )RTestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratchc                     | S r   r(   r   s    r   r!   z\TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__enter__#       r   c                     d S r   r(   )r   exc_type	exc_value	tracebacks       r   r   z[TestAbstractContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__exit__%   s    tr   Nr   r   r   r!   r   r(   r   r   ManagerFromScratchr0   "   s2              r   r9   c                        e Zd Z fdZ xZS )LTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEnterc                 4     t                      j        |  d S r   r   r   s     r   r   zUTestAbstractContextManager.test_structural_subclassing.<locals>.DefaultEnter.__exit__+   r   r   r   r   s   @r   r   r;   *   r   r   r   c                       e Zd ZdZdS )GTestAbstractContextManager.test_structural_subclassing.<locals>.NoEnterNr   r   r   r!   r(   r   r   NoEnterr>   0   s        IIIr   r@   c                       e Zd ZdZdS )FTestAbstractContextManager.test_structural_subclassing.<locals>.NoExitNr   r   r   r   r(   r   r   NoExitrB   5   s        HHHr   rD   )
assertTrue
issubclassr   assertFalse)r   r9   r   r@   rD   s        r   test_structural_subclassingz6TestAbstractContextManager.test_structural_subclassing!   s2   	 	 	 	 	 	 	 	 	
#57MNNOOO	( 	( 	( 	( 	(1 	( 	( 	( 	
<1GHHIII	 	 	 	 	( 	 	 	 	G-CDDEEE	 	 	 	 	' 	 	 	 	F,BCCDDDDDr   N)r   r   r   r#   r-   rH   r(   r   r   r   r      sF        4 4 4  E E E E Er   r   c                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zej        d             Zej        d             Zd Zd Zd Zd ZdS )ContextManagerTestCasec                 (   g t           fd            } |            5 }|                     dg           |                     |d                               |           d d d            n# 1 swxY w Y   |                     g d           d S )Nc               3   h   K                         d           dV                        d           d S N   *     appendstates   r   woohooz@ContextManagerTestCase.test_contextmanager_plain.<locals>.woohoo?   s7      LLOOOHHHLLr   rN   rO   rN   rO   rP   )contextmanagerassertEqualrR   r   rU   xrT   s      @r   test_contextmanager_plainz0ContextManagerTestCase.test_contextmanager_plain=   s    		 	 	 	 
	 VXX 	UQC(((Q###LLOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	-----s   AA//A36A3c                    g t           fd            }|                     t                    5   |            5 }|                     dg           |                     |d                               |           t                      # 1 swxY w Y   	 d d d            n# 1 swxY w Y   |                     g d           d S )Nc               3      K                         d           	 dV                        d           d S #                       d           w xY wrM   rQ   rS   s   r   rU   zBContextManagerTestCase.test_contextmanager_finally.<locals>.woohooL   sT      LLOOO"S!!!!!S!!!!s	   5 ArN   rO   rV   )rW   r+   ZeroDivisionErrorrX   rR   rY   s      @r   test_contextmanager_finallyz2ContextManagerTestCase.test_contextmanager_finallyJ   sB   		" 	" 	" 	" 
	" 011 	* 	* *Q  ,,,  B'''Q')))	* * * * * * * * *	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	-----s/   B$ABB	B$B	B$$B(+B(c                    t           d             }	  |            5  ddz   d d d            n# 1 swxY w Y   n0# t          $ r#}t          j        |j                  }Y d }~nd }~ww xY w|                     t          |          d           |                     |d         j        d           |                     |d         j        d            G d dt                    }	  |            5   |d          # 1 swxY w Y   n+# |$ r#}t          j        |j                  }Y d }~nd }~ww xY w|                     t          |          d           |                     |d         j        d           |                     |d         j        d	            G d
 dt                    }t          d           |d          fD ]$}|                     t          |                    5  	  |            5  |# 1 swxY w Y   	 |                     | d           nN# t          |          $ r9}|                     ||           t          j        |j                  }Y d }~nd }~ww xY w|                     t          |          d           |                     |d         j        d           |                     |d         j        d           d d d            n# 1 swxY w Y   &d S )Nc               3      K   d V  d S r   r(   r(   r   r   fz?ContextManagerTestCase.test_contextmanager_traceback.<locals>.f\         EEEEEr   rN   r   test_contextmanager_traceback1/0c                       e Zd ZdS )RContextManagerTestCase.test_contextmanager_traceback.<locals>.RuntimeErrorSubclassNr'   r(   r   r   RuntimeErrorSubclassrg   k   r*   r   rh   rO   zraise RuntimeErrorSubclass(42)c                       e Zd ZdS )SContextManagerTestCase.test_contextmanager_traceback.<locals>.StopIterationSubclassNr'   r(   r   r   StopIterationSubclassrj   x   r*   r   rk   spamtype was suppressedzraise stop_exc)rW   r^   r7   
extract_tb__traceback__rX   lennamelineRuntimeErrorStopIterationsubTestrn   failr    )r   rb   eframesrh   rk   stop_excs          r   rd   z4ContextManagerTestCase.test_contextmanager_traceback[   s:   		 	 
		;  !                	; 	; 	;)!/::FFFFFF	; 	Va((()HIII///	 	 	 	 	< 	 	 		; / /**2.../ / / / / / / / /# 	; 	; 	;)!/::FFFFFF	; 	Va((()HIII)IJJJ	 	 	 	 	M 	 	 	 &!!!!&))
 	C 	CH 4>>22 C C< ' '&' ' ' ' ' ' ' ' ' II:::;;;;	 H~~ C C CMM!X...&1!/BBFFFFFFC   Va000  1PQQQ  1ABBBC C C C C C C C C C C C C C C		C 	Cs   
: .: 2: 2: 
A'A""A'#
D -C99C==D  C=D D-
D((D-(K*
H4G77G;;H>G;?HKI'./I"K"I''A(KK	"K	c                     t           d             } |            }|                                 |                     |                    t          t	          d          d                      d S )Nc               3      K   d V  d S r   r(   r(   r   r   wheezCContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee   rc   r   foo)rW   r!   rG   r   r,   )r   r~   ctxs      r   test_contextmanager_no_reraisez5ContextManagerTestCase.test_contextmanager_no_reraise   se    		 	 
	dffi51A1A4HHIIIIIr   c                     t           d             } |            }|                                 |                     t          |j        t
          t          d          d            d S )Nc               3   ,   K   	 d V  d S #  d V  Y d S xY wr   r(   r(   r   r   whoozOContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoo   s0      s   
 r   )rW   r!   r+   ru   r   r,   )r   r   r   s      r   *test_contextmanager_trap_yield_after_throwzAContextManagerTestCase.test_contextmanager_trap_yield_after_throw   sl    		 	 
	
 dff#,	9U3C3CT	
 	
 	
 	
 	
r   c                 2    g t            fd            } |            5 }                     dg                                |d                               |           t          d          # 1 swxY w Y                        g d           d S )Nc               3      K                        d           	 dV  d S # t          $ rC}                      | j        d                                        g d           Y d } ~ d S d } ~ ww xY w)NrN   rO   r   rV   )rR   r^   r   rX   )ry   r   rT   s    r   rU   zAContextManagerTestCase.test_contextmanager_except.<locals>.woohoo   s      LLOOO6$ 6 6 6QVAY'''  5555555556s     
A-8A((A-rN   rO   rP   rV   )rW   rX   rR   r^   rY   s   `  @r   test_contextmanager_exceptz1ContextManagerTestCase.test_contextmanager_except   s    		6 	6 	6 	6 	6 
	6 VXX 	)UQC(((Q###LLOOO#C(((		) 	) 	) 	) 	) 	) 	) 	)
 	-----s   AA44A8;A8c                    t           d             } G d dt                    }t          d           |d          fD ]}|                     t          |                    5  	  |            5  |# 1 swxY w Y   	 |                     | d           n-# t
          $ r }|                     ||           Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   d S )Nc               3      K   d V  d S r   r(   r(   r   r   rU   zJContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohoo   rc   r   c                       e Zd ZdS )YContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopIterationSubclassNr'   r(   r   r   rk   r      r*   r   rk   rl   rm   ro   )rW   rv   rw   rn   rx   	Exceptionr    )r   rU   rk   r{   exs        r   #test_contextmanager_except_stopiterz:ContextManagerTestCase.test_contextmanager_except_stopiter   s   		 	 
		 	 	 	 	M 	 	 	 'v..0E0Ef0M0MN 	< 	<H4>>22 < << ' '&' ' ' ' ' ' ' ' '
 II:::;;;; ! 0 0 0MM"h////////0	< < < < < < < < < < < < < < <	< 	<sZ   #C%
B/A22A66B9A6:B>C
C!B<7C<CCC	C	c                    d}i }t          |||           |d         }t          d          }	  |            5  |# 1 swxY w Y   	 |                     d           d S # t          $ r!}|                     ||           Y d }~d S d }~ww xY w)Nztfrom __future__ import generator_stop
from contextlib import contextmanager
@contextmanager
def woohoo():
    yield
rU   rl   zStopIteration was suppressed)execrv   rx   r   r    )r   codelocalsrU   r{   r   s         r   !test_contextmanager_except_pep479z8ContextManagerTestCase.test_contextmanager_except_pep479   s     T66"""! ((	6          
 II455555  	( 	( 	(MM"h'''''''''	(s/   
A ;?A ?A 
B	(BB	c                    t           d             }	  |            5  t          # 1 swxY w Y   n# t          $ rs}|                     t	          |          t
                     |                     |j        d         d           |                     |j	        t                     Y d }~nd }~ww xY w	  |            5  t          d          # 1 swxY w Y   d S # t          $ rn}|                     t	          |          t                     |                     |j        d         d           |                     |j	                   Y d }~d S d }~ww xY w)Nc               3   X   K   	 d V  d S # t           $ r} t          d          | d } ~ ww xY w)Nissue29692:Chained)r   ru   excs    r   test_issue29692zoContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions.<locals>.test_issue29692   sM      B B B B"#788cABs   
 
)$)r   r   zissue29692:Unchained)rW   r^   r   r    rn   ru   rX   r   assertIsInstance	__cause__rv   assertIsNone)r   r   r   s      r   ?test_contextmanager_do_not_unchain_non_stopiteration_exceptionszVContextManagerTestCase.test_contextmanager_do_not_unchain_non_stopiteration_exceptions   s   		B 	B 
	B
	C "" ( (''( ( ( ( ( ( ( ( ( 	C 	C 	CMM$r((L111RWQZ)=>>>!!",0ABBBBBBBB	C
	, "" < <#$:;;;< < < < < < < < < < 	, 	, 	,MM$r((M222RWQZ)?@@@bl+++++++++	,s`   
0 $(0 (0 
B-A)B((B-1
C ;CCC CC 
E"A#EEc                 P    d }t            |d          d                         }|S )Nc                        fd}|S )Nc                 ^                                     D ]\  }}t          | ||           | S r   )itemssetattr)funckvkws      r   decoratezXContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorate   s8    88:: & &CAaD1%%%%r   r(   )r   r   s   ` r   attribszFContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs   s#         Or   bar)r   c                     d S r   r(   )rl   s    r   bazzBContextManagerTestCase._create_contextmanager_attribs.<locals>.baz   s	     Kr   rW   )r   r   r   s      r   _create_contextmanager_attribsz5ContextManagerTestCase._create_contextmanager_attribs   sI    	 	 	 
	U				 	 
	 
	
r   c                     |                                  }|                     |j        d           |                     |j        d           d S )Nr   r   )r   rX   r   r   r   r   s     r   test_contextmanager_attribsz2ContextManagerTestCase.test_contextmanager_attribs   sI    1133e,,,%(((((r   c                 d    |                                  }|                     |j        d           d S NzWhee!r   rX   __doc__r   s     r   test_contextmanager_doc_attribz5ContextManagerTestCase.test_contextmanager_doc_attrib  s1    1133g.....r   c                 v     |                                  d           }|                     |j        d           d S r   r   r   s     r   *test_instance_docstring_given_cm_docstringzAContextManagerTestCase.test_instance_docstring_given_cm_docstring	  s;    3d1133D99g.....r   c                     t           d             } |dddd          5 }|                     |d           d d d            d S # 1 swxY w Y   d S )Nc              3      K   | |||fV  d S r   r(   r   r   r   kwdss       r   rU   z4ContextManagerTestCase.test_keywords.<locals>.woohoo  s!      tT******r         !   ,   r   )r   r   r   r   rW   rX   )r   rU   targets      r   test_keywordsz$ContextManagerTestCase.test_keywords  s    		+ 	+ 
	+V"2B777 	76V%5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   AAAc                       G d d          }t            fd            } | |             |                      5  	 d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )0ContextManagerTestCase.test_nokeepref.<locals>.ANr'   r(   r   r   Ar     r*   r   r   c              3      K   t          j        |           } t          j        |          }t          j                                          |                                             |                       d V  d S r   )weakrefrefr   
gc_collectr   )abr   s     r   rU   z5ContextManagerTestCase.test_nokeepref.<locals>.woohoo  sq      AAAA   aacc"""aacc"""EEEEEr   r   r   )r   r   rU   s   `  r   test_nokeeprefz%ContextManagerTestCase.test_nokeepref  s    	 	 	 	 	 	 	 	 
	 	 	 	 
	 VAACC1133 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                    t           d             }|                     t                    5   |             d d d            n# 1 swxY w Y   |                     t                    5   |dd           d d d            n# 1 swxY w Y   |                     t                    5   |d           d d d            d S # 1 swxY w Y   d S )Nc             3      K   d V  d S r   r(   r   r   s     r   rU   z8ContextManagerTestCase.test_param_errors.<locals>.woohoo(  rc   r         r   )rW   r+   r,   )r   rU   s     r   test_param_errorsz(ContextManagerTestCase.test_param_errors'  s   		 	 
	 y)) 	 	FHHH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	y)) 	 	F1aLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	y)) 	 	FQKKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s5   AA	A'B  BB%B??CCc                      dt            fd            } |            fd                                               d           d S )Nr   c               3   X   K   } dz  d V  dz                       |            d S NrN   )rX   )beforedepthr   s    r   rU   z5ContextManagerTestCase.test_recursive.<locals>.woohoo5  sE       FQJEEEEQJEUF+++++r   c                  ,     dk     r              d S d S )N
   r(   )r   	recursives   r   r   z8ContextManagerTestCase.test_recursive.<locals>.recursive>  s"    rzz	 zr   r   )r   rU   r   r   s   ` @@r   test_recursivez%ContextManagerTestCase.test_recursive3  s    		, 	, 	, 	, 	, 
	, 
	 	 	 	 	 
	 		"""""r   N)r   r   r   r[   r_   rd   r   r   r   r   r   r   r   r   r   requires_docstringsr   r   r   r   r   r   r(   r   r   rJ   rJ   ;   s:       . . .. . ."0C 0C 0CdJ J J
 
 
. . ."< < <$6 6 6*, , ,.  ) ) )
  / / ! /  / / ! /7 7 7  "
 
 
# # # # #r   rJ   c                   :    e Zd Zej        d             Zd Zd ZdS )ClosingTestCasec                 r    t           j        }t          d           }|                     |j        |           d S r   )closingr   rX   r   cm_docstringobjs      r   test_instance_docsz"ClosingTestCase.test_instance_docsI  s4     dmml33333r   c                    g  G fdd          } |            }|                      g            t          |          5 }|                      ||           d d d            n# 1 swxY w Y   |                      dg           d S )Nc                       e Zd Z fdZdS )'ClosingTestCase.test_closing.<locals>.Cc                 2                         d           d S r   rQ   r   rT   s    r   closez-ClosingTestCase.test_closing.<locals>.C.closeS      Qr   Nr   r   r   r   rS   s   r   Cr   R  .                     r   r   rN   )rX   r   r   r   rZ   yrT   s       @r   test_closingzClosingTestCase.test_closingP  s    	  	  	  	  	  	  	  	  	  	  ACC###QZZ 	#1Q"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#$$$$$s   A%%A),A)c                    g  G fdd          } |            }|                      g            |                     t                    5  t          |          5 }|                      ||           ddz   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                      dg           d S )Nc                       e Zd Z fdZdS )-ClosingTestCase.test_closing_error.<locals>.Cc                 2                         d           d S r   rQ   r   s    r   r   z3ClosingTestCase.test_closing_error.<locals>.C.close^  r   r   Nr   rS   s   r   r   r   ]  r   r   r   rN   r   )rX   r+   r^   r   r   s       @r   test_closing_errorz"ClosingTestCase.test_closing_error[  sd   	  	  	  	  	  	  	  	  	  	  ACC###011 	 	 q  A&&&A              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	$$$$$s6   BB9BB			BB		BB #B N)r   r   r   r   r   r   r   r   r(   r   r   r   r   G  sO         4 4 ! 4	% 	% 	%% % % % %r   r   c                       e Zd Zd ZdS )NullcontextTestCasec                      G d d          } |            }t          |          5 }|                     ||           d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )/NullcontextTestCase.test_nullcontext.<locals>.CNr'   r(   r   r   r   r   k  r*   r   r   )nullcontextr    )r   r   cc_ins       r   test_nullcontextz$NullcontextTestCase.test_nullcontextj  s    	 	 	 	 	 	 	 	ACC^^ 	#tMM$"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   AAAN)r   r   r   r  r(   r   r   r   r   i  s#        # # # # #r   r   c                       e Zd Zd ZdS )FileContextTestCasec                    t          j                    }	 d }t          |dd          5 }|                     |j                   |                    d           d d d            n# 1 swxY w Y   |                     |j                   d }|                     t                    5  t          |dd          5 }|                     |j                   | 	                    |
                                d           ddz   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     |j                   t          j        |           d S # t          j        |           w xY w)Nwzutf-8)encodingzBooh
rrN   r   )tempfilemktempopenrG   closedwriterE   r+   r^   rX   readr   unlink)r   tfnrb   s      r   testWithOpenz FileContextTestCase.testWithOpent  s   o	"Ac3111 "Q  ***!!!" " " " " " " " " " " " " " " OOAH%%%A""#455  #sW555 $$QX...$$QVVXXx888EE                            
 OOAH%%%S!!!!!IS!!!!sw   E 0A%E %A))E ,A)-9E &D$9ADD$D	D$D	D$E $D((E +D(,E E5N)r   r   r   r  r(   r   r   r  r  r  s#        " " " " "r   r  c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )LockContextTestCasec                    |                       |                       |5  |                      |                       d d d            n# 1 swxY w Y   |                       |                       |                     t                    5  |5  |                      |                       ddz   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                       |                       d S NrN   r   )rG   rE   r+   r^   )r   locklockeds      r   boilerPlatezLockContextTestCase.boilerPlate  s   """ 	& 	&OOFFHH%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&"""011 	 	  )))A              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"""""sG   A

AAC#B>2C>C	CC	CCCc                 b    t          j                    }|                     ||j                   d S r   )	threadingLockr  r  r   r  s     r   testWithLockz LockContextTestCase.testWithLock  s-    ~t{+++++r   c                 b    t          j                    }|                     ||j                   d S r   )r  RLockr  	_is_ownedr  s     r   testWithRLockz!LockContextTestCase.testWithRLock  s-      t~.....r   c                 d    t          j                    fd}|                     |           d S )Nc                  ,                                      S r   )r   r  s   r   r  z5LockContextTestCase.testWithCondition.<locals>.locked  s    >>###r   )r  	Conditionr  r   r  r  s     @r   testWithConditionz%LockContextTestCase.testWithCondition  sF    "$$	$ 	$ 	$ 	$ 	$v&&&&&r   c                 d    t          j                    fd}|                     |           d S )Nc                  ^                          d          r                                  dS dS NFTacquirereleaser$  s   r   r  z5LockContextTestCase.testWithSemaphore.<locals>.locked  .    ||E"" utr   )r  	Semaphorer  r&  s     @r   testWithSemaphorez%LockContextTestCase.testWithSemaphore  sH    "$$	 	 	 	 	 	v&&&&&r   c                 d    t          j                    fd}|                     |           d S )Nc                  ^                          d          r                                  dS dS r*  r+  r$  s   r   r  z<LockContextTestCase.testWithBoundedSemaphore.<locals>.locked  r.  r   )r  BoundedSemaphorer  r&  s     @r   testWithBoundedSemaphorez,LockContextTestCase.testWithBoundedSemaphore  sH    )++	 	 	 	 	 	v&&&&&r   N)	r   r   r   r  r  r!  r'  r0  r4  r(   r   r   r  r    sn        	# 	# 	#, , ,/ / /' ' '' ' '' ' ' ' 'r   r  c                   (    e Zd Z	 dZdZdZd Zd ZdS )	mycontextFNc                     d| _         | S NTstartedr2   s    r   r!   zmycontext.__enter__  s    r   c                     || _         | j        S r   )r   catchr   r   s     r   r   zmycontext.__exit__  s    zr   )r   r   r   r:  r   r<  r!   r   r(   r   r   r6  r6    sD        CG
CE      r   r6  c                   d    e Zd Zej        d             Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 ZdS )TestContextDecoratorc                 p    t           j        }t                      }|                     |j        |           d S r   )r6  r   rX   r   s      r   r   z'TestContextDecorator.test_instance_docs  s3     !(kkl33333r   c                     t                      }|5 }|                     ||           |                     |j                   d d d            n# 1 swxY w Y   |                     |j        d           d S )NNNN)r6  r    rE   r:  rX   r   )r   contextresults      r   test_contextdecoratorz*TestContextDecorator.test_contextdecorator  s    ++ 	-MM&'***OOGO,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	&899999s   1AAAc                 (   t                      }|                     t          d          5  |5  t          d          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   |                     |j                   |                     |j        d         t                     t                      }d|_        |5  t          d          # 1 swxY w Y   |                     |j                   |                     |j        d         t                     d S )Nr   r   T)r6  assertRaisesRegex	NameErrorassertIsNotNoner   r    r<  )r   rC  s     r   $test_contextdecorator_with_exceptionz9TestContextDecorator.test_contextdecorator_with_exception  s   ++##Iu55 	' 	' ' '&&&' ' ' ' ' ' ' ' '	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	W[)))gk!ni000++ 	# 	#E"""	# 	# 	# 	# 	# 	# 	# 	#W[)))gk!ni00000s>   A=A	AA	AAA7CCCc                      t                       fd            } |                                  j        d           d S )Nc                  p                          j                                        j                   d S r   r   r   rE   r:  rC  r   s   r   testz1TestContextDecorator.test_decorator.<locals>.test  3    gk***OOGO,,,,,r   rB  )r6  rX   r   r   rO  rC  s   ` @r   test_decoratorz#TestContextDecorator.test_decorator  sa    ++		- 	- 	- 	- 	- 
	- 	&899999r   c                 <    t                       fd            }                     t          d          5   |             d d d            n# 1 swxY w Y                        j                                        j        d         t                     d S )Nc                                            j                                        j                   t	          d          )Nr   )r   r   rE   r:  rH  rN  s   r   rO  z@TestContextDecorator.test_decorator_with_exception.<locals>.test  s;    gk***OOGO,,,E"""r   r   r   )r6  rG  rH  rI  r   r    rQ  s   ` @r   test_decorator_with_exceptionz2TestContextDecorator.test_decorator_with_exception  s    ++		# 	# 	# 	# 	# 
	#
 ##Iu55 	 	DFFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	W[)))gk!ni00000s   AAAc                    t                       G fddt                    } |            }|                    dd           |                     |j        d           |                     |j        d           |                     |j        d             |            }|                    ddd           |                     |j        d           |                     |j        d           |                     |j        d            |            }|                    dd           |                     |j        d           |                     |j        d           d S )	Nc                   (    e Zd Z dd            ZdS )9TestContextDecorator.test_decorating_method.<locals>.TestNc                 0    || _         || _        || _        d S r   )r   r   r   )r   r   r   r   s       r   methodz@TestContextDecorator.test_decorating_method.<locals>.Test.method  s    r   r   )r   r   r   rZ  )rC  s   r   TestrX    s3           W  r   r[  rN      r   r   r   r   )r6  objectrZ  rX   r   r   r   )r   r[  rO  rC  s      @r   test_decorating_methodz+TestContextDecorator.test_decorating_method  si   ++	 	 	 	 	 	 	6 	 	 	 tvvAq######&&&tvvCc"""%%%%%%%%%tvva1########r   c                      G d dt                     }|                     t          d          5   |            5  	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd Zd ZdS )7TestContextDecorator.test_typo_enter.<locals>.mycontextc                     d S r   r(   r2   s    r   	__unter__zATestContextDecorator.test_typo_enter.<locals>.mycontext.__unter__"      r   c                     d S r   r(   r=  s     r   r   z@TestContextDecorator.test_typo_enter.<locals>.mycontext.__exit__$  rd  r   N)r   r   r   rc  r   r(   r   r   r6  ra  !  2              r   r6  the context managerContextDecoratorrG  r,   r   r6  s     r   test_typo_enterz$TestContextDecorator.test_typo_enter   s   	 	 	 	 	( 	 	 	 ##I/DEE 	 	                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	3   A AA A	A A	A  A$'A$c                      G d dt                     }|                     t          d          5   |            5  	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd Zd ZdS )6TestContextDecorator.test_typo_exit.<locals>.mycontextc                     d S r   r(   r2   s    r   r!   z@TestContextDecorator.test_typo_exit.<locals>.mycontext.__enter__.  rd  r   c                     d S r   r(   r=  s     r   __uxit__z?TestContextDecorator.test_typo_exit.<locals>.mycontext.__uxit__0  rd  r   N)r   r   r   r!   rr  r(   r   r   r6  ro  -  rf  r   r6  zthe context manager.*__exit__rh  rj  s     r   test_typo_exitz#TestContextDecorator.test_typo_exit,  s   	 	 	 	 	( 	 	 	 ##I/NOO 	 	                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rl  c                       G d dt                     } G d d|t                    } |             fd            } |                                  j        d           d S )Nc                   "    e Zd ZdZdZd Zd ZdS )HTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontextFNc                     d| _         | S r8  r9  r2   s    r   r!   zRTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__enter__=  s    #r   c                     || _         d S r   r   r=  s     r   r   zQTestContextDecorator.test_contextdecorator_as_mixin.<locals>.somecontext.__exit__A      r   )r   r   r   r:  r   r!   r   r(   r   r   somecontextrv  9  s<        GC      r   rz  c                       e Zd ZdS )FTestContextDecorator.test_contextdecorator_as_mixin.<locals>.mycontextNr'   r(   r   r   r6  r|  D  r*   r   r6  c                  p                          j                                        j                   d S r   rM  rN  s   r   rO  zATestContextDecorator.test_contextdecorator_as_mixin.<locals>.testH  rP  r   rB  )r]  ri  rX   r   )r   rz  r6  rO  rC  s   `   @r   test_contextdecorator_as_mixinz3TestContextDecorator.test_contextdecorator_as_mixin8  s    		 		 		 		 		& 		 		 			 	 	 	 	%5 	 	 	 )++		- 	- 	- 	- 	- 
	- 	&899999r   c                      t           fd            }g  |d           fd            } |d                                g d           g  |d                                g d           d S )Nc              3   h   K                        |            d V                       d           d S )NrP   rQ   )r   rT   s    r   rU   zETestContextDecorator.test_contextmanager_as_decorator.<locals>.woohooQ  s7      LLOOOEEELLr   rN   c                 `                         dg                               |            d S r   )rX   rR   )rZ   r   rT   s    r   rO  zCTestContextDecorator.test_contextmanager_as_decorator.<locals>.testX  s.    UQC(((LLOOOOOr   	something)rN   r  rP   something else)rN   r  rP   r   )r   rU   rO  rT   s   `  @r    test_contextmanager_as_decoratorz5TestContextDecorator.test_contextmanager_as_decoratorP  s    		 	 	 	 
	
 		 	 	 	 	 
	 	[ 5 5 5666  : : :;;;;;r   N)r   r   r   r   r   r   rE  rJ  rR  rU  r^  rk  rs  r~  r  r(   r   r   r?  r?    s         4 4 ! 4: : :1 1 1": : :1 1 1$ $ $<	 	 		 	 	: : :0< < < < <r   r?  c                       e Zd ZdZej        d             Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )TestBaseExitStackNc                 |    | j         j        }|                                  }|                     |j        |           d S r   )
exit_stackr   rX   r   s      r   r   z$TestBaseExitStack.test_instance_docsh  s;     .ool33333r   c                 b    |                                  5  	 d d d            d S # 1 swxY w Y   d S r   )r  r2   s    r   test_no_resourcesz#TestBaseExitStack.test_no_resourceso  sy    __ 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   $((c                 ^   di fdi fdi fdt          d          fdt          d          fdt          d          fdt          dd          fg}g fd	}|                                 5 }t          |          D ]h\  }}|r|r |j        |g|R i |}n7|r |j        |g|R  }n&|r |j        |fi |}n|                    |          }|                     ||           i|j        D ]o}|                     |d         j        |           |                     |d         j        |j                   | 	                    |d         j
        |j
                   p	 d d d            n# 1 swxY w Y   |                     |           g |                                 5 }|                     t                    5  |                    d
           d d d            n# 1 swxY w Y   |                     t                    5  | j                            d
           d d d            n# 1 swxY w Y   |                     t                    5  |                    |d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     g            d S )Nr(   )rN   )rN   r\  rN   )exampler      )r   callbackc                  8    	                      | |f           d S r   rQ   )r   r   rD  s     r   _exitz.TestBaseExitStack.test_callback.<locals>._exit~  s"    +MM4,'''''r   )argr\  )r  r  )dictr  reversedr  r    _exit_callbacks__wrapped__assertNotEqualr   r   r   rX   r+   r,   )	r   expectedr  stackr   r   rb   wrapperrD  s	           @r   test_callbackzTestBaseExitStack.test_callbacks  sD   H2JBKa!4???#DOOO$Da!,,,-
 	( 	( 	( 	( 	( __ 	E%&x00 	( 	(
d .D .&u<t<<<t<<AA .&u4t444AA .&u5555AAu--Aa'''' 0 E Egaj4e<<<##GAJ$7HHH!!'!*"4emDDDDE	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	***__ 	6%""9-- & &1%%%& & & & & & & & & & & & & & &""9-- 0 0((Q(///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0""9-- 6 615556 6 6 6 6 6 6 6 6 6 6 6 6 6 6	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	$$$$$s   -C0E**E.1E.!J<GJG#	#J&G#	'JH, J,H0	0J3H0	4JI5)J5I9	9J<I9	=JJJc                     t            fd}d } fd} G d dt                    }                                 5 }|                    |                                |j        d         d         |            ||          }|                    |                                |j        d         d         j        |           |                    |                                |j        d         d         |            ||          }|                    |                                |j        d         d         j        |           |                    |                                |j        d         d         |           |                    |                                |j        d         d         |           ddz   d d d            d S # 1 swxY w Y   d S )	Nc                 4                         |            d S r   )r    )r5   r   exc_tb
exc_raisedr   s      r   _expect_excz0TestBaseExitStack.test_push.<locals>._expect_exc  s    MM(J/////r   c                      dS r8  r(   exc_detailss    r   _suppress_excz2TestBaseExitStack.test_push.<locals>._suppress_exc      4r   c                                          |                                 |                                |           d S r   )r   )r5   r   r  r   s      r   
_expect_okz/TestBaseExitStack.test_push.<locals>._expect_ok  sE    h'''c"""f%%%%%r   c                        e Zd Zd Zd Zd ZdS )+TestBaseExitStack.test_push.<locals>.ExitCMc                     || _         d S r   	check_exc)r   r  s     r   __init__z4TestBaseExitStack.test_push.<locals>.ExitCM.__init__  s    !*r   c                 0    |                      d           d S )NzShould not be called!)rx   r2   s    r   r!   z5TestBaseExitStack.test_push.<locals>.ExitCM.__enter__  s    		122222r   c                      | j         |  d S r   r  r   r  s     r   r   z4TestBaseExitStack.test_push.<locals>.ExitCM.__exit__  s    ,,,,r   Nr   r   r   r  r!   r   r(   r   r   ExitCMr    sA        + + +3 3 3- - - - -r   r  rN   r   )r^   r]  r  pushr    r  __self__)r   r  r  r  r  r  cmr  s   `      @r   	test_pushzTestBaseExitStack.test_push  sE   &
	0 	0 	0 	0 	0 	0	 	 		& 	& 	& 	& 	&	- 	- 	- 	- 	-V 	- 	- 	- __ 	%JJz"""MM%/3A6
CCC
##BJJrNNNMM%/3A6?DDDJJ}%%%MM%/3A6FFF$$BJJrNNNMM%/3A6?DDDJJ{###MM%/3A6DDDJJ{###MM%/3A6DDDaCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   FGG!Gc                     G fddt                     }g  |            }|                                 5 }|j        fd            }|                     |           |                    |           |                     |j        d         d         j        |                               d           d d d            n# 1 swxY w Y   | 	                    g d           d S )Nc                   $    e Zd Z fdZ fdZdS )4TestBaseExitStack.test_enter_context.<locals>.TestCMc                 2                         d           d S r   rQ   )r   rD  s    r   r!   z>TestBaseExitStack.test_enter_context.<locals>.TestCM.__enter__      a     r   c                 2                         d           d S Nr   rQ   )r   r  rD  s     r   r   z=TestBaseExitStack.test_enter_context.<locals>.TestCM.__exit__  r  r   Nr8   rD  s   r   TestCMr    sG        ! ! ! ! !! ! ! ! ! ! !r   r  c                  2                          d           d S )Nr  rQ   r  s   r   r  z3TestBaseExitStack.test_enter_context.<locals>._exit      a     r   r  rN   r\  )rN   r\  r   r  )
r]  r  r  rI  enter_contextr    r  r  rR   rX   )r   r  r  r  r  rD  s        @r   test_enter_contextz$TestBaseExitStack.test_enter_context  sP   	! 	! 	! 	! 	! 	! 	!V 	! 	! 	! VXX__ 	%^! ! ! ! ^!  '''###MM%/3A6?DDDMM!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.....s   A>CCCc                     G d d          } G d d          } G d d          }|                                  5 }|                     t          d          5  |                     |                       d d d            n# 1 swxY w Y   |                     t          d          5  |                     |                       d d d            n# 1 swxY w Y   |                     t          d          5  |                     |                       d d d            n# 1 swxY w Y   |                     |j                   d d d            d S # 1 swxY w Y   d S )Nc                       e Zd ZdS )FTestBaseExitStack.test_enter_context_errors.<locals>.LacksEnterAndExitNr'   r(   r   r   LacksEnterAndExitr    r*   r   r  c                       e Zd Zd ZdS )?TestBaseExitStack.test_enter_context_errors.<locals>.LacksEnterc                     d S r   r(   )r   exc_infos     r   r   zHTestBaseExitStack.test_enter_context_errors.<locals>.LacksEnter.__exit__  rd  r   NrC   r(   r   r   
LacksEnterr    #            r   r  c                       e Zd Zd ZdS )>TestBaseExitStack.test_enter_context_errors.<locals>.LacksExitc                     d S r   r(   r2   s    r   r!   zHTestBaseExitStack.test_enter_context_errors.<locals>.LacksExit.__enter__  rd  r   Nr?   r(   r   r   	LacksExitr    r  r   r  rg  )r  rG  r,   r  rG   r  )r   r  r  r  r  s        r   test_enter_context_errorsz+TestBaseExitStack.test_enter_context_errors  s   	 	 	 	 	 	 	 		 	 	 	 	 	 	 		 	 	 	 	 	 	 	 __ 	4%''	3HII 9 9##$5$5$7$78889 9 9 9 9 9 9 9 9 9 9 9 9 9 9''	3HII 2 2##JJLL1112 2 2 2 2 2 2 2 2 2 2 2 2 2 2''	3HII 1 1##IIKK0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1U2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s}   EB6EB	E	B	
E(CEC	EC	E8D"E"D&	&E)D&	*EEEc                 4   g |                                  5 }|j        fd            }|                     |           |                                                     d           d d d            n# 1 swxY w Y   |                     ddg           d S )Nc                  2                          d           d S r   rQ   r  s   r   r  z+TestBaseExitStack.test_close.<locals>._exit  r  r   r\  rN   )r  r  rI  r   rR   rX   )r   r  r  rD  s      @r   
test_closezTestBaseExitStack.test_close  s    __ 	%^! ! ! ! ^!  '''KKMMMMM!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!Q(((((   AA55A9<A9c                    g |                                  5 }|j        fd            }|                     |           |                                }                    d           d d d            n# 1 swxY w Y                       d           |                                 |                     g d           d S )Nc                  2                          d           d S r  rQ   r  s   r   r  z-TestBaseExitStack.test_pop_all.<locals>._exit  r  r   rN   r\  )rN   r\  r   )r  r  rI  pop_allrR   r   rX   )r   r  r  	new_stackrD  s       @r   test_pop_allzTestBaseExitStack.test_pop_all  s   __ 	%^! ! ! ! ^!  '''IMM!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	a+++++r  c                     |                      t                    5  |                                 5 }|                    d            ddz   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nc                      dS )NFr(   r   s    r   <lambda>z3TestBaseExitStack.test_exit_raise.<locals>.<lambda>  s     r   rN   r   )r+   r^   r  r  r   r  s     r   test_exit_raisez!TestBaseExitStack.test_exit_raise  s    011 	 	"" e

--...!              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s4   A0AA0A	A0A	 A00A47A4c                     |                                  5 }|                    d            ddz   d d d            d S # 1 swxY w Y   d S )Nc                      dS r8  r(   r   s    r   r  z6TestBaseExitStack.test_exit_suppress.<locals>.<lambda>      D r   rN   r   r  r  r  s     r   test_exit_suppressz$TestBaseExitStack.test_exit_suppress  s    __ 	%JJ(()))aCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   >AAc                 `   d }	 |                                  5 }|                    |t                     ddz   d d d            n# 1 swxY w Y   n# t          $ r}|}Y d }~nd }~ww xY w|                     |t                     t	          j        |j                  }dg| j        z   ddgz   }|                     d |D             |           |                     |j	        t                     t	          j        |j	        j                  }|                     d |D             d	g           d S )
Nc                     | r   r(   r   s    r   	raise_exczBTestBaseExitStack.test_exit_exception_traceback.<locals>.raise_exc      Ir   rN   r   )test_exit_exception_tracebackz with self.exit_stack() as stack:)_exit_wrapperzcallback(*args, **kwds))r  z	raise excc                 *    g | ]}|j         |j        fS r(   rs   rt   .0rb   s     r   
<listcomp>zCTestBaseExitStack.test_exit_exception_traceback.<locals>.<listcomp>   s!    111!afaf111r   c                 *    g | ]}|j         |j        fS r(   r  r  s     r   r  zCTestBaseExitStack.test_exit_exception_traceback.<locals>.<listcomp>$  s!    ???q1616*???r   )r  re   )r  r  
ValueErrorr   r7   rp   rq   callback_error_internal_framesrX   __context__r^   )r   r  r  ry   r   	ve_framesr  
zde_framess           r   r  z/TestBaseExitStack.test_exit_exception_traceback  s   	 	 		"" ey*555!                	 	 	CCCCCC	 	c:...():;;	RS/09')) 	 	11y1118	= 	= 	= 	co/@AAA)#/*GHH
??J???BC	E 	E 	E 	E 	Es9   A !AA A

A A
A 
A(A##A(c           	      \    G d d          } G d d          } G d d          }	  |t                     5   |t          t                    5   |            5   |t                    5  ddz   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     d	           n# t           $ rs}|                     |j        t                     |                     |j        j        t                     |                     |j        j        j                   Y d }~nd }~ww xY w|j        d         }|                     |t                     |                     |j        t                     d S )
Nc                        e Zd Zd Zd Zd ZdS )JTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcc                     || _         d S r   r   r=  s     r   r  zSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__init__+  ry  r   c                     | S r   r(   r2   s    r   r!   zTTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__enter__-  r3   r   c                     | j         r   r   r  s     r   r   zSTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExc.__exit__/  s	    hr   Nr  r(   r   r   RaiseExcr  *  sA                r   r  c                        e Zd Zd Zd Zd ZdS )UTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContextc                 "    || _         || _        d S r   )outerinner)r   r  r  s      r   r  z^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__init__3  s    "
"


r   c                     | S r   r(   r2   s    r   r!   z_TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__enter__6  r3   r   c                 *    	 | j         #  | j        xY wr   )r  r  r  s     r   r   z^TestBaseExitStack.test_exit_exception_chaining_reference.<locals>.RaiseExcWithContext.__exit__8  s     %*$%*$s   	 	Nr  r(   r   r   RaiseExcWithContextr  2  sA        # # #  % % % % %r   r  c                       e Zd Zd Zd ZdS )MTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExcc                     | S r   r(   r2   s    r   r!   zWTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__enter__?  r3   r   c                 .    |t          |           _        dS r8  )rn   saved_detailsr  s     r   r   zVTestBaseExitStack.test_exit_exception_chaining_reference.<locals>.SuppressExc.__exit__A  s    +6T

(tr   Nr8   r(   r   r   SuppressExcr  >  s2              r   r  rN   r   0Expected IndexError, but no exception was raised)

IndexErrorKeyErrorAttributeErrorr  rx   r   r  r   r
  r^   )r   r  r  r  r   	inner_excs         r   &test_exit_exception_chaining_referencez8TestBaseExitStack.test_exit_exception_chaining_reference'  s   	 	 	 	 	 	 	 	
	% 
	% 
	% 
	% 
	% 
	% 
	% 
	%	 	 	 	 	 	 	 		J*%% " "((>BB " "$ " "%Xj11 " "EE" " " " " " " " " " " " " " "" " " " " " " " " " " " " " "" " " " " " " " " " " " " " "" " " " " " " " " " " " " " " IIHIIII  	G 	G 	G!!#/8<<<!!#/"=~NNNco9EFFFFFFFF		G  -a0	i444i35FGGGGGs   C$ CB,B,A>	2B>BBBB	B,BB,BB, C,B0	0C3B0	4C7C$ CC$ 
CC$ $
E!.A)EE!c                 4   d }d fd}	 |                                  5 }|                    |t                     |                    |t                     |                    |t                     |                    |           |                    |t                     ddz   d d d            n# 1 swxY w Y   |                     d           n# t          $ rs}|                     |j	        t                     |                     |j	        j	        t                     | 
                    |j	        j	        j	                   Y d }~nd }~ww xY wd         }|                     |t                     |                     |j	        t                     d S )Nc                     | r   r(   r   s    r   r  zATestBaseExitStack.test_exit_exception_chaining.<locals>.raise_excY  r  r   c                      | dS r8  r(   )r  r
  s    r   suppress_exczDTestBaseExitStack.test_exit_exception_chaining.<locals>.suppress_exc]  s    'M4r   rN   r   r  )r  r  r  r  r  r  r  rx   r   r  r   r^   )r   r  r  r  r   r  r
  s         @r   test_exit_exception_chainingz.TestBaseExitStack.test_exit_exception_chainingW  s   	 	 	 	 	 	 	 	
	J"" ey*555y(333y.999

<(((y*555A               IIHIIII  	G 	G 	G!!#/8<<<!!#/"=~NNNco9EFFFFFFFF		G "!$	i444i35FGGGGGs<   C BB4(C 4B88C ;B8<C 
EA)EEc                      G d dt                     t          fd            t           fd            }|fD ]}                                 5  	  |            5  t                      # 1 swxY w Y   	                      d           n,# $ r$}                     |j                   Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   d S )Nc                       e Zd ZdS )PTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.MyExceptionNr'   r(   r   r   MyExceptionr  z  r*   r   r  c               3   d   K   	 d V  d S # t           $ r              } 	 | # d | _        w xY ww xY wr   )BaseExceptionr  )r   r  s    r   my_cmzJTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cm}  s]      +  + + +!kmm+I&*CO****+s    /"	+/c               3      K                                    5 } |                                             | V  d d d            d S # 1 swxY w Y   d S r   )r  r  )r  r  r   s    r   my_cm_with_exit_stackzZTestBaseExitStack.test_exit_exception_explicit_none_context.<locals>.my_cm_with_exit_stack  s      "" e##EEGG,,,                 s   "AAAr  )r   rW   rw   r  rx   r   r  )r   r  r  r   r  r  s   `   @@r   )test_exit_exception_explicit_none_contextz;TestBaseExitStack.test_exit_exception_explicit_none_contextv  s   	 	 	 	 	) 	 	 	 
	+ 	+ 	+ 	+ 
	+ 
	 	 	 	 	 
	
 /0 	R 	RB R RR + +(ll*+ + + + + + + + +
 IIPQQQQ # 7 7 7%%co666666667	R R R R R R R R R R R R R R R	R 	RsZ   C
B"A11A55B8A59B=CB<B72C7B<<CC	C	c                    d }d }	 |                                  5 }|                    d            |                    |t                     d d d            n# 1 swxY w Y   |                     d           n2# t          $ r%}|                     |t                     Y d }~nd }~ww xY w	 |                                  5 }|                    |t                     |                    |           |                    |t                     d d d            n# 1 swxY w Y   |                     d           d S # t          $ r&}|                     |t                     Y d }~d S d }~ww xY w)Nc                     | r   r(   r   s    r   r  zHTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.raise_exc  r  r   c                      dS r8  r(   r  s    r   r  zKTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.suppress_exc  r  r   c                      d S r   r(   r(   r   r   r  zGTestBaseExitStack.test_exit_exception_non_suppressing.<locals>.<lambda>  s    t r   r  z.Expected KeyError, but no exception was raised)r  r  r  rx   r   r   r  r  )r   r  r  r  r   s        r   #test_exit_exception_non_suppressingz5TestBaseExitStack.test_exit_exception_non_suppressing  s   	 	 		 	 		J"" 6e||,,,y*5556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 IIHIIII  	3 	3 	3!!#z22222222	3
	H"" 6ey(333

<(((y*5556 6 6 6 6 6 6 6 6 6 6 6 6 6 6 IIFGGGGG  	1 	1 	1!!#x000000000	1sw   A; 2AA; AA; !A"A; ;
B*B%%B*.D< ADD< DD< !D"D< <
E,E''E,c                    t           d             }t          d          }t          d          }t          d          }t          d          }	 |                                 5 }|                     ||                     |                     ||                     |                     ||                     |# 1 swxY w Y   d S # t          $ r}|                     ||           |                     |j        |           |                     |j        j        |           |                     |j        j        j        |           |                     |j        j        j        j                   Y d }~d S d }~ww xY w)Nc              3       K   	 d V  | # | xY wr   r(   r   s    r   gets_the_context_rightzZTestBaseExitStack.test_exit_exception_with_correct_context.<locals>.gets_the_context_right  s$      	c				s   
 rN   r\  r   r  )rW   r   r  r  r    r  r   )r   r(  exc1exc2exc3exc4r  r   s           r   (test_exit_exception_with_correct_contextz:TestBaseExitStack.test_exit_exception_with_correct_context  s   		 	 
	 ||||||||
	L"" e##$:$:4$@$@AAA##$:$:4$@$@AAA##$:$:4$@$@AAA
	         
  	L 	L 	LMM#t$$$MM#/4000MM#/5t<<<MM#/5A4HHH2>JL L L L L L L L L	Ls8   C "AB??CC CC 
F BE;;F c                    d }t          d          }t          d          }t          d          }t          d          }t          d          }	 |                                 5 }|                    |||           |                    |||           |# 1 swxY w Y   d S # t           $ r}|                     ||           |                     |j        |           |                     |j        j        |           |                     |j        j        j        |           |                     |j        j        j        j        |           |                     |j        j        j        j        j                   Y d }~d S d }~ww xY w)Nc                     	 | # |xY wr   r(   )r  	outer_excs     r   raise_nestedzQTestBaseExitStack.test_exit_exception_with_existing_context.<locals>.raise_nested  s     s    rN   r\  r   r  r   )r   r  r  r    r  r   )	r   r1  r)  r*  r+  r,  exc5r  r   s	            r   )test_exit_exception_with_existing_contextz;TestBaseExitStack.test_exit_exception_with_existing_context  s   	  	  	 
 ||||||||||	Q"" e|T4888|T4888
           	Q 	Q 	QMM#t$$$MM#/4000MM#/5t<<<MM#/5A4HHHMM,8DdL L L+7COQ Q Q Q Q Q Q Q Q	Qs7   B" $1BBB" BB" "
F,CF  Fc                     d }	 |                                  5 }|                    |           ddz   d d d            d S # 1 swxY w Y   d S # t          $ r }|                     d           Y d }~d S d }~ww xY w)Nc                      dS r8  r(   r  s    r   r  zDTestBaseExitStack.test_body_exception_suppress.<locals>.suppress_exc  r  r   rN   r   z%Expected no exception, got IndexError)r  r  r  rx   )r   r  r  r   s       r   test_body_exception_suppressz.TestBaseExitStack.test_body_exception_suppress  s    	 	 		?"" e

<(((!                   	? 	? 	?II=>>>>>>>>>	?s9   A AA AA A	A 
A8A33A8c                     |                                  5 }|                    d            |                    d            |                    d            d d d            d S # 1 swxY w Y   d S )Nc                      dS r8  r(   r   s    r   r  zITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>  r  r   c                      ddz  S r  r(   r   s    r   r  zITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>  s
    AaC r   c                      i d         S r   r(   r   s    r   r  zITestBaseExitStack.test_exit_exception_chaining_suppress.<locals>.<lambda>  s
    BqE r   r  r  s     r   %test_exit_exception_chaining_suppressz7TestBaseExitStack.test_exit_exception_chaining_suppress  s    __ 	+%JJ(()))JJ''(((JJ))***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   AA%%A),A)c                     |                                  5 }t          d          D ]}|                    t                     	 d d d            d S # 1 swxY w Y   d S )Ni'  )r  ranger  int)r   r  is      r   test_excessive_nestingz(TestBaseExitStack.test_excessive_nesting  s    __ 	$%5\\ $ $s####$	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   -AAAc                     G d dt                     } |            }t                      |_        t                      |_        |                                 }|                     t
          d          5  |                    |           d d d            n# 1 swxY w Y   |                    |           |                     |j	        d         d         |           d S )Nc                       e Zd ZdS )7TestBaseExitStack.test_instance_bypass.<locals>.ExampleNr'   r(   r   r   ExamplerC              r   rD  rg  r  rN   )
r]  r!   r   r  rG  r,   r  r  r    r  )r   rD  r  r  s       r   test_instance_bypassz&TestBaseExitStack.test_instance_bypass  s   #####f###WYYxxhh!!##I/DEE 	$ 	$###	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$

2e+B/2B77777s   3BBBc                     G d dt                      G d dt                    }t          fd            }t          d             }|                               5 }|                                 5 }|                     |                       |                     |                        |d          # 1 swxY w Y   	 d d d            n# 1 swxY w Y   |j        }|                     |           |                     |j        |           | 	                    |j        j                   | 	                    |j        j
                   |                     |j
        |j                   d S )Nc                       e Zd ZdS )ITestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueExceptionNr'   r(   r   r   UniqueExceptionrI    rE  r   rJ  c                       e Zd ZdS )LTestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.UniqueRuntimeErrorNr'   r(   r   r   UniqueRuntimeErrorrL    rE  r   rM  c               3   R   K   	 dV  d S # t           $ r}  d          | d } ~ ww xY w)NrN   znew exceptionr   )r   rJ  s    r   secondz@TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.second  sO      @ @ @ @%oo66C?@s    
&!&c               3   <   K   	 dV  d S # t           $ r} | d } ~ ww xY wr   rO  r   s    r   firstz?TestBaseExitStack.test_dont_reraise_RuntimeError.<locals>.first  s<         	s   
 
zplease no infinite loop.)r   ru   rW   r+   r  r  	exceptionr   r  r   r   r    )r   rM  rP  rR  err_ctxes_ctxr   rJ  s          @r   test_dont_reraise_RuntimeErrorz0TestBaseExitStack.test_dont_reraise_RuntimeError  s   .....i...44444444		@ 	@ 	@ 	@ 
	@ 
	 	 
	 // 	E7"" Ef$$VVXX...$$UUWW---(()CDDDE E E E E E E E E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E c?333co/ABBB#/5666#/3444cmS_55555s1   C4AB::B>	>CB>	CCC)r   r   r   r  r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r   r%  r-  r3  r6  r;  r@  rF  rV  r(   r   r   r  r  e  s       J 4 4 ! 4  '% '% '%R     D/ / /&4 4 4&	) 	) 	), , ,    
E E E@.H .H .H`H H H> R  R  RDH H H6L L L>Q Q Q8? ? ?+ + +$ $ $	8 	8 	8 6  6  6  6  6r   r  c                       e Zd ZeZddgZdS )TestExitStack)r   zraise exc_details[1])r   zif cb(*exc_details):N)r   r   r   	ExitStackr  r  r(   r   r   rX  rX  2  s#        J,,&"""r   rX  c                   T    e Zd ZdZdZej        d             Zd Zd Z	d Z
d Zd ZdS )TestRedirectStreamNc                 ~    | j         j        }|                      d           }|                     |j        |           d S r   )redirect_streamr   rX   r   s      r   r   z%TestRedirectStream.test_instance_docs?  s@     +3""4((l33333r   c                     t          t          | j                  }|                     d            |                     t          t          | j                  |           d S r   )getattrsysorig_streamr]  r    )r   orig_stdouts     r   test_no_redirect_in_initz+TestRedirectStream.test_no_redirect_in_initF  sO    c4#344T"""gc4#344kBBBBBr   c                    t          j                    }d}t          t          | j                  }|                     |          5  t          |t          t          | j                             d d d            n# 1 swxY w Y   |                     t          t          | j                  |           |                                	                                }| 
                    ||           d S )Nz<Consider an API like help(), which prints directly to stdoutfile)ioStringIOr_  r`  ra  r]  printr    getvaluestriprX   )r   rb   msgrb  ss        r   test_redirect_to_string_ioz-TestRedirectStream.test_redirect_to_string_ioK  s   KMMLc4#344!!!$$ 	< 	<#GC)9::;;;;	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	< 	<gc4#344kBBBJJLL  C     s   *A;;A?A?c                     t          j                    }|                     |          5 }|                     ||           d d d            d S # 1 swxY w Y   d S r   )rg  rh  r]  r    )r   rb   enter_results      r   test_enter_result_is_targetz.TestRedirectStream.test_enter_result_is_targetU  s    KMM!!!$$ 	+MM,***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+s   AAAc           	      H   t          j                    }|                     |          }t          t          | j                  }|5  t          ddt          t          | j                             d d d            n# 1 swxY w Y   |5  t          dt          t          | j                             d d d            n# 1 swxY w Y   |                     t          t          | j                  |           |                                }| 	                    |d           d S NHello )endrf  zWorld!re  zHello World!

rg  rh  r]  r_  r`  ra  ri  r    rj  rX   r   rb   
write_to_frb  rm  s        r   test_cm_is_reusablez&TestRedirectStream.test_cm_is_reusableZ  s   KMM))!,,
c4#344 	I 	I'sd6F)G)GHHHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	A 	A(d.>!?!?@@@@	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	Agc4#344kBBBJJLL,-----s$   +A<<B B 	*B??CCc           	      H   t          j                    }|                     |          }t          t          | j                  }|5  t          ddt          t          | j                             |5  t          dt          t          | j                             d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t          t          | j                  |           |                                }| 	                    |d           d S rs  rw  rx  s        r   test_cm_is_reentrantz'TestRedirectStream.test_cm_is_reentrantf  s   KMM))!,,
c4#344 	E 	E'sd6F)G)GHHHH E EhWS$2B%C%CDDDDE E E E E E E E E E E E E E E	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	gc4#344kBBBJJLL,-----s6   -B?2*B(B?(B,	,B?/B,	0B??CC)r   r   r   r]  ra  r   r   r   rc  rn  rq  rz  r|  r(   r   r   r[  r[  :  s        OK 4 4 ! 4C C C
! ! !+ + +

. 
. 
.
. 
. 
. 
. 
.r   r[  c                       e Zd ZeZdZdS )TestRedirectStdoutstdoutN)r   r   r   redirect_stdoutr]  ra  r(   r   r   r~  r~  s          %OKKKr   r~  c                       e Zd ZeZdZdS )TestRedirectStderrstderrN)r   r   r   redirect_stderrr]  ra  r(   r   r   r  r  y  r  r   r  c                   ^    e Zd Zej        d             Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
S )TestSuppressc                 p    t           j        }t                      }|                     |j        |           d S r   )suppressr   rX   r   s      r   r   zTestSuppress.test_instance_docs  s3      'jjl33333r   c                     t          t                    5 }|                     |           d d d            d S # 1 swxY w Y   d S r   )r  r  r   )r   rp  s     r   test_no_result_from_enterz&TestSuppress.test_no_result_from_enter  s    j!! 	,\l+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   8<<c                     t          t                    5  |                     t          dd          d           d d d            d S # 1 swxY w Y   d S )Nr\  r       )r  r  rX   powr2   s    r   test_no_exceptionzTestSuppress.test_no_exception  s    j!! 	, 	,SAYY+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   %AAAc                 ~    t          t                    5  t          d           d d d            d S # 1 swxY w Y   d S )Nr   )r  r,   rr   r2   s    r   test_exact_exceptionz!TestSuppress.test_exact_exception  s    i   	 	FFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   266c                 p    t          t                    5  dd          d d d            d S # 1 swxY w Y   d S )Nrt  2   )r  LookupErrorr2   s    r   test_exception_hierarchyz%TestSuppress.test_exception_hierarchy  s}    k"" 	 	BKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   	+//c                     |                      t                    5  t          t                    5  ddz   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  )r+   r^   r  r,   r2   s    r   test_other_exceptionz!TestSuppress.test_other_exception  s    011 	 	)$$  !              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s3   AAAA	A	A	
AA!Ac                     |                      t                    5  t                      5  ddz   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S r  )r+   r^   r  r2   s    r   test_no_argszTestSuppress.test_no_args  s    011 	 	  !              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s1   A<AA 	 AA 	AAAc                     t          t          t                    5  ddz   d d d            n# 1 swxY w Y   t          t          t                    5  t          d           d d d            d S # 1 swxY w Y   d S )NrN   r   r   )r  r^   r,   rr   r2   s    r   test_multiple_exception_argsz)TestSuppress.test_multiple_exception_args  s    '33 	 	aCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'33 	 	FFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   -11A//A36A3c                 t   t          t                    }|5  	 d d d            n# 1 swxY w Y   |5  t          d           d d d            n# 1 swxY w Y   |5  |5  t          d           d d d            n# 1 swxY w Y   d}ddz   d d d            n# 1 swxY w Y   |                     |           d S )Nr   TrN   r   )r  r   rr   rE   )r   ignore_exceptionsouter_continueds      r   r|  z!TestSuppress.test_cm_is_reentrant  s   $Y// 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	FFF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	"  A              "OaCC		 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 	(((((sS   %))AAABA:.B:A>	>BA>	
BBBN)r   r   r   r   r   r   r  r  r  r  r  r  r  r|  r(   r   r   r  r    s         4 4 ! 4, , ,, , ,      
  
  ) ) ) ) )r   r  c                   &    e Zd Zd Zd Zd Zd ZdS )	TestChdirc                     t          j        j        t           j                            t           j                            t
                              g|R  S r   )ospathjoindirnamerealpath__file__)r   partss     r   make_relative_pathzTestChdir.make_relative_path  sF    w|GOOBG,,X6677

 
 
 	
r   c                 l   t          j                    }|                     d          }|                     ||           t	          |          5  |                     t          j                    |           d d d            n# 1 swxY w Y   |                     t          j                    |           d S )Ndata)r  getcwdr  r  chdirrX   )r   old_cwdr   s      r   test_simplezTestChdir.test_simple  s    )++((00GV,,,6]] 	2 	2RY[[&111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2g.....s   (BB	Bc                 \   t          j                    }|                     d          }|                     d          }|                     |||f           t	          |          t	          |          }}|5  |                     t          j                    |           |5  |                     t          j                    |           |5  |                     t          j                    |           d d d            n# 1 swxY w Y   |                     t          j                    |           d d d            n# 1 swxY w Y   |                     t          j                    |           d d d            n# 1 swxY w Y   |                     t          j                    |           d S )Nr  ziptestdata)r  r  r  assertNotInr  rX   )r   r  target1target2chdir1chdir2s         r   test_reentrantzTestChdir.test_reentrant  s&   )++))&11))-887G"4555ww 	3 	3RY[['222 7 7  g666 ; ;$$RY[[':::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;  g666	7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
 RY[['222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	g.....sZ   6*E: *D<
(C>2D<>DD<D*D<0E:<E 	 E:E 	*E::E>E>c                    t          j                    }|                     d          }|                     ||           	 t	          |          5  |                     t          j                    |           t          d          # 1 swxY w Y   n:# t          $ r-}|                     t          |          d           Y d }~nd }~ww xY w|                     t          j                    |           d S )Nr  boom)r  r  r  r  r  rX   ru   str)r   r  r   res       r   test_exceptionzTestChdir.test_exception  s   )++((00GV,,,	.v + +  f555"6***+ + + + + + + + +  	. 	. 	.SWWf--------	.g.....s6    B 7BB

B B
B 
C	#CC	N)r   r   r   r  r  r  r  r(   r   r   r  r    sP        
 
 
/ / // / /"/ / / / /r   r  __main__) rg  r  r`  r	  r  r7   unittest
contextlibrO  r   test.supportr   r   TestCaser   rJ   r   r   r  r  ri  r6  r?  r  rX  r[  r~  r  r  r  r   mainr(   r   r   <module>r     su   ? 				 				 



                     " " " " " " (E (E (E (E (E!2 (E (E (EVI# I# I# I# I#X. I# I# I#X% % % % %h' % % %D# # # # #(+ # # #" " " " "(+ " " "(-' -' -' -' -'(+ -' -' -'`        ]< ]< ]< ]< ]<8, ]< ]< ]<@J6 J6 J6 J6 J6 J6 J6 J6Z    %x'8   6. 6. 6. 6. 6. 6. 6. 6.r    +X->       +X->   4) 4) 4) 4) 4)8$ 4) 4) 4)n,/ ,/ ,/ ,/ ,/! ,/ ,/ ,/^ zHMOOOOO r   