
    ;e0_                     z   d dl Z d dlmZmZmZmZmZmZ d dlZd dl	m
Z
 d dlZd dlZd dlmZ  e
j        d           d Zd Z G d	 d
ej                  Z G d dej                  Z G d dej                  Z G d deej                  Z G d dej                  Zedk    r ej                     dS dS )    N)asynccontextmanagerAbstractAsyncContextManagerAsyncExitStacknullcontextaclosingcontextmanager)support)TestBaseExitStackT)modulec                 F     t          j                    fd            }|S )z5Decorator to turn an async function into a test case.c                  @     | i |}t          j        |           d S N)asynciorun)argskwargscorofuncs      1/usr/lib/python3.11/test/test_contextlib_async.pywrapperz_async_test.<locals>.wrapper   s-    tT$V$$D    )	functoolswraps)r   r   s   ` r   _async_testr      s8    _T     Nr   c                  .    t          j        d            d S r   )r   set_event_loop_policy r   r   tearDownModuler      s    !$'''''r   c                   F    e Zd Zed             Zed             Zd Zd ZdS )TestAbstractAsyncContextManagerc                 &  K    G d dt                     } |            }|                     |                                 d {V |           |4 d {V }|                     ||           d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                        e Zd Z fdZ xZS )@TestAbstractAsyncContextManager.test_enter.<locals>.DefaultEnterc                 D   K    t                      j        |  d {V  d S r   super	__aexit__selfr   	__class__s     r   r'   zJTestAbstractAsyncContextManager.test_enter.<locals>.DefaultEnter.__aexit__   3      'egg'..........r   __name__
__module____qualname__r'   __classcell__r*   s   @r   DefaultEnterr#      8        / / / / / / / / /r   r2   )r   assertIs
__aenter__)r)   r2   managercontexts       r   
test_enterz*TestAbstractAsyncContextManager.test_enter   sE     	/ 	/ 	/ 	/ 	/6 	/ 	/ 	/ ,..G..00000000'::: 	, 	, 	, 	, 	, 	, 	,gMM'7+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   B  
B
B
c                   K   t           d             fd}g }t          d          }|                     t                    5               4 d {V   |            2 3 d {V }|                    |           |6 	 d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     |dg           d S )Nc                    K   d W V  d S r   r   r   r   r   ctxzUTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exit.<locals>.ctx,         EEEEEEr   c                    K                 4 d {V  dW V  d d d           d {V  d S # 1 d {V swxY w Y   d S )N   r   )r;   s   r   genzUTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exit.<locals>.gen0   s      suu                                     s   -
77   r>   )r   
ValueErrorassertRaisesappendassertEqual)r)   r?   retexcvalr;   s        @r   (test_async_gen_propagates_generator_exitzHTestAbstractAsyncContextManager.test_async_gen_propagates_generator_exit(   s      
	 	 
			 	 	 	 	 nnz** 	 	suu        !$       #JJsOOOI "'                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	rd#####sB   B/B A>&B B/
B	B/B	 B//B36B3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 )KTestAbstractAsyncContextManager.test_exit_is_abstract.<locals>.MissingAexitNr-   r.   r/   r   r   r   MissingAexitrK   ?           Dr   rM   )r   rB   	TypeError)r)   rM   s     r   test_exit_is_abstractz5TestAbstractAsyncContextManager.test_exit_is_abstract>   s    	 	 	 	 	6 	 	 	 y)) 	 	LNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	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 )WTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratchc                 
   K   | S r   r   r)   s    r   r5   zbTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__aenter__G   s      r   c                 
   K   d S r   r   )r)   exc_type	exc_value	tracebacks       r   r'   zaTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.ManagerFromScratch.__aexit__I   s      tr   Nr-   r.   r/   r5   r'   r   r   r   ManagerFromScratchrS   F   s2              r   r[   c                        e Zd Z fdZ xZS )QTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.DefaultEnterc                 D   K    t                      j        |  d {V  d S r   r%   r(   s     r   r'   z[TestAbstractAsyncContextManager.test_structural_subclassing.<locals>.DefaultEnter.__aexit__O   r+   r   r,   r1   s   @r   r2   r]   N   r3   r   r2   c                       e Zd ZdZdS )OTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.NoneAenterNr-   r.   r/   r5   r   r   r   
NoneAenterr`   T   s        JJJr   rb   c                       e Zd ZdZdS )NTestAbstractAsyncContextManager.test_structural_subclassing.<locals>.NoneAexitNr-   r.   r/   r'   r   r   r   	NoneAexitrd   Y   s        IIIr   rf   )
assertTrue
issubclassr   assertFalse)r)   r[   r2   rb   rf   s        r   test_structural_subclassingz;TestAbstractAsyncContextManager.test_structural_subclassingE   s2   	 	 	 	 	 	 	 	 	
#57RSSTTT	/ 	/ 	/ 	/ 	/6 	/ 	/ 	/ 	
<1LMMNNN	 	 	 	 	+ 	 	 	 	J0KLLMMM	 	 	 	 	* 	 	 	 	I/JKKLLLLLr   N)r-   r.   r/   r   r8   rH   rP   rj   r   r   r   r    r       sk        	, 	, [	, $ $ [$*  M M M M Mr   r    c                      e Zd Zed             Zed             Zed             Zed             Zed             Zed             Z	ed             Z
ed             Zed	             Zed
             Zed             Zd Zd Zej        d             Zej        ed                         Zed             Zed             Zed             Zed             Zed             ZdS )AsyncContextManagerTestCasec                 P  K   g t           fd            } |            4 d {V }|                     dg           |                     |d                               |           d d d           d {V  n# 1 d {V swxY w Y   |                     g d           d S )Nc                 j   K                         d           dW V                        d           d S N   *     rC   states   r   woohoozEAsyncContextManagerTestCase.test_contextmanager_plain.<locals>.woohood   s9      LLOOOHHHHLLr   rp   rq   rp   rq   rr   )r   rD   rC   r)   rv   xru   s      @r   test_contextmanager_plainz5AsyncContextManagerTestCase.test_contextmanager_plaina   sI     		 	 	 	 
		 688 	 	 	 	 	 	 	qUQC(((Q###LLOOO	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	-----s   AA==
B
Bc                   K   g t           fd            }|                     t                    5   |            4 d {V }|                     dg           |                     |d                               |           t                      # 1 d {V swxY w Y   	 d d d            n# 1 swxY w Y   |                     g d           d S )Nc                    K                         d           	 dW V                        d           d S #                       d           w xY wro   rs   rt   s   r   rv   zGAsyncContextManagerTestCase.test_contextmanager_finally.<locals>.woohoor   sV      LLOOO"S!!!!!S!!!!s	   6 Arp   rq   rw   )r   rB   ZeroDivisionErrorrD   rC   rx   s      @r   test_contextmanager_finallyz7AsyncContextManagerTestCase.test_contextmanager_finallyo   s     		" 	" 	" 	" 
		" 011 	* 	*vxx * * * * * * *1  ,,,  B'''Q')))	* * * * * * * * * * * * * * *	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	-----s0   B2AB
B	B2!B	"B22B69B6c                   K   t           d             }	  |            4 d {V  ddz   d d d           d {V  n# 1 d {V 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                    }	  |            4 d {V   |d          # 1 d {V 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                    } G d dt                    }t          d          t          d           |d           |d          fD ]0}|                     t          |                    5  	  |            4 d {V  |# 1 d {V 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   2d S )Nc                    K   d W V  d S r   r   r   r   r   fzDAsyncContextManagerTestCase.test_contextmanager_traceback.<locals>.f   r<   r   rp   r   test_contextmanager_tracebackz1/0c                       e Zd ZdS )WAsyncContextManagerTestCase.test_contextmanager_traceback.<locals>.RuntimeErrorSubclassNrL   r   r   r   RuntimeErrorSubclassr      rN   r   r   rq   zraise RuntimeErrorSubclass(42)c                       e Zd ZdS )XAsyncContextManagerTestCase.test_contextmanager_traceback.<locals>.StopIterationSubclassNrL   r   r   r   StopIterationSubclassr      rN   r   r   c                       e Zd ZdS )]AsyncContextManagerTestCase.test_contextmanager_traceback.<locals>.StopAsyncIterationSubclassNrL   r   r   r   StopAsyncIterationSubclassr      rN   r   r   spamhamtype was suppressedzraise stop_exc)r   r}   rY   
extract_tb__traceback__rD   lennamelineRuntimeErrorStopIterationStopAsyncIterationsubTestr   failr4   )r)   r   eframesr   r   r   stop_excs           r   r   z9AsyncContextManagerTestCase.test_contextmanager_traceback   sU     		 	 
			;qss        !                            	; 	; 	;)!/::FFFFFF	; 	Va((()HIII///	 	 	 	 	< 	 	 		;qss / / / / / / / /**2.../ / / / / / / / / / / / / / /# 	; 	; 	;)!/::FFFFFF	; 	Va((()HIII)IJJJ	 	 	 	 	M 	 	 		 	 	 	 	); 	 	 	 &!!u%%!!&))&&v..	
 	C 	CH 4>>22 C C< qss ' ' ' ' ' ' ' '&' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 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   A <A 
AA 	A
A 
A;A66A;7D% D
DD%  D!D% %E*EE3L25I3I
II3II3L23J>/J94L29J>>A(L22L6	9L6	c                    K   t           d             } |            }|                                 d {V  |                     |                    t          t	          d          d            d {V            d S )Nc                    K   d W V  d S r   r   r   r   r   wheezHAsyncContextManagerTestCase.test_contextmanager_no_reraise.<locals>.whee   r<   r   foo)r   r5   ri   r'   rO   )r)   r   r;   s      r   test_contextmanager_no_reraisez:AsyncContextManagerTestCase.test_contextmanager_no_reraise   s      		 	 
		dffnns}}Y	%8H8H$OOOOOOOOPPPPPr   c                 6  K   t           d             } |            }|                                 d {V  |                     t                    5  |                    t
          t          d          d            d {V  d d d            d S # 1 swxY w Y   d S )Nc                 0   K   	 d W V  d S #  d W V  Y d S xY wr   r   r   r   r   whoozTAsyncContextManagerTestCase.test_contextmanager_trap_yield_after_throw.<locals>.whoo   s4      s    r   )r   r5   rB   r   r'   rO   r)   r   r;   s      r   *test_contextmanager_trap_yield_after_throwzFAsyncContextManagerTestCase.test_contextmanager_trap_yield_after_throw   s     		 	 
		
 dffnn|,, 	C 	C--	9U+;+;TBBBBBBBBB	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	C 	Cs   0BBBc                    K   t           d             } |            }|                     t                    5  |                                 d {V  d d d            d S # 1 swxY w Y   d S )Nc                 
   K   d S r   r   r   r   r   r   zKAsyncContextManagerTestCase.test_contextmanager_trap_no_yield.<locals>.whoo   s       r   )r   rB   r   r5   r   s      r   !test_contextmanager_trap_no_yieldz=AsyncContextManagerTestCase.test_contextmanager_trap_no_yield   s      		 	 
		 dff|,, 	# 	#.."""""""""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   AA#&A#c                   K   t           d             } |            }|                                 d {V  |                     t                    5  |                    d d d            d {V  d d d            d S # 1 swxY w Y   d S )Nc                    K   d W V  d W V  d S r   r   r   r   r   r   zOAsyncContextManagerTestCase.test_contextmanager_trap_second_yield.<locals>.whoo   s       EEEEEEEEEEr   )r   r5   rB   r   r'   r   s      r   %test_contextmanager_trap_second_yieldzAAsyncContextManagerTestCase.test_contextmanager_trap_second_yield   s      		 	 
		 dffnn|,, 	2 	2--dD111111111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   A<<B B c                   K   t           d             } |            }|                                 d {V  |                     t                    5  |                    t
          d d            d {V  d d d            d S # 1 swxY w Y   d S )Nc                 @   K   	 d W V  d S # t           $ r t          w xY wr   )r   SyntaxErrorr   r   r   r   zLAsyncContextManagerTestCase.test_contextmanager_non_normalised.<locals>.whoo   s;      " " " "!!"s    )r   r5   rB   r   r'   r   r   s      r   "test_contextmanager_non_normalisedz>AsyncContextManagerTestCase.test_contextmanager_non_normalised   s      		" 	" 
		" dffnn{++ 	: 	:--dD999999999	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   #BBBc                 N   K   g t            fd            } |            4 d {V }                     dg                                |d                               |           t          d          # 1 d {V swxY w Y                        g d           d S )Nc                    K                        d           	 dW V  d S # t          $ rC}                      | j        d                                        g d           Y d } ~ d S d } ~ ww xY w)Nrp   rq   r   rw   )rC   r}   r   rD   )r   r)   ru   s    r   rv   zFAsyncContextManagerTestCase.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.rp   rq   rr   rw   )r   rD   rC   r}   rx   s   `  @r   test_contextmanager_exceptz6AsyncContextManagerTestCase.test_contextmanager_except   s     		6 	6 	6 	6 	6 
		6 688 	) 	) 	) 	) 	) 	) 	)qUQC(((Q###LLOOO#C(((		) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)
 	-----s   AA<<
B	Bc                 .  K   t           d             } G d dt                    } G d dt                    }t          d          t          d           |d           |d          fD ]}|                     t	          |                    5  	  |            4 d {V  |# 1 d {V 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                    K   d W V  d S r   r   r   r   r   rv   zOAsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.woohoo  r<   r   c                       e Zd ZdS )^AsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopIterationSubclassNrL   r   r   r   r   r     rN   r   r   c                       e Zd ZdS )cAsyncContextManagerTestCase.test_contextmanager_except_stopiter.<locals>.StopAsyncIterationSubclassNrL   r   r   r   r   r     rN   r   r   r   r   r   r   )r   r   r   r   r   r   	Exceptionr4   )r)   rv   r   r   r   exs         r   #test_contextmanager_except_stopiterz?AsyncContextManagerTestCase.test_contextmanager_except_stopiter  s#     		 	 
			 	 	 	 	M 	 	 		 	 	 	 	); 	 	 	 &!!u%%!!&))&&v..	
 	< 	<H 4>>22 < <<%vxx ' ' ' ' ' ' ' '&' ' ' ' ' ' ' ' ' ' ' ' ' ' '
 II:::;;;; ! 0 0 0MM"h////////0	< < < < < < < < < < < < < < <	< 	<sZ   D	C"B%%
B//C2B/3C7D	
C:C50D	5C::D		D	D	c                   K   t           d             }|                     t                    5   |            4 d {V  ddz   d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     t                    5   |            4 d {V  t          # 1 d {V swxY w Y   	 d d d            d S # 1 swxY w Y   d S )Nc                 `   K   	 d W V  d S # t           $ r} t          d|            | d } ~ ww xY w)Nzcaught )r   r   rF   s    r   rv   zQAsyncContextManagerTestCase.test_contextmanager_wrap_runtimeerror.<locals>.woohoo"  sO      = = = ="?S??33<=s    
-(-rp   r   )r   rB   r   r   )r)   rv   s     r   %test_contextmanager_wrap_runtimeerrorzAAsyncContextManagerTestCase.test_contextmanager_wrap_runtimeerror   sO     		= 	= 
		= |,, 	 	vxx        A                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 122 	) 	)vxx ) ) ) ) ) ) ) )(() ) ) ) ) ) ) ) ) ) ) ) ) ) )	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)sd   A3AA3
A 	 A3#A 	$A33A7:A7C)B11
B;	;C>B;	?CCCc                 P    d }t            |d          d                         }|S )Nc                        fd}|S )Nc                 ^                                     D ]\  }}t          | ||           | S r   )itemssetattr)r   kvkws      r   decoratez]AsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs.<locals>.decorate6  s8    88:: & &CAaD1%%%%r   r   )r   r   s   ` r   attribszKAsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.attribs5  s#         Or   bar)r   c                   K   dW V  dS )Whee!Nr   )r   s    r   bazzGAsyncContextManagerTestCase._create_contextmanager_attribs.<locals>.baz;  s       EEEEEEr   )r   )r)   r   r   s      r   _create_contextmanager_attribsz:AsyncContextManagerTestCase._create_contextmanager_attribs4  sL    	 	 	 
	U				 	 
	 
		 
r   c                     |                                  }|                     |j        d           |                     |j        d           d S )Nr   r   )r   rD   r-   r   r)   r   s     r   test_contextmanager_attribsz7AsyncContextManagerTestCase.test_contextmanager_attribsB  sI    1133e,,,%(((((r   c                 d    |                                  }|                     |j        d           d S Nr   r   rD   __doc__r   s     r   test_contextmanager_doc_attribz:AsyncContextManagerTestCase.test_contextmanager_doc_attribG  s1    1133g.....r   c                    K    |                                  d           }|                     |j        d           |4 d {V  	 d d d           d {V  d S # 1 d {V swxY w Y   d S r   r   r   s     r   *test_instance_docstring_given_cm_docstringzFAsyncContextManagerTestCase.test_instance_docstring_given_cm_docstringL  s      4d1133D99g... 	 	 	 	 	 	 	 		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A
A"%A"c                    K   t           d             } |dddd          4 d {V }|                     |d           d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                   K   | |||fW V  d S r   r   r)   r   r   kwdss       r   rv   z9AsyncContextManagerTestCase.test_keywords.<locals>.woohooW  s$      tT*******r   r>   r@   !   ,   r   )r>   r@   r   r   r   rD   )r)   rv   targets      r   test_keywordsz)AsyncContextManagerTestCase.test_keywordsT  s      
	+ 	+ 
		+6r"=== 	7 	7 	7 	7 	7 	7 	7V%5666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s   A
AAc                     K   ddt            fd            } |            fd                          d {V                       d                                d           d S )Nr   c                 d   K   dz  } dz  d W V  dz                       |            d S Nrp   )rD   )beforedepthncolsr)   s    r   rv   z:AsyncContextManagerTestCase.test_recursive.<locals>.woohoob  sR       QJE FQJEEEEEQJEUF+++++r   c                  <   K    dk     r              d {V  d S d S )N
   r   )r   	recursives   r   r   z=AsyncContextManagerTestCase.test_recursive.<locals>.recursiven  s;      rzzikk!!!!!!!!! zr   r   r   )r)   rv   r   r   r   s   ` @@@r   test_recursivez*AsyncContextManagerTestCase.test_recursive]  s      			, 		, 		, 		, 		, 		, 
			, 
	" 	" 	" 	" 	" 
	" ikk###"""""r   c                     K   dt           fd            } |             fd            }                                 |             d {V                                  d S )NFc                    K   d d W V  d d S NTFr   entereds   r   r7   z;AsyncContextManagerTestCase.test_decorator.<locals>.context|  s"       GEEEEGGGr   c                  6   K                                    d S r   )rg   r   r)   s   r   testz8AsyncContextManagerTestCase.test_decorator.<locals>.test  s      OOG$$$$$r   )r   ri   r)   r7   r   r   s   `  @r   test_decoratorz*AsyncContextManagerTestCase.test_decoratorx  s      		 	 	 	 
		 
	% 	% 	% 	% 	% 
	% 	!!!dff!!!!!r   c                 <   K   dt           fd            } |             fd            }                                                     t          d          5   |             d {V  d d d            n# 1 swxY w Y                                   d S )NFc                 .   K   	 d d W V  d d S # d w xY wr   r   r   s   r   r7   zJAsyncContextManagerTestCase.test_decorator_with_exception.<locals>.context  s2       %s    c                  P   K                                    t          d          )Nr   )rg   	NameErrorr   s   r   r   zGAsyncContextManagerTestCase.test_decorator_with_exception.<locals>.test  s'      OOG$$$E"""r   r   )r   ri   assertRaisesRegexr   r   s   `  @r   test_decorator_with_exceptionz9AsyncContextManagerTestCase.test_decorator_with_exception  s     		  	  	  	  
		  
	# 	# 	# 	# 	# 
	# 	!!!##Iu55 	 	$&&LLLLLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!!!!!s   A<<B B c                   K   t           d              G fddt                    } |            }|                    dd           d {V  |                     |j        d           |                     |j        d           |                     |j        d             |            }|                    ddd           d {V  |                     |j        d           |                     |j        d           |                     |j        d            |            }|                    dd	           d {V  |                     |j        d           |                     |j        d           d S )
Nc                    K   d W V  d S r   r   r   r   r   r7   zCAsyncContextManagerTestCase.test_decorating_method.<locals>.context  r<   r   c                   8    e Zd Z              dd            ZdS )@AsyncContextManagerTestCase.test_decorating_method.<locals>.TestNc                 4   K   || _         || _        || _        d S r   )abc)r)   r  r  r  s       r   methodzGAsyncContextManagerTestCase.test_decorating_method.<locals>.Test.method  s      r   r   )r-   r.   r/   r  )r7   s   r   Testr    s9        WYY   Y  r   r  rp      r  r  r  )r  r  )r   objectr  rD   r  r  r  )r)   r  r   r7   s      @r   test_decorating_methodz2AsyncContextManagerTestCase.test_decorating_method  s      
	 	 
			 	 	 	 	 	 	6 	 	 	 tvvkk!Q######&&&tvvkk#sC(((((((((%%%%%%%%%tvvkkAk#################r   N)r-   r.   r/   r   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r	   requires_docstringsr   r   r   r   r   r   r
  r   r   r   rl   rl   _   s2       . . [. . . [." 5C 5C [5Cn Q Q [Q 
C 
C [
C # # [# 2 2 [2 : : [: . . [." < < [<4 ) ) [)&  ) ) )
  / / ! /    [ !  7 7 [7 # # [#4 " " ["$ " " [", $ $ [$ $ $r   rl   c                   p    e Zd Zej        d             Zed             Zed             Zed             Z	dS )AclosingTestCasec                 r    t           j        }t          d           }|                     |j        |           d S r   )r   r   rD   )r)   cm_docstringobjs      r   test_instance_docsz#AclosingTestCase.test_instance_docs  s3    'tnnl33333r   c                 :  K   g  G fdd          } |            }|                      g            t          |          4 d {V }|                      ||           d d d           d {V  n# 1 d {V swxY w Y   |                      dg           d S )Nc                       e Zd Z fdZdS ))AclosingTestCase.test_aclosing.<locals>.Cc                 6   K                        d           d S r   rs   r)   ru   s    r   aclosez0AclosingTestCase.test_aclosing.<locals>.C.aclose        Qr   Nr-   r.   r/   r  rt   s   r   Cr    .                     r   r  rp   )rD   r   r)   r  ry   yru   s       @r   test_aclosingzAclosingTestCase.test_aclosing  sM     	  	  	  	  	  	  	  	  	  	  ACC###A;; 	# 	# 	# 	# 	# 	# 	#!Q"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#$$$$$s   
A33
A= A=c                   K   g  G fdd          } |            }|                      g            |                     t                    5  t          |          4 d {V }|                      ||           ddz   d d d           d {V  n# 1 d {V 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 )/AclosingTestCase.test_aclosing_error.<locals>.Cc                 6   K                        d           d S r   rs   r  s    r   r  z6AclosingTestCase.test_aclosing_error.<locals>.C.aclose  r  r   Nr  rt   s   r   r  r!    r  r   r  rp   r   )rD   rB   r}   r   r  s       @r   test_aclosing_errorz$AclosingTestCase.test_aclosing_error  s     	  	  	  	  	  	  	  	  	  	  ACC###011 	 	{{       a  A&&&A                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	$$$$$s6   B0%BB0
B	B0 B	!B00B47B4c                   K   g t           fd            fd} |            }|                     g            |                     t                    5  t	          |          4 d {V }|                     ||           |                     d|                                 d {V            ddz   d d d           d {V  n# 1 d {V swxY w Y   d d d            n# 1 swxY w Y   |                     dg           d S )Nc               3   t   K   	 d V                        d           d S #                       d           w xY wr   rs   rt   s   r   sync_resourcez>AclosingTestCase.test_aclosing_bpo41229.<locals>.sync_resource  s<       QQs     7c                 f   K                 5  dW V  dW V  d d d            d S # 1 swxY w Y   d S )Nr   )r&  s   r   agenfuncz9AclosingTestCase.test_aclosing_bpo41229.<locals>.agenfunc  s                         s   &**r(  rp   r   )r   rD   rB   r}   r   	__anext__)r)   r*  ry   r  ru   r&  s       @@r   test_aclosing_bpo41229z'AclosingTestCase.test_aclosing_bpo41229  s     		  	  	  	  
	 	 	 	 	 	
 HJJ###011 	 	{{       a  A&&&  1;;==%8%8%8%8%8%8999A                          	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 	$$$$$s7   C'.A
C
8C'

C	C'C	C''C+.C+N)
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 G d de          ZeZg dZd Zed             Z	ed             Z
ed             Zed             Zed	             Zed
             Zed             ZdS )TestAsyncExitStackc                   6    e Zd Zed             Zd Zd Zd ZdS )%TestAsyncExitStack.SyncAsyncExitStackc                 T   t          j                                                                        |           }|                    fd                                            |                                }|s|                                S |j        }	 |#  ||_        |xY w)Nc                 ,                                     S r   )stop)r   loops    r   <lambda>zETestAsyncExitStack.SyncAsyncExitStack.run_coroutine.<locals>.<lambda>  s    $))++ r   )	r   get_event_loop_policyget_event_loopcreate_taskadd_done_callbackrun_forever	exceptionresult__context__)r   trF   r7   r4  s       @r   run_coroutinez3TestAsyncExitStack.SyncAsyncExitStack.run_coroutine  s    022AACCD  &&A 5 5 5 5666++--C 	xxzz!/I&-COIs   B B'c                 P    |                      |                                           S r   )r?  r  rU   s    r   closez+TestAsyncExitStack.SyncAsyncExitStack.close  s    %%dkkmm444r   c                 P    |                      |                                           S r   )r?  r5   rU   s    r   	__enter__z/TestAsyncExitStack.SyncAsyncExitStack.__enter__  s     %%doo&7&7888r   c                 <    |                       | j        |           S r   )r?  r'   r)   exc_detailss     r   __exit__z.TestAsyncExitStack.SyncAsyncExitStack.__exit__  s    %%ndnk&BCCCr   N)r-   r.   r/   staticmethodr?  rA  rC  rG  r   r   r   SyncAsyncExitStackr0    s_        		 	 
	$	5 	5 	5	9 	9 	9	D 	D 	D 	D 	Dr   rI  ))rG  z7return self.run_coroutine(self.__aexit__(*exc_details))r?  z	raise excrJ  )r'   zraise exc_details[1])r'   zcb_suppress = cb(*exc_details)c                     t          j                    | _        t          j        | j                   |                     | j        j                   |                     t           j        d            d S r   )r   new_event_loopr4  set_event_loop
addCleanuprA  r   rU   s    r   setUpzTestAsyncExitStack.setUp(  sX    *,,	ty)))	(((5t<<<<<r   c           	      n  K   di fdi fdi fdt          d          fdt          d          fdt          d          fg}g fd}t                      4 d {V }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           d {V  n# 1 d {V swxY w Y   |                     |           g t                      4 d {V }|                     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           d {V  n# 1 d {V swxY w Y   |                     g            d S )Nr   )rp   )rp   r  rp   )examplec                  :   K                        | |f           dS )zTest metadata propagationNrs   )r   r   r<  s     r   _exitz5TestAsyncExitStack.test_async_callback.<locals>._exit9  s#      MM4,'''''r   )argr     )callbackrT  )dictr   reversedpush_async_callbackr4   _exit_callbacks__wrapped__assertNotEqualr-   assertIsNoner   rD   rB   rO   
exit_stack)	r)   expectedrS  stackr   r   r   r   r<  s	           @r   test_async_callbackz&TestAsyncExitStack.test_async_callback.  s1      H2JBKa!4???#DOOO$
 	( 	( 	( 	( 	( "## 	E 	E 	E 	E 	E 	E 	Eu&x00 	( 	(
d 9D 911%G$GGG$GGAA 911%?$???AA 911%@@4@@AA11%88A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 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E  	***!## 	A 	A 	A 	A 	A 	A 	Au""9-- 1 1))a)0001 1 1 1 1 1 1 1 1 1 1 1 1 1 1""9-- ; ;333:::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;""9-- A A))5a)@@@A A A A A A A A A A A A A A A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	$$$$$s   C0E  
E*-E*J8GJG	J"G	#J H(J(H,	,J/H,	0JI1%J1I5	5J8I5	9J
JJc                    K   t            fd}d } fd} G d dt                    }                                 4 d {V }|                    |                                |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 {V  d S # 1 d {V swxY w Y   d S )	Nc                 8   K                        |            d S r   )r4   )rW   rF   exc_tb
exc_raisedr)   s      r   _expect_excz7TestAsyncExitStack.test_async_push.<locals>._expect_exc\  s!      MM(J/////r   c                  
   K   dS NTr   )rF  s    r   _suppress_excz9TestAsyncExitStack.test_async_push.<locals>._suppress_exc^  s      4r   c                    K                        |                                 |                                |           d S r   )r]  )rW   rF   rd  r)   s      r   
_expect_okz6TestAsyncExitStack.test_async_push.<locals>._expect_ok`  sI      h'''c"""f%%%%%r   c                        e Zd Zd Zd Zd ZdS )2TestAsyncExitStack.test_async_push.<locals>.ExitCMc                     || _         d S r   	check_exc)r)   rp  s     r   __init__z;TestAsyncExitStack.test_async_push.<locals>.ExitCM.__init__e  s    !*r   c                 4   K   |                      d           d S )NzShould not be called!)r   rU   s    r   r5   z=TestAsyncExitStack.test_async_push.<locals>.ExitCM.__aenter__g  s      		122222r   c                 *   K    | j         |  d {V  d S r   ro  rE  s     r   r'   z<TestAsyncExitStack.test_async_push.<locals>.ExitCM.__aexit__i  s-      $dnk2222222222r   N)r-   r.   r/   rq  r5   r'   r   r   r   ExitCMrm  d  sA        + + +3 3 33 3 3 3 3r   rt  r(  rp   r   )r}   r	  r^  push_async_exitr4   rZ  __self__)r)   rf  ri  rk  rt  r`  cmre  s   `      @r   test_async_pushz"TestAsyncExitStack.test_async_pushY  s     &
	0 	0 	0 	0 	0 	0	 	 		& 	& 	& 	& 	&	3 	3 	3 	3 	3V 	3 	3 	3 ??$$ 	 	 	 	 	 	 	!!*---MM%/3A6
CCC
##B!!"%%%MM%/3A6?DDD!!-000MM%/3A6FFF$$B!!"%%%MM%/3A6?DDD!!+...MM%/3A6DDD!!+...MM%/3A6DDDaCC	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   FG((
G25G2c                   K    G fddt                     }g  |            }t                      4 d {V }|j        fd            }|                     |           |                    |           d {V  |                     |j        d         d         j        |                               d           d d d           d {V  n# 1 d {V swxY w Y   | 	                    g d           d S )Nc                   $    e Zd Z fdZ fdZdS );TestAsyncExitStack.test_enter_async_context.<locals>.TestCMc                 6   K                        d           d S r   rs   )r)   r<  s    r   r5   zFTestAsyncExitStack.test_enter_async_context.<locals>.TestCM.__aenter__        a     r   c                 6   K                        d           d S )NrU  rs   )r)   rF  r<  s     r   r'   zETestAsyncExitStack.test_enter_async_context.<locals>.TestCM.__aexit__  r}  r   NrZ   r<  s   r   TestCMr{    sG        ! ! ! ! !! ! ! ! ! ! !r   r  c                  6   K                         d           d S )N   rs   r  s   r   rS  z:TestAsyncExitStack.test_enter_async_context.<locals>._exit  s      a     r   r(  rp   r  )rp   r  rU  r  )
r	  r   rY  assertIsNotNoneenter_async_contextr4   rZ  rv  rC   rD   )r)   r  rw  r`  rS  r<  s        @r   test_enter_async_contextz+TestAsyncExitStack.test_enter_async_context}  s     	! 	! 	! 	! 	! 	! 	!V 	! 	! 	! VXX!## 	 	 	 	 	 	 	u&! ! ! ! '&!  '''++B/////////MM%/3A6?DDDMM!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	.....s   BC
CCc                   K    G d d          } G d d          } G d d          }|                                  4 d {V }|                     t          d          5  |                     |                       d {V  d d d            n# 1 swxY w Y   |                     t          d          5  |                     |                       d {V  d d d            n# 1 swxY w Y   |                     t          d          5  |                     |                       d {V  d d d            n# 1 swxY w Y   |                     |j                   d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                       e Zd ZdS )MTestAsyncExitStack.test_enter_async_context_errors.<locals>.LacksEnterAndExitNrL   r   r   r   LacksEnterAndExitr    rN   r   r  c                       e Zd Zd ZdS )FTestAsyncExitStack.test_enter_async_context_errors.<locals>.LacksEnterc                 
   K   d S r   r   )r)   exc_infos     r   r'   zPTestAsyncExitStack.test_enter_async_context_errors.<locals>.LacksEnter.__aexit__        r   Nre   r   r   r   
LacksEnterr    #            r   r  c                       e Zd Zd ZdS )ETestAsyncExitStack.test_enter_async_context_errors.<locals>.LacksExitc                 
   K   d S r   r   rU   s    r   r5   zPTestAsyncExitStack.test_enter_async_context_errors.<locals>.LacksExit.__aenter__  r  r   Nra   r   r   r   	LacksExitr    r  r   r  asynchronous context manager)r^  r   rO   r  ri   rZ  )r)   r  r  r  r`  s        r   test_enter_async_context_errorsz2TestAsyncExitStack.test_enter_async_context_errors  s?     	 	 	 	 	 	 	 		 	 	 	 	 	 	 		 	 	 	 	 	 	 	 ??$$ 	4 	4 	4 	4 	4 	4 	4''	3QRR E E//0A0A0C0CDDDDDDDDDE E E E E E E E E E E E E E E''	3QRR > >//

=========> > > > > > > > > > > > > > >''	3QRR = =//		<<<<<<<<<= = = = = = = = = = = = = = =U2333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s~   E4 $BE4B	E4B	E46$C&E4&C*	*E4-C*	.E4$D<0E4<E 	 E4E 	E44
E>E>c                 \  K   d }d fd}	 |                                  4 d {V }|                    |t                     |                    |t                     |                    |t                     |                    |           |                    |t                     ddz   d d d           d {V  n# 1 d {V 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                 
   K   | r   r   r   s    r   	raise_exczHTestAsyncExitStack.test_async_exit_exception_chaining.<locals>.raise_exc  s      Ir   c                     K   | dS rh  r   )rF  saved_detailss    r   suppress_exczKTestAsyncExitStack.test_async_exit_exception_chaining.<locals>.suppress_exc  s      'M4r   rp   r   0Expected IndexError, but no exception was raised)r^  rY  
IndexErrorKeyErrorAttributeErrorru  rA   r   assertIsInstancer=  r]  r}   )r)   r  r  r`  rF   	inner_excr  s         @r   "test_async_exit_exception_chainingz5TestAsyncExitStack.test_async_exit_exception_chaining  sJ     	 	 	 	 	 	 	 	
	J((       E)))Z@@@)))X>>>)))^DDD%%l333)))Z@@@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C0C) 
CC) CC) )
E&3A)E!!E&c                    K    G d dt                     t          fd            t           fd            }|fD ]}                                 5  	  |            4 d {V  t                      # 1 d {V 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 )WTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.MyExceptionNrL   r   r   r   MyExceptionr    rN   r   r  c                 f   K   	 d W V  d S # t           $ r              } 	 | # d | _        w xY ww xY wr   )BaseExceptionr=  )rF   r  s    r   my_cmzQTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.my_cm  s_      +  + + +!kmm+I&*CO****+s    0#	,0c                    K                                    4 d {V } |                                             d {V  | W V  d d d           d {V  d S # 1 d {V swxY w Y   d S r   )r^  r  )r`  r  r)   s    r   my_cm_with_exit_stackzaTestAsyncExitStack.test_async_exit_exception_explicit_none_context.<locals>.my_cm_with_exit_stack  s	     ((       E//888888888                             s   )A
A$'A$r  )r   r   r   r  r   r]  r=  )r)   r  rw  rF   r  r  s   `   @@r   /test_async_exit_exception_explicit_none_contextzBTestAsyncExitStack.test_async_exit_exception_explicit_none_context  s     
	 	 	 	 	) 	 	 	 
	+ 	+ 	+ 	+ 
		+ 
	 	 	 	 	 
		
 /0 	R 	RB R RR!rtt + + + + + + + +(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!*A99
BB!BB!C!C
&C CC

CC	 C	c                   K    G d dt                     } |            }t                      |_        t                      |_        |                                 }|                     t
          d          5  |                    |           d {V  d d d            n# 1 swxY w Y   |                    |           |                     |j	        d         d         |           d S )Nc                       e Zd ZdS )>TestAsyncExitStack.test_instance_bypass_async.<locals>.ExampleNrL   r   r   r   Exampler    s          r   r  r  r(  rp   )
r	  r5   r'   r^  r   rO   r  ru  r4   rZ  )r)   r  rw  r`  s       r   test_instance_bypass_asyncz-TestAsyncExitStack.test_instance_bypass_async  s     #####f###WYYxx!!##I/MNN 	0 	0++B/////////	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0b!!!e+B/2B77777s   5BB!$B!N)r-   r.   r/   r   rI  r^  callback_error_internal_framesrO  r   ra  rx  r  r  r  r  r  r   r   r   r.  r.    s4       D D D D D^ D D D: $J& & &"= = = (% (% [(%T ! ! [!F / / [/* 4 4 [4& H H [H>  R  R [ RD 	8 	8 [	8 	8 	8r   r.  c                   $    e Zd Zed             ZdS )TestAsyncNullcontextc                    K    G d d          } |            }t          |          4 d {V }|                     ||           d d d           d {V  d S # 1 d {V swxY w Y   d S )Nc                       e Zd ZdS )6TestAsyncNullcontext.test_async_nullcontext.<locals>.CNrL   r   r   r   r  r    rN   r   r  )r   r4   )r)   r  r  c_ins       r   test_async_nullcontextz+TestAsyncNullcontext.test_async_nullcontext  s     	 	 	 	 	 	 	 	ACCq>> 	# 	# 	# 	# 	# 	# 	#TMM$"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   A
A#&A#N)r-   r.   r/   r   r  r   r   r   r  r    s-        # # [# # #r   r  __main__)r   
contextlibr   r   r   r   r   r   r   r   r	   unittestrY   test.test_contextlibr
   requires_working_socketr   r   TestCaser    rl   r  r.  r  r-   mainr   r   r   <module>r     s   ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ;                2 2 2 2 2 2  t , , , ,  ( ( (BM BM BM BM BMh&7 BM BM BMJc$ c$ c$ c$ c$("3 c$ c$ c$L9% 9% 9% 9% 9%x( 9% 9% 9%xs8 s8 s8 s8 s8*H,= s8 s8 s8l# # # # #8, # # # zHMOOOOO r   