HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_context.cpython-37.opt-1.pyc
B

��gOu�@sddlZddlZddlZddlZddlZddlZddlZddlZyddl	m
Z
Wnek
rhdZ
YnXdd�ZGdd�dej
�ZGdd�d�ZGd	d
�d
e�ZGdd�d�ZGd
d�de�ZGdd�de�Ze�e
dkd�Gdd�dej
��Zedk�re��dS)�N)�hamtcst����fdd��}|S)z*Needed to make reftracking test mode work.cst��}|j�f|�|�S)N)�contextvars�Context�run)�args�kwargs�ctx)�func��-/usr/local/lib/python3.7/test/test_context.py�wrappersz!isolated_context.<locals>.wrapper)�	functools�wraps)r	rr
)r	r�isolated_contextsrc@s�eZdZdd�Zedd��Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zedd��Z
dd�Zdd�Zdd�Zedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zd%d&�Zed'd(��Zd)d*�Zd+S),�ContextTestc	Cs�|�td��t��WdQRX|�td��t�d�WdQRXt�d�}|�|jd�|�t��d|_WdQRX|�t	|�t	d��dS)Nztakes exactly 1z
must be a str��aaa�bbb)
�assertRaisesRegex�	TypeErrorr�
ContextVar�assertEqual�name�assertRaises�AttributeError�assertNotEqual�hash)�self�cr
r
r�test_context_var_new_1s
z"ContextTest.test_context_var_new_1cCs�t�d�}|�dt|��tjddd�}|�dt|��g}tjd|d�}|�|�|�dt|��|�dt|��|�d�}|�t|�t|��|�dt|��|�|�|�dt|��dS)N�a�{)�defaultZ123z...rz used )rr�assertIn�repr�append�set�assertNotIn�reset)rrZlst�tr
r
r�test_context_var_repr_1)s



z#ContextTest.test_context_var_repr_1c	Cs�|�td��Gdd�dtj�}WdQRX|�td��Gdd�dtj�}WdQRX|�td��Gdd�dtj�}WdQRXdS)Nznot an acceptable base typec@seZdZdS)z<ContextTest.test_context_subclassing_1.<locals>.MyContextVarN)�__name__�
__module__�__qualname__r
r
r
r�MyContextVar?sr.c@seZdZdS)z9ContextTest.test_context_subclassing_1.<locals>.MyContextN)r+r,r-r
r
r
r�	MyContextDsr/c@seZdZdS)z7ContextTest.test_context_subclassing_1.<locals>.MyTokenN)r+r,r-r
r
r
r�MyTokenHsr0)rrrrr�Token)rr.r/r0r
r
r�test_context_subclassing_1=sz&ContextTest.test_context_subclassing_1c	Cs||�td��t�d�WdQRX|�td��tjddd�WdQRX|�td��tjdd�WdQRXtjfi�dS)Nz
any argumentsr)r )rrrr)rr
r
r�test_context_new_1KszContextTest.test_context_new_1c	Csnt��}|�td��|dWdQRX|�td��d|kWdQRX|�td��|�d�WdQRXdS)NzContextVar key was expectedr)rrrr�get)rrr
r
r�test_context_typerrors_1Tsz$ContextTest.test_context_typerrors_1cCst��}|�|tj�dS)N)r�copy_contextZassertIsInstancer)rrr
r
r�test_context_get_context_1^sz&ContextTest.test_context_get_context_1c	Cs,t��}|�td��|��WdQRXdS)Nzmissing 1 required)rrrrr)rrr
r
r�test_context_run_1bszContextTest.test_context_run_1cCs�t��}dd�}x�|t�|�fD]�}|�|�|�dddif�|�|�|d�dddif�|�|j|dd	�dddd
�f�|�|j|ddd	�dddd
�f�i}|�|j|df|�dddif�|�|i�q WdS)
Nc_sd|d<|d7}||fS)N�foo�spam)�barr
)rrr
r
rr	ksz,ContextTest.test_context_run_2.<locals>.func)r;r:r9r)rr;�)r )r r:�)r=r;)rrr
�partialrr)rrr	�fr r
r
r�test_context_run_2hs zContextTest.test_context_run_2c	Cs�t��}dd�}|�t��|�|�WdQRX|�t��|�|dd�WdQRX|�t��|j|dddd�WdQRXdS)Nc_sdddS)Nrrr
)rrr
r
rr	�sz,ContextTest.test_context_run_3.<locals>.funcrr<r!)r )rrr�ZeroDivisionErrorr)rrr	r
r
r�test_context_run_3�szContextTest.test_context_run_3cspt��}t���t�d����fdd������fdd�}|�|�}��||���|�d����|�dS)N�varcs����d��dS)N)�assertIsNoner4r
)rrCr
r�func2�sz-ContextTest.test_context_run_4.<locals>.func2csb����d����d���������d�d�t��}��t|�d���|�d�|S)Nr:r)rDr4r&rrrr6�len)Zcur)�ctx2rErrCr
r�func1�s

z-ContextTest.test_context_run_4.<locals>.func1r:)rrrrrr#)r�ctx1rHZreturned_ctxr
)rGrErrCr�test_context_run_4�s

zContextTest.test_context_run_4c	sTt��}t�d����fdd�}��t��|�|�WdQRX����d��dS)NrCcs&����d����d�dddS)Nr:rr)rDr4r&r
)rrCr
rr	�s
z,ContextTest.test_context_run_5.<locals>.func)rrrrrArrDr4)rrr	r
)rrCr�test_context_run_5�s
zContextTest.test_context_run_5cs4t���tjddd�����fdd�}��|�dS)Nr r)r"csP�����d����������d������d�������d�dS)Nr�*)rr4rDr&r
)rrrr
r�fun�s

z+ContextTest.test_context_run_6.<locals>.fun)rrrr)rrMr
)rrrr�test_context_run_6�szContextTest.test_context_run_6cs&t������fdd������dS)Nc	s&��td������WdQRXdS)Nzis already entered)r�RuntimeErrorrr
)rrMrr
rrM�sz+ContextTest.test_context_run_7.<locals>.fun)rrr)rr
)rrMrr�test_context_run_7�szContextTest.test_context_run_7c	Cs�t�d�}|�t��|��WdQRX|�|�d��|�d�}|�|��d�|�|�d�d�|�|j	|j
�|�|j	tjj
�|�|j|�|�d�}|�|��d�|�|�d�d�|�|j	d�|�
|�|�|��d�|�|�d�d�|�d�|�td��|�
|�WdQRX|�|��d�t��}|�||�|�
|�|�td��|�
|�WdQRX|�|�d��|�||�|�||d�|�|�|d�d�|�t|�d�|�t|���|dfg�|�t|���dg�|�t|���|g�|�t|�|g�t��}|�||�|�t��||WdQRX|�|�|d�d�|�t|�d�|�t|�g�dS)	NrrLr:Zspam2zhas already been used�aarr)rrr�LookupErrorr4rDr&r�assertIs�	old_value�MISSINGr1rCr(rrOr6r#rF�list�items�values�keysr'�KeyError)rrZt0r)rIrGr
r
r�test_context_getset_1�sT





z!ContextTest.test_context_getset_1c	CsDt�d�}t�d�}|�d�}|�td��|�|�WdQRXdS)N�v1�v2rLzby a different)rrr&r�
ValueErrorr()rr\r]Zt1r
r
r�test_context_getset_2s



z!ContextTest.test_context_getset_2cs4tjddd��t������fdd�}��|�dS)NrrL)r"c	s������d���t����WdQRX������������d�d��������t����g���d�}��t�����g�����d���	|���t����g���t����WdQRXdS)NrLr:r)
rr4rrZrDr'rVrYr&r()r))rrrr
rrMs

z.ContextTest.test_context_getset_3.<locals>.fun)rrrr)rrMr
)rrrr�test_context_getset_3sz!ContextTest.test_context_getset_3c	CsJtjddd�}t��}|�|jd�}|�td��|�|�WdQRXdS)NrrL)r"rzdifferent Context)rrrrr&rr^r()rrr�tokr
r
r�test_context_getset_4's
z!ContextTest.test_context_getset_4csHtjddd����g���fdd�}t���|������g�dS)NrrL)r"cs.��g�����d������dg�dS)NrL)r&r4r%rr
)rrr
rrM6s
z.ContextTest.test_context_getset_5.<locals>.fun)rrr&r6rrr4)rrMr
)rrr�test_context_getset_51s

z!ContextTest.test_context_getset_5csDt���tjddd������fdd�}��fdd����|�dS)NrrL)r"csz��d����}��|�d���d�����d���|�d�|�������d���|�d�dS)N�
��)r&�copyrr)rG)rrI�ctx2_funrr
r�ctx1_funBs


z1ContextTest.test_context_copy_1.<locals>.ctx1_funcs.�����d���d������d�dS)Nrdrf)rr4r&r
)rrr
rrhPs
z1ContextTest.test_context_copy_1.<locals>.ctx2_fun)rrrr)rrir
)rrIrhrr�test_context_copy_1>s
zContextTest.test_context_copy_1csbt�d����fdd�}tjjdd�}zt|�|td���}Wd|��X��	|ttd���dS)N�cvarcsJxDtd�D]8}��||�t�t�dd�������||�q
W|S)Nrdg����MbP?g�������?)�ranger&�timeZsleep�randomZuniformrr4)Znum�i)rkrr
r�sub[s
z/ContextTest.test_context_threads_1.<locals>.subrd)�max_workers)
rr�
concurrentZfuturesZThreadPoolExecutorrV�maprlZshutdownr)rrp�tp�resultsr
)rkrr�test_context_threads_1Ws

z"ContextTest.test_context_threads_1cCstj}|�|t|�dS)N)rrr�str)rZclssr
r
r�test_contextvar_getitemisz#ContextTest.test_contextvar_getitemN)r+r,r-rrr*r2r3r5r7r8r@rBrJrKrNrPr[r_r`rbrcrjrvrxr
r
r
rrs*	

	6	

rc@s6eZdZdZdd�dd�Zdd�Zdd�Zd	d
�ZdS)�HashKeyN)�error_on_eq_tocCs||_||_||_dS)N)rrrz)rrrrzr
r
r�__init__tszHashKey.__init__cCsd|j�d|j�d�S)Nz
<Key name:z hash:�>)rr)rr
r
r�__repr__zszHashKey.__repr__cCs|jdk	r|jjrt�|jS)N)�_crasher�
error_on_hash�HashingErrorr)rr
r
r�__hash__}szHashKey.__hash__cCs�t|t�stS|jdk	r$|jjr$t�|jdk	rL|j|krLtd|�d|����|jdk	rt|j|krttd|�d|����|j|j	f|j|j	fkS)Nzcannot compare z to )
�
isinstancery�NotImplementedr~�error_on_eq�EqErrorrzr^rr)r�otherr
r
r�__eq__�s
zHashKey.__eq__)r+r,r-r~r{r}r�r�r
r
r
rryqs
rycs(eZdZ�fdd�Z�fdd�Z�ZS)�KeyStrcs tjdk	rtjjrt�t���S)N)ryr~rr��superr�)r)�	__class__r
rr��szKeyStr.__hash__cs"tjdk	rtjjrt�t��|�S)N)ryr~r�r�r�r�)rr�)r�r
rr��sz
KeyStr.__eq__)r+r,r-r�r��
__classcell__r
r
)r�rr��sr�c@s,eZdZddd�dd�Zdd�Zdd�Zd	S)
�HaskKeyCrasherF)rr�cCs||_||_dS)N)rr�)rrr�r
r
rr{�szHaskKeyCrasher.__init__cCstjdk	rtd��|t_dS)Nzcannot nest crashers)ryr~rO)rr
r
r�	__enter__�s
zHaskKeyCrasher.__enter__cGs
dt_dS)N)ryr~)r�excr
r
r�__exit__�szHaskKeyCrasher.__exit__N)r+r,r-r{r�r�r
r
r
rr��sr�c@seZdZdS)r�N)r+r,r-r
r
r
rr��sr�c@seZdZdS)r�N)r+r,r-r
r
r
rr��sr�z!_testcapi lacks "hamt()" functionc@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%d&�Zd'd(�Zd)d*�Zd+d,�Zd-S).�HamtTestcCsntdd�}tdd�}|�||�|�t|�t|��t�}d||<d||<|�||d�|�||d�dS)Nrdrrr �b)ryrrr�dict)r�k1�k2�dr
r
r�test_hashkey_helper_1�s

zHamtTest.test_hashkey_helper_1cCst�}d}dS)N)r)r�hr
r
r�test_hamt_basics_1�szHamtTest.test_hamt_basics_1cCsBt�}|�t|�d�|�dd�}|�||�|�t|�d�|�t|�d�|�|�d��|�|�dd�d�|�|�d�d�|�dd�}|�||�|�t|�d�|�t|�d�|�t|�d�|�|�d�d�|�|�d�d�|�|�d��|�|�d��|�|�d��|�|�d�d�d}}}dS)Nrr r�rrLrdr<)rrrFr&�assertIsNotrDr4)rr��h2�h3r
r
r�test_hamt_basics_2�s*zHamtTest.test_hamt_basics_2cCs4t�}t�}|�d|�}|�d|�}|�||�dS)N�1)r�objectr&rS)rr��o�h1r�r
r
r�test_hamt_basics_3�s
zHamtTest.test_hamt_basics_3cCsft�}|�dg�}|�dg�}|�||�|�t|�d�|�t|�d�|�|�d�|�d��dS)N�keyr)rr&r�rrFr4)rr�r�r�r
r
r�test_hamt_basics_4�szHamtTest.test_hamt_basics_4c	Cs�tdd�}tdd�}tdd�}t�}|�|d�}|�|d�}|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|d�}|�|d�}|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�|�|�d�|�t|�d	�|�t|�d
�|�t|�d�|�t|�d�|�t|�d�dS)
NrdrrZcccr r�ZccrQrrr<�)ryrr&rr4rF)	rr�r�Zk3r�r�r�Zh4Zh5r
r
r�test_hamt_collision_1�s8


zHamtTest.test_hamt_collision_1cCsd}d}d}d}d}�x�t|�D�]�}t�}t�}�xt|�D]�}	t|	�}
|	|s�tdd��(|�t��|�|
|	�WdQRXWdQRX|�|
|	�}|	|s�tdd��*|�t��|�	t|	��WdQRXWdQRX|	||
<|�
t|�t|��|	|s>|�
t|���t|����|�
t|���t|����q>W|�
t|�|�x*t|�D]}
|�
|�	t|
�d	�|
��qRWt
t|��}t�|��x8t|�D�]*\}}	t|	�}
||�s�tdd��&|�t��|�|
�WdQRXWdQRX||�s,tdd��*|�t��|�t|	��WdQRXWdQRX|�|
�}|�
|�	|
d	�d	�||
=|�
t|�t|��||d
k�r~|}
|��}||�s�|�
t|���t|����|�
t|���t|�����q�W|�
t|�d�|�
t|�d�x(|D] }
|�
|
�	t|
��||
��q�W|�
t|�t|
��x�t|�D]�\}	}
|
�t|
��}
|�
|
�	t|
�d	�d	�|�t|
�d�|�
t|�t|��|	|�s.|�
t|���t|����|�
t|���t|�����q.W|�
t|�d�|�
t|�d�|�
t
|���g�q WdS)NiXi��ar=r�T)r)r�z	not foundr<r)rlrr�r�r�rr�r&r�r4rrFrWrVrnZshuffle�	enumerate�deletergrYrw�poprX)rZCOLLECTION_SIZEZTEST_ITERS_EVERYZCRASH_HASH_EVERYZCRASH_EQ_EVERYZ
RUN_XTIMES�_r�r�ror�Zkeys_to_deleteZiter_iZhmZdmr
r
r�test_hamt_stresss� " 


"

"
 
"zHamtTest.test_hamt_stressc	Csbtdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}tdd
|d�}t�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}t|�}	|�|�}|�t|�|	d�|�td��|�|�WdQRX|�|�}|�t|�|	d�|�|�}
|�|
|�|�|�}|�t|�|	d�|�|�	|d�d�|�|�	|�d�|�|�	|�d�dS)N�d�A�e�B�f�C�g�D�h�Ei�����Z�Er)rzr r�rr��erzcannot comparer<r�rL)
ryrr&rFr�rrr^rSr4)rr�r�r�r�r�r�r�r��orig_lenr�r
r
r�test_hamt_delete_1us6





	



zHamtTest.test_hamt_delete_1c
	Cs�tdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}tdd
|d�}t�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}t|�}	|�td��|�|�WdQRX|�|�}|�t|�|	�|�|�}|�t|�|	d�|�|�}|�t|�|	d�|�|�}|�t|�|	d�|�|�|�d�|�|�|�d�|�|�}|�|�}|�|�}|�|�}|�t|�d�dS)Nr�r�i)r�i��r�r�r�r�r�i����r�r�)rzr r�rr�r�zcannot comparerr<r�r)	ryrr&rFrr^r�rr4)
rr�r�r�r�r�r�r�r�r�r
r
r�test_hamt_delete_2�s>













zHamtTest.test_hamt_delete_2cCs�tdd�}tdd�}tdd�}tdd�}tdd	�}t�}|�|d
�}|�|d�}|�|d�}|�|d
�}|�|d�}t|�}|�|�}|�t|�|d�|�|�}|�t|�|d�|�|�|�d�|�|�|�d�dS)Nr�r�r�r�i�r�r�r�r�r r�rr�r�rr<)ryrr&rFr�rr4)rr�r�r�r�r�r�r�r
r
r�test_hamt_delete_3�s$






zHamtTest.test_hamt_delete_3cCstdd�}tdd�}tdd�}tdd�}tdd�}t�}|�|d	�}|�|d
�}|�|d�}|�|d�}|�|d
�}t|�}|�|�}|�t|�|d�|�|�}|�t|�|d�|�|�}|�t|�|d�|�|�}|�t|�|d�|�|�}|�t|�d�dS)Nr�r�r�r�i�r�r�r�r r�rr�r�rr<r��r)ryrr&rFr�r)rr�r�r�r�r�r�r�r
r
r�test_hamt_delete_4�s,









zHamtTest.test_hamt_delete_4cCs,t�}g}x:td�D].}t|t|��}|�|�|�|d|���}qWtdd�}|�|d�}|�t|�d�|�|d�}|�t|�d�|�|�}|�t|�d�|�|d�}|�t|�d�|�|d	�}|�t|�d
�|�|d	�}|�t|�d
�x|D]}|�|�}�qW|�t|�d�dS)N�zval-�Z18Z	collision�r<�r�r)	rrlryrwr%r&rrFr�)rr�rYror�Zcollision_key16r
r
r�test_hamt_delete_5$s,



zHamtTest.test_hamt_delete_5c	
Cs�tdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}t�}|�|d
�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}|��}|�tt|��|d
f|df|df|df|df|dfh�dS)Nr�r�i)r�i��r�r�r�r�r��n�Fr r�rr�r�r?)ryrr&rWrrV)	rr�r�r�r�r�r�r��itr
r
r�test_hamt_items_1Us"






zHamtTest.test_hamt_items_1c	
Cs�tdd�}tdd�}tdd�}tdd�}tdd�}td	d
�}t�}|�|d�}|�|d�}|�|d
�}|�|d�}|�|d�}|�|d�}|��}|�tt|��|df|df|d
f|df|df|dfh�dS)Nr�r�r�r�i�r�r�r�r�r�r r�rr�r�r?)ryrr&rWrrV)	rr�r�r�r�r�r�r�r�r
r
r�test_hamt_items_2js"






zHamtTest.test_hamt_items_2c	Cs�tdd�}tdd�}tdd�}tdd�}tdd�}td	d
�}t�}|�|d�}|�|d�}|�|d
�}|�|d�}|�|d�}|�|d�}|�tt|����||||||h�|�tt|��||||||h�dS)Nr�r�r�r�i�r�r�r�r�r�r r�rr�r�r?)ryrr&rrVrY)rr�r�r�r�r�r�r�r
r
r�test_hamt_keys_1s





$zHamtTest.test_hamt_keys_1cCs2t�}|�t|���d�|�t|���g�dS)Nr)rrrFrWrV)rr�r
r
r�test_hamt_items_3�szHamtTest.test_hamt_items_3cCs�tdd�}tdd�}tdd�}tdd�}tdd	�}t�}|�|d
�}|�|d�}|�|d�}|�|d
�}t�}|�|d
�}|�||k�|�||k�|�|d�}|�||k�|�||k�|�|d�}|�||k�|�||k�|�|d�}|�||k�|�||k�|�|d
�}|�||k�|�||k�|�|d�}|�||k�|�||k�|�|�}|�||k�|�||k�|�|d
�}|�||k�|�||k�dS)Nr�r�r�r�i�r�r��xr�r r�rr�Zd2r�)ryrr&�assertFalse�
assertTruer�)rr�r�r�r�r�r�r�r
r
r�test_hamt_eq_1�sF





zHamtTest.test_hamt_eq_1c	Cs�tdd�}tdd|d�}t�}|�|d�}t�}|�|d�}|�td��||kWdQRX|�td��||kWdQRXdS)Nr�r�r�)rzr zcannot compare)ryrr&rr^)rr�r�r�r�r
r
r�test_hamt_eq_2�s
zHamtTest.test_hamt_eq_2cCs�tdd�}t�}|�dd�}t�|�}g}|�|�|�|�g}|�|�|�|�|�||�}~~~t��t��t��|�|��dS)Nr�r�r)	ryrr&�weakref�refr%�gc�collectrD)rr�r�r�r r�r
r
r�test_hamt_gc_1�s 





zHamtTest.test_hamt_gc_1cCsxtdd�}tdd�}t�}|�|d�}|�||�}t�|�}|��}t|�~~t��t��t��|�	|��dS)Nr�r�r�r�r )
ryrr&r�r�rW�nextr�r�rD)rr�r�r�r��hir
r
r�test_hamt_gc_2�s


zHamtTest.test_hamt_gc_2c
Cs�tdd�}tdd�}tdd�}t�}|�|d�}|�||k�|�||k�|�t��$tdd��||kWdQRXWdQRX|�t��$tdd��||kWdQRXWdQRXdS)	Nr�r�r�r�rT)r�)r)	ryrr&r�r�rr�r�r�)rr��AAr�r�r
r
r�test_hamt_in_1s


zHamtTest.test_hamt_in_1c
Cs�tdd�}tdd�}tdd�}t�}|�|d�}|�||d�|�||d�|�t��||WdQRX|�t��$tdd��||WdQRXWdQRX|�t��$tdd��||WdQRXWdQRXdS)	Nr�r�r�r�rT)r�)r)	ryrr&rrrZr�r�r�)rr�r�r�r�r
r
r�test_hamt_getitem_1s


zHamtTest.test_hamt_getitem_1N)r+r,r-r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
r
r
rr��s,	%Y-4$*1/r��__main__)�concurrent.futuresrrrr
r�rnrmZunittestr�Z	_testcapir�ImportErrorrZTestCaserryrwr�r��	Exceptionr�r�ZskipIfr�r+�mainr
r
r
r�<module>s8
	Z!
|