Your IP : 216.73.216.213


Current Path : /opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/test/test_asyncio/__pycache__/test_waitfor.cpython-39.opt-2.pyc

a

XC?h�!�@sXddlZddlZddlZdd�ZdZGdd�d�ZGdd�dej�Zed	krTe�	�dS)
�NcCst�d�dS�N)�asyncioZset_event_loop_policy�rr�C/opt/alt/python39/lib64/python3.9/test/test_asyncio/test_waitfor.py�tearDownModulesrg-C��6?c@s eZdZdZdd�Zdd�ZdS)�SlowTask皙�����?cCs
d|_dS)NF)�exited��selfrrr�__init__szSlowTask.__init__c�sZt��|j}|t��}|dkr$qPzt�|�IdHWqtjyLYq0qd|_dS)NrT)�time�	monotonic�TASK_TIMEOUTr�sleep�CancelledErrorr	)rZexitatZtosleeprrr�runszSlowTask.runN)�__name__�
__module__�__qualname__rrrrrrrrsrc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!S)"�AsyncioWaitForTestc�s\t�}t�t�|��|jd��}t�d�IdH|��t�|h�IdH|�	|j
�dS)N�r)rr�create_task�wait_forrrr�cancel�wait�
assertTruer	)r�tZwaitfortaskrrr�test_asyncio_wait_for_cancelled)s�z2AsyncioWaitForTest.test_asyncio_wait_for_cancelledc�sLt�}z t�|��|jd�IdHWntjy:Yn0|�|j�dS)Nr)rrrrr�TimeoutErrorrr	)rrrrr�test_asyncio_wait_for_timeout4s z0AsyncioWaitForTest.test_asyncio_wait_for_timeoutc�sjt��}|��}|�d�|��}t�|d�IdH}|��}|�|d�|�|���|�	||d�dS)N�doner皙�����?)
r�get_running_loop�
create_future�
set_resultr
r�assertEqualrr!�
assertLess)r�loop�fut�t0Zret�t1rrr�2test_wait_for_timeout_less_then_0_or_0_future_done>s
zEAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_future_donec�s�t��}d��fdd�}|�tj��,|��}t�|�d�IdHWd�n1sV0Y|��}|��d�|�||d�dS)NFc�sd�dS)NTrr�Zfoo_startedrr�fooQsz_AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_started.<locals>.foorr")rr#�assertRaisesrr
rr&r')rr(r.r*r+rr-r�?test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedLs2zRAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedc
�s�t��}dD]�}|j|d���d�|�����fdd�}t�|��}�IdH|�tj��*|��}t�||�IdHWd�n1s�0Y|��}|�	|�
��|�	|���|��d�|�
||d�Wd�q1s�0YqdS)N)r�����timeoutc�s2d���d�zt�d�IdHWd�nd�0dS�NT�
Fr!)r%rrr��foo_runningZstartedrrr.es
zFAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0.<locals>.fooFr")rr#ZsubTestr$rr/rr
rrr!�	cancelledr&r')rr(r3r.r)r*r+rr6r�&test_wait_for_timeout_less_then_0_or_0]s 

0z9AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0c�s�t��}d��fdd�}t�|��}|�tj��*|��}t�|d�IdHWd�n1s`0Y|��}|�|���|�|�	��|�
||d�|��d�dS)Nc�s(d�zt�d�IdHWd�nd�0dSr4�rrr�r7rrr.�s
z-AsyncioWaitForTest.test_wait_for.<locals>.foor"g�?F)rr#rr/rr
rrr!r8r'r&)rr(r.r)r*r+rr;r�
test_wait_for}s	0z AsyncioWaitForTest.test_wait_forc�s.dd�}tj|�dd�IdH}|�|d�dS)Nc�sdS)Nr!rrrrr�coro�sz7AsyncioWaitForTest.test_wait_for_blocking.<locals>.coror2r!�rrr&)rr=�resrrr�test_wait_for_blocking�sz)AsyncioWaitForTest.test_wait_for_blockingc�sHt��}|��}tj|dd�}|�d|jd�|IdH}|�|d�dS)Nrr2r"�ok)rr#r$rZ
call_laterr%r&)rr(r)�taskr?rrr�test_wait_for_race_condition�s
z/AsyncioWaitForTest.test_wait_for_race_conditionc�s2�fdd�}tj|�dd�IdH}��|d�dS)Nc�s@��tj�� t�d�IdHWd�n1s20YdS)N�)r/rrrrr
rr�inner�s.zKAsyncioWaitForTest.test_wait_for_cancellation_race_condition.<locals>.innerg{�G�z�?r2rDr>)rrE�resultrr
r�)test_wait_for_cancellation_race_condition�sz<AsyncioWaitForTest.test_wait_for_cancellation_race_conditionc�s�d��fdd�}t�|��}|�tj��$}tj|td�IdHWd�n1sR0Y|���|jj}|�	t
|�tj�dS)NFc�sPzDzt�d�IdHWn&tjy<t�t�IdH�Yn0Wd�nd�0dS�Nr5T�rrr�_EPSILONr�Z	task_donerrrE�s
zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.innerr2)rrr/rrrJr�	exception�__context__r&�typer)rrE�
inner_task�cm�chainedrrKr�)test_wait_for_waits_for_task_cancellation�s
2
z<AsyncioWaitForTest.test_wait_for_waits_for_task_cancellationc�spd��fdd�}|�tj��}|�IdHWd�n1s>0Y|���|jj}|�t|�tj�dS)NFc�s@�fdd�}t�|��}t�t�IdHtj|dd�IdHdS)Nc�sPzDzt�d�IdHWn&tjy<t�t�IdH�Yn0Wd�nd�0dSrHrIrrKrrrE�s
zdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.innerrr2)rrrrJr�rErOrKrrr.�s
zUAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo)	r/rrrrLrMr&rNr)rr.rPrQrrKr�5test_wait_for_waits_for_task_cancellation_w_timeout_0�s*
zHAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0c�sVGdd�dt���fdd�}|����|�IdHWd�n1sH0YdS)Nc@seZdZdS)z]AsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.FooExceptionN)rrrrrrr�FooException�srUc�s0�fdd�}t�|��}tj|td�IdHdS)Nc�s$zt�d�IdHW��n��0dS)Nrr:r�rUrrrE�szcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.innerr2)rrrrJrSrVrrr.�szTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo)�	Exceptionr/)rr.rrVr�4test_wait_for_reraises_exception_during_cancellation�szGAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellationc�s�dd�}t�|��}tj|dd�}t�|�}t�d�IdH|��|�tj��|IdHWd�n1sp0Y|�|IdHd�dS)Nc�shzt�d�IdHWnNtjybzt�d�IdHWn$tjy\t�d�IdHYn0Yn0dS)Ng333333�?�*)rrrrrrrrE�szAAsyncioWaitForTest.test_wait_for_self_cancellation.<locals>.innerr"r2rrY)rrrrrr/rr&)rrErOrrBrrr�test_wait_for_self_cancellation�s
(z2AsyncioWaitForTest.test_wait_for_self_cancellationc�s�t����fdd�}t�|��}t�t�||��}��|j�|�tj��|IdHWd�n1sj0Y|�|�	��dS)Nc�s���}|IdHdSr)r$)r)�r(rr�blocking_coroutineszDAsyncioWaitForTest._test_cancel_wait_for.<locals>.blocking_coroutine)
rr#rrZ	call_soonrr/rrr8)rr3r\rBrrr[r�_test_cancel_wait_fors(z(AsyncioWaitForTest._test_cancel_wait_forc�s|�d�IdHdSr�r]r
rrr�test_cancel_blocking_wait_forsz0AsyncioWaitForTest.test_cancel_blocking_wait_forc�s|�d�IdHdS)NgN@r^r
rrr�test_cancel_wait_for!sz'AsyncioWaitForTest.test_cancel_wait_forN)rrrrr r,r0r9r<r@rCrGrRrTrXrZr]r_r`rrrrr's 
 		r�__main__)
rZunittestr
rrJrZIsolatedAsyncioTestCaserr�mainrrrr�<module>s