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.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$eZdZdZdZdd�Zdd�ZdS)�SlowTaskz? Task will run for this defined time, ignoring cancel requests 皙�����?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__�__doc__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$�assertRaisesr r
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%rr0r r
rrr"�	cancelledr'r()rr)r4r/r*r+r,rr7r�&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�0dSr5�rrr�r8rrr/�s
z-AsyncioWaitForTest.test_wait_for.<locals>.foor#g�?F)rr$rr0r r
rrr"r9r(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>.coror3r"�rrr')rr>�resrrr�test_wait_for_blocking�sz)AsyncioWaitForTest.test_wait_for_blockingc�sHt��}|��}tj|dd�}|�d|jd�|IdH}|�|d�dS)Nrr3r#�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�)r0rrrrr
rr�inner�s.zKAsyncioWaitForTest.test_wait_for_cancellation_race_condition.<locals>.innerg{�G�z�?r3rEr?)rrF�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�Nr6T�rrr�_EPSILONr�Z	task_donerrrF�s
zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.innerr3)rrr0r rrKr�	exception�__context__r'�typer)rrF�
inner_task�cm�chainedrrLr�)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�0dSrIrJrrLrrrF�s
zdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.innerrr3)rrrrKr�rFrPrLrrr/�s
zUAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo)	r0rr rrMrNr'rOr)rr/rQrRrrLr�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�srVc�s0�fdd�}t�|��}tj|td�IdHdS)Nc�s$zt�d�IdHW��n��0dS)Nrr;r�rVrrrF�szcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.innerr3)rrrrKrTrWrrr/�szTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo)�	Exceptionr0)rr/rrWr�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�?�*)rrrrrrrrF�szAAsyncioWaitForTest.test_wait_for_self_cancellation.<locals>.innerr#r3rrZ)rrrrrr0rr')rrFrPrrCrrr�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_soonrr0rrr9)rr4r]rCrrr\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-r1r:r=rArDrHrSrUrYr[r^r`rarrrrr's 
 		r�__main__)
rZunittestr
rrKrZIsolatedAsyncioTestCaserr�mainrrrr�<module>s