
    z%i+                         d dl Z d dlZd dlZd ZdZ G d d      Z G d dej                        Z G d d	ej                        Ze	d
k(  r ej                          yy)    Nc                  .    t        j                  d        y N)asyncioset_event_loop_policy     R/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/test/test_asyncio/test_waitfor.pytearDownModuler
      s    !!$'r   g-C6?c                       e Zd Z	 dZd Zd Zy)SlowTask皙?c                     d| _         y )NF)exitedselfs    r	   __init__zSlowTask.__init__   s	    r   c                   K   t        j                         | j                  z   }	 |t        j                         z
  }|dk  r		 d| _        y 	 t        j                  |       d {    D7 # t        j
                  $ r Y w xY ww)NTr   )time	monotonicTASK_TIMEOUTr   sleepCancelledErrorr   )r   exitattosleeps      r	   runzSlowTask.run   s|     !D$5$55t~~//G!| mmG,,,  -)) s<   ABA+ #A)$A+ (B)A+ +B>B BBN)__name__
__module____qualname__r   r   r   r   r   r	   r   r      s    ILr   r   c                   r    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d Zd Zd Zd Zd Zd Zy)AsyncioWaitForTestc                 |  K   t               }t        j                  t        j                  |j	                         |j
                  dz              }t        j                  d       d {    |j                          t        j                  |h       d {    | j                  |j                         y 7 N7 "w)N   r   )r   r   create_taskwait_forr   r   r   cancelwait
assertTruer   )r   twaitfortasks      r	   test_asyncio_wait_for_cancelledz2AsyncioWaitForTest.test_asyncio_wait_for_cancelled)   s     J))QUUWannq&89;mmAllK=)))!	 	)s$   A'B<)B8*-B<B:!B<:B<c                    K   t               }	 t        j                  |j                         |j                  dz         d {    | j                  |j                         y 7  # t        j
                  $ r Y 3w xY ww)Nr"   )r   r   r$   r   r   TimeoutErrorr'   r   )r   r(   s     r	   test_asyncio_wait_for_timeoutz0AsyncioWaitForTest.test_asyncio_wait_for_timeout4   sf     J	""1557ANNQ,>??? 	!	 @## 		s:   A>4A% A#A% A>#A% %A;8A>:A;;A>c                   K   t        j                         }|j                         }|j                  d       |j	                         }t        j
                  |d       d {   }|j	                         }| j                  |d       | j                  |j                                | j                  ||z
  d       y 7 [w)Ndoner   皙?)
r   get_running_loopcreate_future
set_resultr   r$   assertEqualr'   r/   
assertLess)r   loopfutt0rett1s         r	   2test_wait_for_timeout_less_then_0_or_0_future_donezEAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_future_done>   s     '')  "vYY[$$S!,,YY[f%
#R% -s   AB?!B="AB?c                   K   t        j                         }dfd}| j                  t         j                        5  |j	                         }t        j
                   |       d       d {    d d d        |j	                         }| j                  d       | j                  |z
  d       y 7 D# 1 sw Y   CxY ww)NFc                     K   d y w)NTr   )foo_starteds   r	   fooz_AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_started.<locals>.fooQ   s     Ks   r   r0   )r   r1   assertRaisesr,   r   r$   r4   r5   )r   r6   r?   r8   r:   r>   s        @r	   ?test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedzRAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedL   s     '')	 w334 	-B""35!,,,	- YY[e,R%	 -	- 	-s/   ;C /B4-B2.B42A C 2B44B=9C c                   K   t        j                         }dD ]%  }| j                  |      5  d |j                         fd}t        j                   |             } d {    | j                  t         j                        5  |j                         }t        j                  ||       d {    d d d        |j                         }| j                  |j                                | j                  |j                                | j                  d       | j                  |z
  d       d d d        ( y 7 7 # 1 sw Y   xY w# 1 sw Y   DxY ww)N)r   timeoutc                     K   d j                  d        	 t        j                  d       d {    d y7 # d w xY wwNT
   Fr/   )r3   r   r   )foo_runningstarteds   r	   r?   zFAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0.<locals>.fooe   sD     "&K&&t,,%mmB///&+! 0&+s#   A: 8: A: >AFr0   )r   r1   subTestr2   r#   r@   r,   r   r$   r'   r/   	cancelledr4   r5   )	r   r6   rE   r?   r7   r8   r:   rI   rJ   s	          @@r	   &test_wait_for_timeout_less_then_0_or_0z9AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0]   s'    '') 	.Gg. .",,." ))#%0&&w';';< 9B!**38889 YY[
+0  e4R-5. .	.   99 9#. .sY   -E"8E)E*#E*E	7E
8E	<A=E9E"EE		EEE	E"c                 *  K   t        j                         }d fd}t        j                   |             }| j                  t         j                        5  |j                         }t        j                  |d       d {    d d d        |j                         }| j                  |j                                | j                  |j                                | j                  |z
  d       | j                  d       y 7 # 1 sw Y   xY ww)Nc                  d   K   d 	 t        j                  d       d {    d y7 # d w xY wwrG   r   r   )rI   s   r	   r?   z-AsyncioWaitForTest.test_wait_for.<locals>.foo   s6     K$mmB'''# (#s    0) ') 0) -0r0   g      ?F)r   r1   r#   r@   r,   r   r$   r'   r/   rL   r5   r4   )r   r6   r?   r7   r8   r:   rI   s         @r	   test_wait_forz AsyncioWaitForTest.test_wait_for}   s     '')	 !!#%(w334 	-B""3,,,	- YY[
#(R%e, -	- 	-s1   AD*DDDA>DDDDc                    K   d }t        j                   |       d        d {   }| j                  |d       y 7 w)Nc                     K   ywNr/   r   r   r   r	   coroz7AsyncioWaitForTest.test_wait_for_blocking.<locals>.coro   	        rD   r/   r   r$   r4   )r   rU   ress      r	   test_wait_for_blockingz)AsyncioWaitForTest.test_wait_for_blocking   s9     	 $$TVT::f% ;   #?=?c                    K   t        j                         }|j                         }t        j                  |d      }|j	                  |j
                  d       | d {   }| j                  |d       y 7 w)Nr   rD   ok)r   r1   r2   r$   	call_soonr3   r4   )r   r6   r7   taskrY   s        r	   test_wait_for_race_conditionz/AsyncioWaitForTest.test_wait_for_race_condition   sb     '')  "S1s~~t,jd# s   AA9A7 A9c                     K    fd}t        j                   |       d       d {   } j                  |d       y 7 w)Nc                     K    j                  t        j                        5  t        j                  d       d {    d d d        y7 # 1 sw Y   yxY ww)N   )r@   r   r   r   r   s   r	   innerzKAsyncioWaitForTest.test_wait_for_cancellation_race_condition.<locals>.inner   sH     ""7#9#9: 'mmA&&&' ''s,    AAA
A	A
AAA{Gz?rD   rc   rX   )r   rd   results   `  r	   )test_wait_for_cancellation_race_conditionz<AsyncioWaitForTest.test_wait_for_cancellation_race_condition   s:     	
 ''==# >s   %AA Ac                   K   dfd}t        j                   |             }| j                  t         j                        5 }t        j                  |t
               d {    d d d        | j                         j                  j                  }| j                  t        |      t         j                         y 7 ]# 1 sw Y   \xY ww)NFc                     K   	 t        j                  d       d {    d y 7 # t         j                  $ r$ t        j                  t               d {  7    w xY w# d w xY wwNrH   Tr   r   r   _EPSILON	task_dones   r	   rd   zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.inner   s[     !mmB'''
 !	 ()) mmH--- !	=   A(' %' A(' /AAAA! !A%%A(rD   )r   r#   r@   r,   r$   rl   r'   	exception__context__r4   typer   )r   rd   
inner_taskcmchainedrn   s        @r	   )test_wait_for_waits_for_task_cancellationz<AsyncioWaitForTest.test_wait_for_waits_for_task_cancellation   s     		! ((1
w334 	A"":x@@@	A 		",,**g(>(>?	 A	A 	As1   ACC#C$C(ACCCCc                 F  K   dfd}| j                  t        j                        5 } |        d {    d d d        | j                         j                  j
                  }| j                  t        |      t        j                         y 7 ]# 1 sw Y   \xY ww)NFc                     K   fd} t        j                   |              }t        j                  t               d {    t        j                  |d       d {    y 7 $7 w)Nc                     K   	 t        j                  d       d {    d y 7 # t         j                  $ r$ t        j                  t               d {  7    w xY w# d w xY wwrj   rk   rm   s   r	   rd   zdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.inner   s[     %!--+++
 !%I ,-- !--111 !%Iro   r   rD   )r   r#   r   rl   r$   )rd   rs   rn   s     r	   r?   zUAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo   sQ     % !,,UW5J--)))"":q999 *9s"   <A(A$ A(A&A(&A()	r@   r   r,   r'   rp   rq   r4   rr   r   )r   r?   rt   ru   rn   s       @r	   5test_wait_for_waits_for_task_cancellation_w_timeout_0zHAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0   s     		: w334 	%KK	 		",,**g(>(>?	 	 	s,   'B!BBBAB!BBB!c                    K    G d dt               fd}| j                        5   |        d {    d d d        y 7 # 1 sw Y   y xY ww)Nc                       e Zd Zy)]AsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.FooExceptionN)r   r   r   r   r   r	   FooExceptionr}      s    r   r~   c                     K   fd} t        j                   |              }t        j                  |t               d {    y 7 w)Nc                  \   K   	 t        j                  d       d {     7 #  xY ww)Nr   rP   )r~   s   r	   rd   zcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.inner   s0     '!--,,,&& -&&s    ,& $& ,& ),rD   )r   r#   r$   rl   )rd   rs   r~   s     r	   r?   zTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo   s6     ' !,,UW5J"":x@@@s   >A	AA	)	Exceptionr@   )r   r?   r~   s     @r	   4test_wait_for_reraises_exception_during_cancellationzGAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation   sO     	9 			A |, 	%KK	 		 	s+   &AAAA	AAA	Ac                   K   t        j                         fd}t        j                   |             }t        j                  t        j                  ||            }j	                  |j
                         | j                  t         j                        5  | d {    d d d        | j                  |j                                y 7 ,# 1 sw Y   +xY ww)Nc                  F   K   j                         } |  d {    y 7 wr   )r2   )r7   r6   s    r	   blocking_coroutinezDAsyncioWaitForTest._test_cancel_wait_for.<locals>.blocking_coroutine   s     $$&CIIs   !!)
r   r1   r#   r$   r^   r%   r@   r   r'   rL   )r   rE   r   r_   r&   r6   s        @r	   _test_cancel_wait_forz(AsyncioWaitForTest._test_cancel_wait_for   s     '')	
 ""#5#78""7#3#3D'#BCt{{#w556 	JJ	 	() 	 	s0   BCC C!C%(CCCCc                 B   K   | j                  d        d {    y 7 wr   r   r   s    r	   test_cancel_blocking_wait_forz0AsyncioWaitForTest.test_cancel_blocking_wait_for       ((...   c                 B   K   | j                  d       d {    y 7 w)Ng      N@r   r   s    r	   test_cancel_wait_forz'AsyncioWaitForTest.test_cancel_wait_for  r   r   c                    K   d }t        j                   |       d       d {   }| j                  |d       y 7 w)Nc                  ~   K   	 t        j                  d       d {    y 7 # t         j                  $ r Y yw xY ww)NrH   *   )r   r   r   r   r   r	   	return_42zEAsyncioWaitForTest.test_wait_for_cancel_suppressed.<locals>.return_42  s4     mmB''')) s(   =$ "$ =$ :=:=r0   rD   r   rX   )r   r   rY   s      r	   test_wait_for_cancel_suppressedz2AsyncioWaitForTest.test_wait_for_cancel_suppressed	  s9     	 $$Y[#>>b! ?r[   c                 B  K   d }t        j                   |             dfd}t        j                   |             }| j                  |j                                t        j                  d       d {    |j                          | j                  t         j                        5  | d {    d d d        | j                  j                                | j                   d {   d       | j                         y 7 7 Y# 1 sw Y   XxY w7 +w)Nc                     K   ywrT   r   r   r   r	   rd   z:AsyncioWaitForTest.test_wait_for_issue86296.<locals>.inner  rV   rW   Fc                     K   t        j                   d       d {    t        j                  d       d {    dy 7 $7 	w)Nd   rD   rc   T)r   r$   r   )rs   reached_ends   r	   wait_for_corozBAsyncioWaitForTest.test_wait_for_issue86296.<locals>.wait_for_coro$  s=     "":s;;;--"""K <"s   AAAAAAr   r/   )
r   r#   assertFalser/   r   r%   r@   r   r'   r4   )r   rd   r   r_   rs   r   s       @@r	   test_wait_for_issue86296z+AsyncioWaitForTest.test_wait_for_issue86296  s     
	 ((1
	 ""=?3%mmAw556 	JJ	
)*z)62% 	 	 	 *sH   A7D;D<3D/D5D6D:7D1D2DDDDN)r   r   r   r*   r-   r;   rA   rM   rQ   rZ   r`   rg   rv   rz   r   r   r   r   r   r   r   r   r	   r    r    '   sZ    	""&&".@-2&$$@,@2$*&//" &r   r    c                       e Zd Zd Zd Zd Zy)WaitForShieldTestsc                 P  K   d }t        j                   |             }| j                  t         j                        5  t        j                  |      }t        j
                  |d       d {    d d d        | j                  |j                                | j                  |j                                | j                  j                                t        j                  d       d {    | j                  |j                                y 7 # 1 sw Y   xY w7 2w)Nc                  J   K   t        j                  d       d {    y7 w)Nre   r/   rP   r   r   r	   rU   z2WaitForShieldTests.test_zero_timeout.<locals>.coro?  s      --%%% &   #!#r   rD   r0   )r   r#   r@   r,   shieldr$   r   r/   rL   r'   r   )r   rU   r_   shielded_tasks       r	   test_zero_timeoutz$WaitForShieldTests.test_zero_timeout8  s     	 ""46*w334 	=#NN40M""=!<<<	=
 	%)*//12 mmC   		$ =	= 	= 	!s;   =D&0D/D0D4A=D&1D$2$D&DD!D&c                 $  K   d }t        j                   |             }t        j                  t        j                  |      d        d {    | j	                  |j                                | j                  | d {   d       y 7 >7 w)Nc                  J   K   t        j                  d       d {    y7 wNr0   r/   rP   r   r   r	   rU   z2WaitForShieldTests.test_none_timeout.<locals>.coroU        --$$$ %r   rD   r/   )r   r#   r$   r   r'   r/   r4   r   rU   r_   s      r	   test_none_timeoutz$WaitForShieldTests.test_none_timeoutR  sn     	 ""46*w~~d3TBBB		$tV, 	C $s$   ABB3BBBBc                   K   d }t        j                   |             }| j                  t         j                        5  t        j                  t        j
                  |      d       d {    d d d        | j                  |j                                | j                  |j                                | j                  | d {   d       y 7 e# 1 sw Y   dxY w7 w)Nc                  J   K   t        j                  d       d {    y7 wr   rP   r   r   r	   rU   z6WaitForShieldTests.test_shielded_timeout.<locals>.coroa  r   r   re   rD   r/   )
r   r#   r@   r,   r$   r   r   r/   rL   r4   r   s      r	   test_shielded_timeoutz(WaitForShieldTests.test_shielded_timeout_  s     	 ""46*w334 	G""7>>$#7FFF	G 	%)*tV,	 G	G 	G
 $s;   =C#.C-C.C2AC#C!	
C#CCC#N)r   r   r   r   r   r   r   r   r	   r   r   6  s    %4--r   r   __main__)r   unittestr   r
   rl   r   IsolatedAsyncioTestCaser    r   r   mainr   r   r	   <module>r      sf      (  .L&99 L&^5-99 5-p zHMMO r   