Your IP : 216.73.216.52


Current Path : /opt/alt/python310/lib64/python3.10/test/test_asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/test_asyncio/__pycache__/test_waitfor.cpython-310.pyc

o

0�i�!�@s\ddlZddlZddlZdd�ZdZGdd�d�ZGdd�dej�Zed	kr,e�	�dSdS)
�NcCst�d�dS�N)�asyncioZset_event_loop_policy�rr�E/opt/alt/python310/lib64/python3.10/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__s
zSlowTask.__init__c�s^�t��|j}	|t��}|dkrnz
t�|�IdHWn
tjy(Ynwq	d|_dS)NTr)�time�	monotonic�TASK_TIMEOUTr�sleep�CancelledErrorr	)rZexitatZtosleeprrr�runs���

zSlowTask.runN)�__name__�
__module__�__qualname__�__doc__rrrrrrrrs
rc@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�sN�t�}zt�|��|jd�IdHWn
tjyYnw|�|j�dS)Nr)rrrrr�TimeoutErrorrr	)rrrrr�test_asyncio_wait_for_timeout4s� �z0AsyncioWaitForTest.test_asyncio_wait_for_timeoutc�sl�t��}|��}|�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�n1s,wY|��}|��d�|�||d�dS)NFc�s
�d�dS)NTrr�Zfoo_startedrr�fooQs�z_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��zRAsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0_coroutine_do_not_startedc
�s��t��}dD]s}|j|d��cd�|�����fdd�}t�|��}�IdH|�tj��|��}t�||�IdHWd�n1sFwY|��}|�	|�
��|�	|���|��d�|�
||d�Wd�n1suwYqdS)N)r�����timeoutc�s2�d���d�z
t�d�IdHWd�dSd�w�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*�

����z9AsyncioWaitForTest.test_wait_for_timeout_less_then_0_or_0c�s��t��}d��fdd�}t�|��}|�tj��|��}t�|d�IdHWd�n1s1wY|��}|�|���|�|�	��|�
||d�|��d�dS)Nc�s(�d�z
t�d�IdHWd�dSd�wr5�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�	�z AsyncioWaitForTest.test_wait_forc�s0�dd�}tj|�dd�IdH}|�|d�dS)Nc�s�dS)Nr"rrrrr�coro�s�z7AsyncioWaitForTest.test_wait_for_blocking.<locals>.coror3r"�rrr')rr>�resrrr�test_wait_for_blocking�s�z)AsyncioWaitForTest.test_wait_for_blockingc�sJ�t��}|��}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�s4��fdd�}tj|�dd�IdH}��|d�dS)Nc�sD���tj��t�d�IdHWd�dS1swYdS)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�n1s*wY|���|jj}|�	t
|�tj�dS)NFc��L�z!z
t�d�IdHWntjyt�t�IdH�wWd�dSd�w�Nr6T�rrr�_EPSILONr�Z	task_donerrrF�����zKAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation.<locals>.innerr3)rrr0r rrLr�	exception�__context__r'�typer)rrF�
inner_task�cm�chainedrrMr�)test_wait_for_waits_for_task_cancellation�s�
�
z<AsyncioWaitForTest.test_wait_for_waits_for_task_cancellationc�sr�d��fdd�}|�tj��}|�IdHWd�n1s wY|���|jj}|�t|�tj�dS)NFc�sB��fdd�}t�|��}t�t�IdHtj|dd�IdHdS)Nc�rIrJrKrrMrrrF�rNzdAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo.<locals>.innerrr3)rrrrLr�rFrRrMrrr/�s
�
zUAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0.<locals>.foo)	r0rr rrOrPr'rQr)rr/rSrTrrMr�5test_wait_for_waits_for_task_cancellation_w_timeout_0�s��
zHAsyncioWaitForTest.test_wait_for_waits_for_task_cancellation_w_timeout_0c�sZ�Gdd�dt���fdd�}|����|�IdHWd�dS1s&wYdS)Nc@seZdZdS)z]AsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.FooExceptionN)rrrrrrr�FooException�srXc�s2��fdd�}t�|��}tj|td�IdHdS)Nc�s�zt�d�IdHW����)Nrr;r�rXrrrF�s�zcAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo.<locals>.innerr3)rrrrLrVrYrrr/�s�zTAsyncioWaitForTest.test_wait_for_reraises_exception_during_cancellation.<locals>.foo)�	Exceptionr0)rr/rrYr�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�n1s9wY|�|IdHd�dS)Nc�sl�zt�d�IdHWdStjy5zt�d�IdHWYdStjy4t�d�IdHYYdSww)Ng333333�?�*)rrrrrrrrF�s�����zAAsyncioWaitForTest.test_wait_for_self_cancellation.<locals>.innerr#r3rr\)rrrrrr0rr')rrFrRrrCrrr�test_wait_for_self_cancellation�s�
�z2AsyncioWaitForTest.test_wait_for_self_cancellationc�s��t����fdd�}t�|��}t�t�||��}��|j�|�tj��
|IdHWd�n1s6wY|�|�	��dS)Nc�s����}|IdHdSr)r%)r*�r)rr�blocking_coroutines�zDAsyncioWaitForTest._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_for��z0AsyncioWaitForTest.test_cancel_blocking_wait_forc�s�|�d�IdHdS)NgN@rar
rrr�test_cancel_wait_for!rcz'AsyncioWaitForTest.test_cancel_wait_forN)rrrrr!r-r1r:r=rArDrHrUrWr[r]r`rbrdrrrrr's"
 		r�__main__)
rZunittestr
rrLrZIsolatedAsyncioTestCaserr�mainrrrr�<module>s�