
    daf                         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"                          yy)z3Tests support for new syntax introduced by PEP 492.    N)mock)utilsc                  .    t        j                  d        y N)asyncioset_event_loop_policy     8/root/Python-3.12.4/Lib/test/test_asyncio/test_pep492.pytearDownModuler      s    !!$'r
   c                   &    e Zd Zd ZddZd Zd Zy)FakeCoroc                      y r   r	   )selfvalues     r   sendzFakeCoro.send       r
   Nc                      y r   r	   )r   typvaltbs       r   throwzFakeCoro.throw   r   r
   c                      y r   r	   r   s    r   closezFakeCoro.close   r   r
   c              #      K   d  y wr   r	   r   s    r   	__await__zFakeCoro.__await__   s	        )NN)__name__
__module____qualname__r   r   r   r   r	   r
   r   r   r      s    r
   r   c                        e Zd Z fdZ xZS )BaseTestc                 `   t         |           t        j                         | _        t        j                         | j                  _        t        j                         | j                  _        d| j                  j                  j                  _
        | j                  | j                         y )Nr	   )supersetUpr   BaseEventLooploopr   Mock_process_events	_selectorselectreturn_valueset_event_loop)r   	__class__s    r   r&   zBaseTest.setUp"   sj    ))+	$(IIK		!"iik		24		""/DII&r
   )r   r    r!   r&   __classcell__)r/   s   @r   r#   r#       s    ' 'r
   r#   c                       e Zd Zd Zd Zy)	LockTestsc                 :    t        j                         t        j                         t        j                         t        j                         g} fd}|D ]B  } j
                  j                   ||              j                  |j                                D y )Nc                   K   t        j                  d       d {    j                  | j                                | 4 d {   }j	                  |d        j                  | j                                t        j                  d       d {    j                  | j                                d d d       d {    j                  | j                                y 7 7 7 W7 *# 1 d {  7  sw Y   :xY ww)N{Gz?)r   sleepassertFalselockedassertIs
assertTrue)lock_lockr   s     r   testz7LockTests.test_context_manager_async_with.<locals>.test5   s     --%%%T[[]+ / /ueT*.mmD))).	/ /
 T[[]+ &/ */ / / /sj   DC()DC*D
A
C0C,#C08DC.%D*D,C0.D0D6C97D>D	r   Lock	Condition	SemaphoreBoundedSemaphorer(   run_until_completer7   r8   r   
primitivesr=   	primitives   `   r   test_context_manager_async_withz)LockTests.test_context_manager_async_with-   sz    LLN$$&	

	, $ 	1III((i9Y--/0	1r
   c                 :    t        j                         t        j                         t        j                         t        j                         g} fd}|D ]B  } j
                  j                   ||              j                  |j                                D y )Nc                 $  K   t        j                  d       d {    j                  | j                                j	                  t
        d      5  |  d {   5  	 d d d        d d d        y 7 W7 # 1 sw Y   xY w# 1 sw Y   y xY ww)Nr5   z#can't be used in 'await' expression)r   r6   r7   r8   assertRaisesRegex	TypeError)r;   r   s    r   r=   z7LockTests.test_context_manager_with_await.<locals>.testK   s     --%%%T[[]+''5   Z 	  &    	 sQ   BA49BBA6B!A8#B+
B6B8B	=BB	Br>   rD   s   `   r   test_context_manager_with_awaitz)LockTests.test_context_manager_with_awaitC   sz    LLN$$&	

	 $ 	1III((i9Y--/0	1r
   N)r   r    r!   rG   rL   r	   r
   r   r2   r2   +   s    1,1r
   r2   c                       e Zd Zd Zy)StreamReaderTestsc                     d}t        j                  | j                        j                  |       j	                          fd}| j                  j                   |             }| j                  |g d       y )Ns   line1
line2
line3r(   c                  T   K   g } 2 3 d {   }| j                  |       7 6 | S wr   )append)datalinestreams     r   readerz/StreamReaderTests.test_readline.<locals>.readerc   s4     D$ " "dD!"fKs   (%#%(%()s   line1
s   line2
s   line3)r   StreamReaderr(   	feed_datafeed_eofrC   assertEqual)r   DATArV   rS   rU   s       @r   test_readlinezStreamReaderTests.test_readline\   sb    %%%4995	 yy++FH5ABr
   N)r   r    r!   r\   r	   r
   r   rN   rN   Z   s    Cr
   rN   c                   <    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
y	)
CoroutineTestsc                    d } |       }	 | j                  t        j                  |             |j                          | j                  t        j                  t	                            y # |j                          w xY w)Nc                     K   y wr   r	   r	   r
   r   fooz,CoroutineTests.test_iscoroutine.<locals>.foop           )r:   r   iscoroutiner   r   )r   ra   fs      r   test_iscoroutinezCoroutineTests.test_iscoroutineo   sW    E	OOG//23GGI++HJ78 GGIs   $A- -A?c                 \    d }| j                  t        j                   |                    y )Nc               3      K   d  y wr   r	   r	   r
   r   ra   z6CoroutineTests.test_iscoroutine_generator.<locals>.foo{   s     5r   )r7   r   rd   r   ra   s     r   test_iscoroutine_generatorz)CoroutineTests.test_iscoroutine_generatorz   s     ,,SU34r
   c                 R    d }| j                  t        j                  |             y )Nc                     K   y wr   r	   r	   r
   r   ra   z4CoroutineTests.test_iscoroutinefunction.<locals>.foo   rb   rc   )r:   r   iscoroutinefunctionri   s     r   test_iscoroutinefunctionz'CoroutineTests.test_iscoroutinefunction   s    33C89r
   c                    d fd}| j                   j                   |             }| j                  |d       | j                   j                  d       | j                   j                   |             }| j                  |d       y )Nc                     K   yw)Nspamr	   r	   r
   r   barz5CoroutineTests.test_async_def_coroutines.<locals>.bar   s	     rc   c                  .   K             d {   S 7 wr   r	   )rr   s   r   ra   z5CoroutineTests.test_async_def_coroutines.<locals>.foo   s     ;;s   rq   T)r(   rC   rZ   	set_debug)r   ra   rS   rr   s      @r   test_async_def_coroutinesz(CoroutineTests.test_async_def_coroutines   so    		 yy++CE2v& 			D!yy++CE2v&r
   c                      fd} j                  t        j                         d        j                  j	                  d        j                  j                   |               j                  t        j                         d       y )Nc                  Z   K    j                  t        j                         dkD         y wNr   )r:   sys#get_coroutine_origin_tracking_depthr   s   r   startzOCoroutineTests.test_debug_mode_manages_coroutine_origin_tracking.<locals>.start   s!     OOCCCEIJs   (+r   T)rZ   ry   rz   r(   rt   rC   )r   r{   s   ` r   1test_debug_mode_manages_coroutine_origin_trackingz@CoroutineTests.test_debug_mode_manages_coroutine_origin_tracking   sc    	K 	@@BAF		D!		$$UW-@@BAFr
   c                      d t         j                  fd        fd} j                  j                   |             } j	                  |d       y )Nc               3   $   K   dE d {    y7 w)Nr	   rq   r	   r	   r
   r   genz0CoroutineTests.test_types_coroutine.<locals>.gen   s     MM s   c                               S r   r	   )r   s   r   funcz1CoroutineTests.test_types_coroutine.<locals>.func   s
    5Lr
   c                  r   K           } j                  | t        j                         |  d {   S 7 wr   )assertIsInstancetypes_GeneratorWrapper)wrapperr   r   s    r   coroz1CoroutineTests.test_types_coroutine.<locals>.coro   s.     fG!!'5+B+BC = =s   -757rq   )r   	coroutiner(   rC   rZ   )r   r   rS   r   r   s   `  @@r   test_types_coroutinez#CoroutineTests.test_types_coroutine   sM    	 
	 
		!
 yy++DF3v&r
   c                 h     d  fd fd} j                   j                   |              y )Nc                     K   j                  d      } 	 j                  | d   j                  j                  d       d } y # d } w xY ww)N   )limitr   ra   )	get_stackrZ   f_codeco_name)re   Tr   s    r   ra   z1CoroutineTests.test_task_print_stack.<locals>.foo   sD     !$A  1!4!4e<Ds   A
)A  A
AA
c                  r   K   t        j                          j                           d {    y 7 w)NrP   )r   ensure_futurer(   )r   ra   r   s   r   runnerz4CoroutineTests.test_task_print_stack.<locals>.runner   s&     %%ce$))<AGGs   ,757)r(   rC   )r   r   r   ra   s   ` @@r   test_task_print_stackz$CoroutineTests.test_task_print_stack   s(    		
 			$$VX.r
   c                      d  fd} j                   j                  d        j                  t        d      5   j                   j	                   |              d d d        y # 1 sw Y   y xY w)Nc                  J   K   t        j                  d       d {    y 7 w)Ng?)r   r6   r	   r
   r   afuncz/CoroutineTests.test_double_await.<locals>.afunc   s     --$$$s   #!#c                     K           } j                   j                  |       }	 t        j                  d       d {    |  d {    |j	                          y 7 7 # |j	                          w xY wwrx   )r(   create_taskr   r6   cancel)r   tr   r   s     r   r   z0CoroutineTests.test_double_await.<locals>.runner   s\     7D		%%d+AmmA&&&


 '
s?   #A8A# A 	A# 	A!
A# A8A# !A# #A55A8Tz"coroutine is being awaited already)msg)r(   rt   assertRaisesRuntimeErrorrC   )r   r   r   s   ` @r   test_double_awaitz CoroutineTests.test_double_await   se    	%	 			D!8  : 	3 II((2		3 	3 	3s   !A((A1N)r   r    r!   rf   rj   rn   ru   r|   r   r   r   r	   r
   r   r^   r^   m   s+    	95:'G'"/"3r
   r^   __main__)__doc__ry   r   unittestr   r   test.test_asyncior   
test_utilsr   r   TestCaser#   r2   rN   r^   r   mainr	   r
   r   <module>r      s    9 
     1(
 'z"" ',1 ,1^C C&c3X c3L zHMMO r
   