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_locks.cpython-39.pyc

a

XC?hQs�@s�dZddlZddlmZddlZddlZdZe�e�Zdd�ZGdd�dej	�Z
Gd	d
�d
ej	�ZGdd�dej	�ZGd
d�dej	�Z
edkr�e��dS)zTests for lock.py�N)�mockzv^<(?P<class>.*?) object at (?P<address>.*?)\[(?P<extras>(set|unset|locked|unlocked)(, value:\d)?(, waiters:\d+)?)\]>\ZcCst�d�dS�N)�asyncioZset_event_loop_policy�rr�A/opt/alt/python39/lib64/python3.9/test/test_asyncio/test_locks.py�tearDownModulesrc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�	LockTestsc�s�t��}|�t��tj|d�}Wd�n1s40Y|�|j|�|�t�� tjt��d�}Wd�n1s|0Y|�|jt���dS�N��loop)	r�Mock�assertWarns�DeprecationWarningr�Lock�assertIs�_loop�get_running_loop)�selfr�lockrrr�test_ctor_loops*.zLockTests.test_ctor_loopc�st��}|�|jt���dSr)rrrrr�rrrrr�test_ctor_noloop"szLockTests.test_ctor_noloopc�s�|�t�� tjt��d�}Wd�n1s00Y|�t|��d��|�t�	t|���|�
�IdH|�t|��d��|�t�	t|���dS)Nr
z[unlocked]>�	[locked]>)r
rrrr�
assertTrue�repr�endswith�RGX_REPR�match�acquirerrrr�	test_repr&s.zLockTests.test_reprc�sPt��}|�td��|IdHWd�n1s40Y|�|���dS)Nz/object Lock can't be used in 'await' expression)rr�assertRaisesRegex�	TypeError�assertFalse�lockedrrrr�	test_lock0s�(zLockTests.test_lockc
�s�t��t��t��t��g}|D]�}t�d�IdH|�|���|�t	d��:|IdH�Wd�n1sp0YWd�n1s�0Y|�|���q dS)N�{�G�z�?z.object \w+ can't be used in 'await' expression)
rr�	Condition�	Semaphore�BoundedSemaphore�sleepr"r#r r!)rZ
primitivesrrrr�test_lock_by_with_statement;s��<z%LockTests.test_lock_by_with_statementc�svt���g}|����IdH��fdd�}�fdd�}�fdd�}t�||��}t�||��}t�d�IdH|�g|����t�d�IdH|�dg|�t�d�IdH|�dg|�t�||��}���t�d�IdH|�dd	g|����t�d�IdH|�gd
�|�|�|���|�|�	��|�|���|�|�	��|�|���|�|�	��dS)Nc�s���IdHr|�d�dS�N�T�r�append��result�rrr�c1Ts
z"LockTests.test_acquire.<locals>.c1c�s���IdHr|�d�dS�N�Tr-r/r1rr�c2Ys
z"LockTests.test_acquire.<locals>.c2c�s���IdHr|�d�dS�N�Tr-r/r1rr�c3^s
z"LockTests.test_acquire.<locals>.c3rr,r4�r,r4r7)
rrrr�create_taskr)�assertEqual�release�doner0�rr0r2r5r8�t1�t2�t3rr1r�test_acquireNs8zLockTests.test_acquirec�s�|�t�� tjt��d�}Wd�n1s00Y|�|��IdH�t�|���}t���|j	�|�
tj��|IdHWd�n1s�0Y|�|j
�dSr	)r
rrrrrrr:�	call_soon�cancel�assertRaises�CancelledErrorr"�_waiters)rrZtaskrrr�test_acquire_cancel�s.(zLockTests.test_acquire_cancelc�sR|�t�� tjt��d��Wd�n1s00Y�fdd�}t����}t�|d|��}t�d�IdH|���	��t�|dd��}t�d�IdH|�
t�j�d�t�|dd��}t�d�IdH|�
t�j�d	�|�
d�|��|��jd���t�d�IdH|���	��|�|���|�|���|IdHdS)
Nr
c�s<���IdHz|dur"|IdHW���n
���0dSr)rr<)�nameZblockerr1rr�lockit�s
z*LockTests.test_cancel_race.<locals>.lockit�Ar�Br,�Cr4)r
rrrrZ
create_futurer:r)rr#r;�lenrGZ
set_resultrD�	cancelledr"r=)rrJZfaZta�tb�tcrr1r�test_cancel_race�s*.
zLockTests.test_cancel_racec�s@t��}|�t��tj|d��Wd�n1s40Yd�d����fdd�}��fdd�}���IdHt�|���t�|��}t�|��}t�d�IdH|�|�|�	tj
���IdHWd�n1s�0Y|��d�|��d�|���
��o|���|��t�d�IdH|�|�
��dS)	Nr
rc�s"�d7����IdH�d7�dS�Nr,)rr)�
call_countr�
lock_countrrrJ�sz2LockTests.test_cancel_release_race.<locals>.lockitcs������dSr)rDr<r)rr?rr�trigger�sz3LockTests.test_cancel_release_race.<locals>.triggerr,r7)rrr
rrrr:r)rCrErFr;rrOr=rD)rrrJrVr@rAr)rTrrUr?r�test_cancel_release_race�s**
(z"LockTests.test_cancel_release_racec�s�|�t�� tjt��d�}Wd�n1s00Y|��IdH|�|���t�|���}t�	d�IdH|�
t|j�d�t�|���}|�
�|��t�	d�IdH|�|���|�|���|IdHdS)Nr
rr,)r
rrrrrrr#r:r)r;rNrGrDr<rO)rrrPrQrrr�test_finished_waiter_cancelled�s.z(LockTests.test_finished_waiter_cancelledc�sL|�t�� tjt��d�}Wd�n1s00Y|�t|j�dSr	)r
rrrrrE�RuntimeErrorr<rrrr�test_release_not_acquireds.z#LockTests.test_release_not_acquiredc�sp|�t�� tjt��d�}Wd�n1s00Y|��IdH|�|���|��|�	|���dSr	)
r
rrrrrrr#r<r"rrrr�test_release_no_waiterss.z!LockTests.test_release_no_waitersc	�snt��}|�|���|4IdH�$|�|���Wd�IdHq\1IdHsR0Y|�|���dSr)rrr"r#rrrrr�test_context_managers
8zLockTests.test_context_managerN)�__name__�
__module__�__qualname__rrrr$r*rBrHrRrWrXrZr[r\rrrrrs

30.	rc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�
EventTestsc�s�t��}|�t��tj|d�}Wd�n1s40Y|�|j|�|�t�� tjt��d�}Wd�n1s|0Y|�|jt���dSr	)	rrr
rr�Eventrrr)rr�evrrrrs*.zEventTests.test_ctor_loopc�s,t�t���t��}|�|jt���dSr)rZset_event_looprrarr�rrbrrrr'szEventTests.test_ctor_noloopc�s�|�t�� tjt��d�}Wd�n1s00Y|�t|��d��t�	t|��}|�
|�d�d�|��|�t|��d��|�t�	t|���|j
�t���|�dt|�v�|�t�	t|���dS)Nr
z[unset]>ZextrasZunsetz[set]>�	waiters:1)r
rrrarrrrrrr;�group�setrGr.rr)rrbrrrrr,s.zEventTests.test_reprc�s6|�t�� tjt��d��Wd�n1s00Y|�����g}�fdd�}�fdd�}�fdd�}t�||��}t�||��}t�d�IdH|�	g|�t�||��}��
�t�d�IdH|�	gd	�|�|�|���|�
|���|�|���|�
|���|�|���|�
|���dS)
Nr
c�s���IdHr|�d�dSrS��waitr.r/�rbrrr2Bsz EventTests.test_wait.<locals>.c1c�s���IdHr|�d�dS)Nr4rgr/rirrr5Fsz EventTests.test_wait.<locals>.c2c�s���IdHr|�d�dS)Nr7rgr/rirrr8Jsz EventTests.test_wait.<locals>.c3r)r7r,r4)r
rrrarr"�is_setr:r)r;rfrr=ZassertIsNoner0r>rrir�	test_wait;s*.zEventTests.test_waitc�s,t��}|��|��IdH}|�|�dSr)rrarfrhr)rrb�resrrr�test_wait_on_setaszEventTests.test_wait_on_setc�slt��}t�|���}t���|j�|�tj��|IdHWd�n1sR0Y|�	|j
�dSr)rrar:rhrrCrDrErFr"rG)rrbrhrrr�test_wait_cancelhs(zEventTests.test_wait_cancelc�sFt��}|�|���|��|�|���|��|�|���dSr)rrar"rjrfr�clearrcrrr�
test_clearqszEventTests.test_clearc�s�t���g}�fdd�}t�||��}t�d�IdH|�g|�������|�����������|�dt	�j
��t�d�IdH|�dg|�|�dt	�j
��|�|���|�|�
��dS)Nc�s���IdHr|�d�dSr+rgr/rirrr2s
z.EventTests.test_clear_with_waiters.<locals>.c1rr,)rrar:r)r;rfror"rjrNrGrr=r0�rr0r2�trrir�test_clear_with_waiters{s"z"EventTests.test_clear_with_waitersN)r]r^r_rrrrkrmrnrprsrrrrr`s
&	
r`c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�ConditionTestsc�srt��}|�t��Ltj|d�}|�|j|�tjt��d�}|�|jt���Wd�n1sd0YdSr	)	rrr
rrr&rrr)rr�condrrrr�szConditionTests.test_ctor_loopc�st��}|�|jt���dSr)rr&rrr�rrurrrr�szConditionTests.test_ctor_noloopc�s�t���g}�fdd�}�fdd�}�fdd�}t�||��}t�||��}t�||��}t�d�IdH|�g|�|�����|����IdH���	�t�d�IdH|�g|�|�������
�t�d�IdH|�dg|�|�������	d	�t�d�IdH|�dg|�|�������
�t�d�IdH|�dd	g|�|�������
�t�d�IdH|�gd
�|�|�����|�|���|�|���|�|���|�|���|�|���|�|���dS)Nc�s*���IdH���IdHr&|�d�dSr+�rrhr.r/�rurrr2�s
z$ConditionTests.test_wait.<locals>.c1c�s*���IdH���IdHr&|�d�dSr3rwr/rxrrr5�s
z$ConditionTests.test_wait.<locals>.c2c�s*���IdH���IdHr&|�d�dSr6rwr/rxrrr8�s
z$ConditionTests.test_wait.<locals>.c3rr,r4r9)
rr&r:r)r;r"r#rr�notifyr<r=r0r>rrxrrk�sL
zConditionTests.test_waitc�s�t��}|��IdHt�|���}t���|j�|�tj	��|IdHWd�n1s`0Y|�
|j�|�|�
��dSr)rr&rr:rhrrCrDrErFr"rGrr#)rrurhrrrrn�s(zConditionTests.test_wait_cancelc�s�t��}|��IdH|�|���t�|���}t�d�IdH|�|���|��IdH|�|���|�	�t�
��|j�t�
��|j
�z|IdHWntjy�Yn0|�|���dS)Nr)rr&rrr#r:rhr)r"ryrrCrDr<rF)rruZ	wait_taskrrr�test_wait_cancel_contested�s z)ConditionTests.test_wait_cancel_contestedc�s�|�t�� tjt��d��Wd�n1s00Yd���fdd�}t�|��}t�d�IdH���IdH���t�d�IdH|�	�t�d�IdH��
�t�d�IdH|�|���|���dS)Nr
Fc	�sN�4IdH�(d����IdHWd�IdHqJ1IdHs@0YdS)NT)rhr�ruZwaitedrr�wait_on_condszBConditionTests.test_wait_cancel_after_notify.<locals>.wait_on_condr)
r
rrr&rr:r)rryrDr<rrO)rr|�waiterrr{r�test_wait_cancel_after_notify
s.z,ConditionTests.test_wait_cancel_after_notifyc�sDt��}|�t��|��IdHWd�n1s60YdSr)rr&rErYrhrvrrr�test_wait_unacquired$sz#ConditionTests.test_wait_unacquiredc�s�t���d��fdd��g}��fdd�}t�||��}t�d�IdH|�g|����IdH������t�d�IdH|�g|�d����IdH������t�d�IdH|�dg|�|�|�	��|�|�
��dS)	NFcs�Srrr)�presultrr�	predicate-sz/ConditionTests.test_wait_for.<locals>.predicatec�s4���IdH����IdHr0|�d����dSr+)r�wait_forr.r<r/)rur�rrr22s

z(ConditionTests.test_wait_for.<locals>.c1rTr,�rr&r:r)r;rryr<rr=r0rqr)rur�r�r�
test_wait_for)s*zConditionTests.test_wait_forc�snt��}|�dd��IdH}|�gd�|�|�t��$|�dd��IdHWd�n1s`0YdS)NcSsgd�S)Nr9rrrrr�<lambda>R�z9ConditionTests.test_wait_for_unacquired.<locals>.<lambda>r9cSsdS)NFrrrrrr�Vr�)rr&r�r;rErY)rrurlrrr�test_wait_for_unacquiredNs
z'ConditionTests.test_wait_for_unacquiredc�sVt���g}�fdd�}�fdd�}�fdd�}t�||��}t�||��}t�||��}t�d�IdH|�g|����IdH��d����t�d�IdH|�dg|����IdH��d���d	����t�d�IdH|�gd
�|�|�|�	��|�|�
��|�|�	��|�|�
��|�|�	��|�|�
��dS)Nc�s2���IdH���IdHr.|�d����dSr+�rrhr.r<r/rxrrr2\s

z&ConditionTests.test_notify.<locals>.c1c�s2���IdH���IdHr.|�d����dSr3r�r/rxrrr5cs

z&ConditionTests.test_notify.<locals>.c2c�s2���IdH���IdHr.|�d����dSr6r�r/rxrrr8js

z&ConditionTests.test_notify.<locals>.c3rr,ir9r�r>rrxr�test_notifyXs6


zConditionTests.test_notifyc�s�t���g}�fdd�}�fdd�}t�||��}t�||��}t�d�IdH|�g|����IdH������t�d�IdH|�ddg|�|�|�	��|�|�
��|�|�	��|�|�
��dS)Nc�s2���IdH���IdHr.|�d����dSr+r�r/rxrrr2�s

z*ConditionTests.test_notify_all.<locals>.c1c�s2���IdH���IdHr.|�d����dSr3r�r/rxrrr5�s

z*ConditionTests.test_notify_all.<locals>.c2rr,r4)rr&r:r)r;r�
notify_allr<rr=r0)rr0r2r5r?r@rrxr�test_notify_all�s"zConditionTests.test_notify_allcCst��}|�t|j�dSr)rr&rErYryrvrrr�test_notify_unacquired�sz%ConditionTests.test_notify_unacquiredcCst��}|�t|j�dSr)rr&rErYr�rvrrr�test_notify_all_unacquired�sz)ConditionTests.test_notify_all_unacquiredc�s�t��}|�dt|�v�|�t�t|���|��IdH|�dt|�v�|j�t	�
��|�dt|�v�|�t�t|���|j�t	�
��|�dt|�v�|�t�t|���dS)NZunlockedr#rd�	waiters:2)rr&rrrrrrGr.rrrvrrrr�szConditionTests.test_reprc	�snt��}|�|���|4IdH�$|�|���Wd�IdHq\1IdHsR0Y|�|���dSr)rr&r"r#rrvrrrr\�s
8z#ConditionTests.test_context_managerc�sNd�fdd�	}|�IdH|t���IdHt��}||t�|��IdHdS)Nc	�s4|durt��}|dur"t�|�}��|j|���|�����|���|4IdH�2��|�����|���Wd�IdHq�1IdHs�0Y��|�����|���|4IdH�4��|�����|���Wd�IdH�q1IdH�s
0Y��|�����|���dSr)rrr&r�_lockr"r#r)rru�rrr�f�s"
8<z,ConditionTests.test_explicit_lock.<locals>.f)NN)rrr&)rr�rrr�r�test_explicit_lock�s
z!ConditionTests.test_explicit_lockc�sLt������j���fdd�}��fdd�}|�IdH|�IdHdS)Nc	�s���t��tj�d�Wd�n1s,0Yt��}�|_|4IdH�L��td��t�|�Wd�n1s~0YWd�IdHq�1IdHs�0YdS)Nr
�"loop argument must agree with lock)r
rrrrr �
ValueErrorr&r1�rrrr�wrong_loop_in_lock�s*�z?ConditionTests.test_ambiguous_loops.<locals>.wrong_loop_in_lockc
�s�t��}|4IdH�z��td��H��t��tj|�d�Wd�n1sR0YWd�n1sp0YWd�IdHq�1IdHs�0YdS)Nr�r
)rrr r�r
rr&r1r�rr�wrong_loop_in_cond�s�z?ConditionTests.test_ambiguous_loops.<locals>.wrong_loop_in_cond)rZnew_event_loopZ
addCleanup�close)rr�r�rr�r�test_ambiguous_loops�sz#ConditionTests.test_ambiguous_loopsc	�s�t��}|4IdH�Z|�tj��(tj|��dd�IdHWd�n1sP0YWd�IdHq�1IdHsz0YdS)Ng�?)Ztimeout)rr&rE�TimeoutErrorr�rh)rZ	conditionrrr�test_timeout_in_blocksz$ConditionTests.test_timeout_in_blockN)r]r^r_rrrkrnrzr~rr�r�r�r�r�r�rr\r�r�r�rrrrrt�s$	?%
4$"rtc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�SemaphoreTestsc�s�t��}|�t��tj|d�}Wd�n1s40Y|�|j|�|�t�� tjt��d�}Wd�n1s|0Y|�|jt���dSr	)	rrr
rrr'rrr)rr�semrrrrs*.zSemaphoreTests.test_ctor_loopc�st��}|�|jt���dSr)rr'rrr�rr�rrrrszSemaphoreTests.test_ctor_noloopc�sN|�t��"tjdt��d�}Wd�n1s20Y|�|���dS)Nrr
)r
rrr'rrr#r�rrr�test_initial_value_zero"s0z&SemaphoreTests.test_initial_value_zeroc�s�t��}|�t|��d��|�t�t|���|��IdH|�t|��d��|�dt|�v�|�t�t|���|j�	t
���|�dt|�v�|�t�t|���|j�	t
���|�dt|�v�|�t�t|���dS)Nz[unlocked, value:1]>r�waitersrdr�)rr'rrrrrrrGr.rrr�rrrr'szSemaphoreTests.test_reprc�slt��}|�d|j�|�td��|IdHWd�n1sB0Y|�|���|�d|j�dS)Nr,z4object Semaphore can't be used in 'await' expression)rr'r;�_valuer r!r"r#r�rrr�test_semaphore9s�(zSemaphoreTests.test_semaphorecCs|�ttjd�dS)N���)rEr�rr'r�rrr�test_semaphore_valueFsz#SemaphoreTests.test_semaphore_valuec�s�t�d��g}|����IdH�|����IdH�|������fdd�}�fdd�}�fdd�}�fdd	�}t�||��}t�||��}t�||��}t�d
�IdH|�dg|�|�����|�dt	�j
��|�d
�j�t�||��}	������|�d�j�t�d
�IdH|�d
�j�|�dt	|��|�����|�dt	�j
��|�d
�j�|�|�
��|�|���|||	g}
d
d�|
D�}|�dt	|�����tj|
�IdHdS)Nr7c�s���IdH|�d�dSr+r-r/�r�rrr2Qs
z'SemaphoreTests.test_acquire.<locals>.c1c�s���IdH|�d�dSr3r-r/r�rrr5Vs
z'SemaphoreTests.test_acquire.<locals>.c2c�s���IdH|�d�dSr6r-r/r�rrr8[s
z'SemaphoreTests.test_acquire.<locals>.c3c�s���IdH|�d�dS)N�Tr-r/r�rr�c4`s
z'SemaphoreTests.test_acquire.<locals>.c4rr,r4cSs g|]}|��r|��r|�qSr)r=r0��.0rrrrr�
<listcomp>r�z/SemaphoreTests.test_acquire.<locals>.<listcomp>)rr'rrr"r#r:r)r;rNrGr�r<r=r0�gather)rr0r2r5r8r�r?r@rA�t4Z
race_tasksZ
done_tasksrr�rrBIsD

zSemaphoreTests.test_acquirec�s�t��}|��IdHt�|���}t���|j�|�tj��|IdHWd�n1s`0Y|�	|j
p�tdd�|j
D���dS)Ncss|]}|��VqdSr�r=)r�r}rrr�	<genexpr>�r�z5SemaphoreTests.test_acquire_cancel.<locals>.<genexpr>)rr'rr:rrCrDrErFrrG�all)rr�rrrrrH�s(�z"SemaphoreTests.test_acquire_cancelc�s�tjdd�}t�|���}t�|���}t�|���}t�|���}t�d�IdH|��|��|��t�d�IdHtdd�||fD��}|�|d�|�	|�
��|�|�
��|��|��t�d�IdHdS)Nr��valuecss|]}|��VqdSrr�r�rrrr��r�zCSemaphoreTests.test_acquire_cancel_before_awoken.<locals>.<genexpr>r,)rr'r:rr)rDr<�sumr;rr=r")rr�r?r@rAr�Znum_donerrr�!test_acquire_cancel_before_awoken�s"z0SemaphoreTests.test_acquire_cancel_before_awokenc�sxtjdd�}t�|���}t�|���}t�d�IdH|��|��t�d�IdH|�|���|�|�	��dS)Nrr�)
rr'r:rr)rDr<rr#r=)rr�r?r@rrr�test_acquire_hang�sz SemaphoreTests.test_acquire_hangc�sL|�t�� tjt��d�}Wd�n1s00Y|�t|j�dSr	)r
rrr(rrEr�r<r�rrrrZ�s.z(SemaphoreTests.test_release_not_acquiredc�s>t��}|��IdH|�|���|��|�|���dSr)rr'rrr#r<r"r�rrrr[�s
z&SemaphoreTests.test_release_no_waitersc�snt�d��g���fdd�}t�|d��}t�|d��}t�|d��}t�|||�IdH|�gd���dS)Nr,c�sp���IdH��|�d��t�d�IdH������IdH��|�d��t�d�IdH���dS)NZ_1r%Z_2)rr.rr)r<)�tag�r0r�rr�coro�sz4SemaphoreTests.test_acquire_fifo_order.<locals>.coror2r5r8)Zc1_1Zc2_1Zc3_1Zc1_2Zc2_2Zc3_2)rr'r:r�r;)rr�r?r@rArr�r�test_acquire_fifo_order�s
�z&SemaphoreTests.test_acquire_fifo_orderN)r]r^r_rrr�rr�r�rBrHr�r�rZr[r�rrrrr�s

=
r��__main__)�__doc__Zunittestr�rerZSTR_RGX_REPR�compilerrZIsolatedAsyncioTestCaserr`rtr�r]�mainrrrr�<module>s&�
}|N