
    <e                     
   d Z ddlZddlZddlZddlmZ ddlZddlmZ d Z	 G d d          Z
 G d d	ej                  Z G d
 de          Z G d de          Z G d de          Zedk    r ej                     dS dS )z3Tests support for new syntax introduced by PEP 492.    N)mock)utilsc                  .    t          j        d            d S N)asyncioset_event_loop_policy     4/usr/lib/python3.11/test/test_asyncio/test_pep492.pytearDownModuler      s    !$'''''r
   c                   (    e Zd Zd ZddZd Zd ZdS )FakeCoroc                     d S r   r	   )selfvalues     r   sendzFakeCoro.send       r
   Nc                     d S r   r	   )r   typvaltbs       r   throwzFakeCoro.throw   r   r
   c                     d S r   r	   r   s    r   closezFakeCoro.close   r   r
   c              #      K   d V  d S r   r	   r   s    r   	__await__zFakeCoro.__await__   s      r
   )NN)__name__
__module____qualname__r   r   r   r   r	   r
   r   r   r      sU                   r
   r   c                        e Zd Z fdZ xZS )BaseTestc                 L   t                                                       t          j                    | _        t          j                    | j        _        t          j                    | j        _        d| j        j        j	        _
        |                     | j                   d S )Nr	   )supersetUpr   BaseEventLooploopr   Mock_process_events	_selectorselectreturn_valueset_event_loop)r   	__class__s    r   r%   zBaseTest.setUp"   sp    )++	$(IKK	!"ikk	24	"/DI&&&&&r
   )r   r   r    r%   __classcell__)r.   s   @r   r"   r"       s8        ' ' ' ' ' ' ' ' 'r
   r"   c                       e Zd Zd Zd ZdS )	LockTestsc                 D    t          j                    t          j                    t          j                    t          j                    g} fd}|D ]L} j                             ||                                          |                                           Md S )Nc                 0  K   t          j        d           d {V                      |                                            | 4 d {V }                    |d                                |                                            t          j        d           d {V                      |                                            d d d           d {V  n# 1 d {V swxY w Y                       |                                            d S )N{Gz?)r   sleepassertFalselockedassertIs
assertTrue)lock_lockr   s     r   testz7LockTests.test_context_manager_async_with.<locals>.test5   s     -%%%%%%%%%T[[]]+++ / / / / / / /ueT***...mD)))))))))...	/ / / / / / / / / / / / / / / / / / / / / / / / / / /
 T[[]]+++++s   A?C
C(+C(	r   Lock	Condition	SemaphoreBoundedSemaphorer'   run_until_completer6   r7   r   
primitivesr<   	primitives   `   r   test_context_manager_async_withz)LockTests.test_context_manager_async_with-   s    LNN$&&	

	, 	, 	, 	, 	, $ 	1 	1II((i999Y--//0000	1 	1r
   c                 D    t          j                    t          j                    t          j                    t          j                    g} fd}|D ]L} j                             ||                                          |                                           Md S )Nc                 8  K   t          j        d           d {V                      |                                                                t
          d          5  |  d {V 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 )Nr4   z#can't be used in 'await' expression)r   r5   r6   r7   assertRaisesRegex	TypeError)r:   r   s    r   r<   z7LockTests.test_context_manager_with_await.<locals>.testK   s1     -%%%%%%%%%T[[]]+++''5     ZZZZZZ                	                 s6    	B)A7+B7A;	;B>A;	?BBBr=   rC   s   `   r   test_context_manager_with_awaitz)LockTests.test_context_manager_with_awaitC   s    LNN$&&	

	 	 	 	 	 $ 	1 	1II((i999Y--//0000	1 	1r
   N)r   r   r    rF   rK   r	   r
   r   r1   r1   +   s2        1 1 1,1 1 1 1 1r
   r1   c                       e Zd Zd ZdS )StreamReaderTestsc                    d}t          j        | j                                      |                                            fd}| j                             |                      }|                     |g d           d S )Ns   line1
line2
line3r'   c                  P   K   g } 2 3 d {V }|                      |           6 | S r   )append)datalinestreams     r   readerz/StreamReaderTests.test_readline.<locals>.readerc   sS      D$ " " " " " " "dD!!!! %Ks   %)s   line1
s   line2
s   line3)r   StreamReaderr'   	feed_datafeed_eofrB   assertEqual)r   DATArU   rR   rT   s       @r   test_readlinezStreamReaderTests.test_readline\   s    %%49555	 	 	 	 	 y++FFHH55AAABBBBBr
   N)r   r   r    r[   r	   r
   r   rM   rM   Z   s(        C C C C Cr
   rM   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	CoroutineTestsc                 2   d } |            }	 |                      t          j        |                     |                                 n# |                                 w xY w|                      t          j        t	                                           d S )Nc                  
   K   d S r   r	   r	   r
   r   fooz,CoroutineTests.test_iscoroutine.<locals>.foop   
        r
   )r9   r   iscoroutiner   r   )r   r`   fs      r   test_iscoroutinezCoroutineTests.test_iscoroutineo   s    CEE	OOG/22333GGIIIIAGGIIII+HJJ7788888s   'A A!c                 Z    d }|                      t          j        |                     d S )Nc                  
   K   d S r   r	   r	   r
   r   r`   z4CoroutineTests.test_iscoroutinefunction.<locals>.foo{   ra   r
   )r9   r   iscoroutinefunction)r   r`   s     r   test_iscoroutinefunctionz'CoroutineTests.test_iscoroutinefunctionz   s.    3C8899999r
   c                 ,   d fd}| j                              |                      }|                     |d           | j                             d           | j                              |                      }|                     |d           d S )Nc                  
   K   dS )Nspamr	   r	   r
   r   barz5CoroutineTests.test_async_def_coroutines.<locals>.bar   s      6r
   c                  (   K                  d {V S r   r	   )rl   s   r   r`   z5CoroutineTests.test_async_def_coroutines.<locals>.foo   s      ;;;;;;r
   rk   T)r'   rB   rY   	set_debug)r   r`   rR   rl   s      @r   test_async_def_coroutinesz(CoroutineTests.test_async_def_coroutines~   s    	 	 		 	 	 	 	 y++CCEE22v&&& 		D!!!y++CCEE22v&&&&&r
   c                 &     fd}                      t          j                    d            j                            d            j                             |                                             t          j                    d           d S )Nc                  `   K                         t          j                    dk               d S Nr   )r9   sys#get_coroutine_origin_tracking_depthr   s   r   startzOCoroutineTests.test_debug_mode_manages_coroutine_origin_tracking.<locals>.start   s-      OOCCEEIJJJJJr
   r   T)rY   rs   rt   r'   rn   rB   )r   ru   s   ` r   1test_debug_mode_manages_coroutine_origin_trackingz@CoroutineTests.test_debug_mode_manages_coroutine_origin_tracking   s    	K 	K 	K 	K 	K 	@BBAFFF	D!!!	$$UUWW---@BBAFFFFFr
   c                      d t           j        fd             fd} j                             |                      }                     |d           d S )Nc               3      K   dE d {V  dS )Nr	   rk   r	   r	   r
   r   genz0CoroutineTests.test_types_coroutine.<locals>.gen   s      MMMMMMM6r
   c                                    S r   r	   )ry   s   r   funcz1CoroutineTests.test_types_coroutine.<locals>.func   s    355Lr
   c                  l   K                }                      | t          j                   |  d {V S r   )assertIsInstancetypes_GeneratorWrapper)wrapperr{   r   s    r   coroz1CoroutineTests.test_types_coroutine.<locals>.coro   s=      dffG!!'5+BCCC ====== r
   rk   )r~   	coroutiner'   rB   rY   )r   r   rR   r{   ry   s   `  @@r   test_types_coroutinez#CoroutineTests.test_types_coroutine   s    	 	 	 
	 	 	 	 
		! 	! 	! 	! 	! 	!
 y++DDFF33v&&&&&r
   c                 n     d  fd fd} j                              |                       d S )Nc                     K                        d          } 	                     | d         j        j        d           d } d S # d } w xY w)N   )limitr   r`   )	get_stackrY   f_codeco_name)rc   Tr   s    r   r`   z1CoroutineTests.test_task_print_stack.<locals>.foo   sT      !$$A  1!4e<<<Ds   &A A	c                  b   K   t          j                     j                     d {V  d S )NrO   )r   ensure_futurer'   )r   r`   r   s   r   runnerz4CoroutineTests.test_task_print_stack.<locals>.runner   s9      %ccee$)<<<AGGGGGGGGGr
   )r'   rB   )r   r   r   r`   s   ` @@r   test_task_print_stackz$CoroutineTests.test_task_print_stack   so    	 	 	 	 	 		 	 	 	 	 	 	
 		$$VVXX.....r
   c                      d  fd} j                             d                                t          d          5   j                              |                       d d d            d S # 1 swxY w Y   d S )Nc                  >   K   t          j        d           d {V  d S )Ng?)r   r5   r	   r
   r   afuncz/CoroutineTests.test_double_await.<locals>.afunc   s.      -$$$$$$$$$$$r
   c                     K                } j                             |           }	 t          j        d           d {V  |  d {V  |                                 d S # |                                 w xY wrr   )r'   create_taskr   r5   cancel)r   tr   r   s     r   r   z0CoroutineTests.test_double_await.<locals>.runner   s      577D	%%d++AmA&&&&&&&&&















s   "A! !A7Tz"coroutine is being awaited already)msg)r'   rn   assertRaisesRuntimeErrorrB   )r   r   r   s   ` @r   test_double_awaitz CoroutineTests.test_double_await   s    	% 	% 	%	 	 	 	 	 	 		D!!!8  : : 	3 	3 I((222		3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   #A22A69A6N)
r   r   r    rd   rh   ro   rv   r   r   r   r	   r
   r   r]   r]   m   s        	9 	9 	9: : :' ' 'G G G' ' '"/ / /"3 3 3 3 3r
   r]   __main__)__doc__rs   r~   unittestr   r   test.test_asyncior   
test_utilsr   r   TestCaser"   r1   rM   r]   r   mainr	   r
   r   <module>r      sm   9 9 



          1 1 1 1 1 1( ( (
       ' ' ' ' 'z" ' ' ',1 ,1 ,1 ,1 ,1 ,1 ,1 ,1^C C C C C C C C&]3 ]3 ]3 ]3 ]3X ]3 ]3 ]3@ zHMOOOOO r
   