
    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d Zy)SlowTaskz? Task will run for this defined time, ignoring cancel requests 皙?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____doc__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(   r0   
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   r1   )r   r2   assertRaisesr-   r   r%   r5   r6   )r   r7   r@   r9   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
   Fr0   )r4   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Fr1   )r   r2   subTestr3   r$   rA   r-   r   r%   r(   r0   	cancelledr5   r6   )	r   r7   rF   r@   r8   r9   r;   rJ   rK   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rH   r   r   )rJ   s   r	   r@   z-AsyncioWaitForTest.test_wait_for.<locals>.foo   s6     K$mmB'''# (#s    0) ') 0) -0r1   g      ?F)r   r2   r$   rA   r-   r   r%   r(   r0   rM   r6   r5   )r   r7   r@   r8   r9   r;   rJ   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Nr0   r   r   r   r	   coroz7AsyncioWaitForTest.test_wait_for_blocking.<locals>.coro   	        rE   r0   r   r%   r5   )r   rV   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   rE   ok)r   r2   r3   r%   	call_soonr4   r5   )r   r7   r8   taskrZ   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   )rA   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?rE   rd   rY   )r   re   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NrI   Tr   r   r   _EPSILON	task_dones   r	   re   zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.inner   s[     !mmB'''
 !	 ()) mmH--- !	=   A(' %' A(' /AAAA! !A%%A(rE   )r   r$   rA   r-   r%   rm   r(   	exception__context__r5   typer   )r   re   
inner_taskcmchainedro   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rk   rl   rn   s   r	   re   zdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.inner   s[     %!--+++
 !%I ,-- !--111 !%Irp   r   rE   )r   r$   r   rm   r%   )re   rt   ro   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()	rA   r   r-   r(   rq   rr   r5   rs   r   )r   r@   ru   rv   ro   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   rQ   )r   s   r	   re   zcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.inner   s0     '!--,,,&& -&&s    ,& $& ,& ),rE   )r   r$   r%   rm   )re   rt   r   s     r	   r@   zTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo   s6     ' !,,UW5J"":x@@@s   >A	AA	)	ExceptionrA   )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   )r3   )r8   r7   s    r	   blocking_coroutinezDAsyncioWaitForTest._test_cancel_wait_for.<locals>.blocking_coroutine   s     $$&CIIs   !!)
r   r2   r$   r%   r_   r&   rA   r   r(   rM   )r   rF   r   r`   r'   r7   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)NrI   *   )r   r   r   r   r   r	   	return_42zEAsyncioWaitForTest.test_wait_for_cancel_suppressed.<locals>.return_42  s4     mmB''')) s(   =$ "$ =$ :=:=r1   rE   r   rY   )r   r   rZ   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rU   r   r   r   r	   re   z:AsyncioWaitForTest.test_wait_for_issue86296.<locals>.inner  rW   rX   Fc                     K   t        j                   d       d {    t        j                  d       d {    dy 7 $7 	w)Nd   rE   rd   T)r   r%   r   )rt   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   r0   )
r   r$   assertFalser0   r   r&   rA   r   r(   r5   )r   re   r   r`   rt   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<   rB   rN   rR   r[   ra   rh   rw   r{   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)Nrf   r0   rQ   r   r   r	   rV   z2WaitForShieldTests.test_zero_timeout.<locals>.coro?  s      --%%% &   #!#r   rE   r1   )r   r$   rA   r-   shieldr%   r   r0   rM   r(   r   )r   rV   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Nr1   r0   rQ   r   r   r	   rV   z2WaitForShieldTests.test_none_timeout.<locals>.coroU        --$$$ %r   rE   r0   )r   r$   r%   r   r(   r0   r5   r   rV   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   rQ   r   r   r	   rV   z6WaitForShieldTests.test_shielded_timeout.<locals>.coroa  r   r   rf   rE   r0   )
r   r$   rA   r-   r%   r   r   r0   rM   r5   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
   rm   r   IsolatedAsyncioTestCaser!   r   r   mainr   r   r	   <module>r      sf      (  .L&99 L&^5-99 5-p zHMMO r   