Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.15.138.33
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_context.cpython-310.pyc
o

`b�t�@sddlZddlZddlZddlZddlZddlZddlZddlZzddl	m
Z
Wney3dZ
Ynwdd�ZGdd�dej
�ZGdd�d�ZGd	d
�d
e�ZGdd�d�ZGd
d�de�ZGdd�de�Ze�e
dud�Gdd�dej
��Zedkr�e��dSdS)�N��hamtcst����fdd��}|S)z*Needed to make reftracking test mode work.cs t��}|j�g|�Ri|��S�N��contextvars�Context�run)�args�kwargs�ctx��func��:/usr/local/python-3.10/lib/python3.10/test/test_context.py�wrappersz!isolated_context.<locals>.wrapper)�	functools�wraps)r
rrr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)S)*�ContextTestcCs�|�td��t��Wd�n1swY|�td��
t�d�Wd�n1s0wYt�d�}|�|jd�|�t��d|_Wd�n1sTwY|�t	|�t	d��dS)Nztakes exactly 1z
must be a str��aaa�bbb)
�assertRaisesRegex�	TypeErrorr�
ContextVar�assertEqual�name�assertRaises�AttributeError�assertNotEqual�hash)�self�crrr�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)r!r"Zlst�trrr�test_context_var_repr_1)s



z#ContextTest.test_context_var_repr_1cCs�|�td��Gdd�dtj�}Wd�n1swY|�td��Gdd�dtj�}Wd�n1s9wY|�td��Gdd�dtj�}Wd�dS1sYwYdS)Nznot an acceptable base typec@�eZdZdS)z<ContextTest.test_context_subclassing_1.<locals>.MyContextVarN��__name__�
__module__�__qualname__rrrr�MyContextVar?sr5c@r0)z9ContextTest.test_context_subclassing_1.<locals>.MyContextNr1rrrr�	MyContextD�r6c@r0)z7ContextTest.test_context_subclassing_1.<locals>.MyTokenNr1rrrr�MyTokenHr7r8)rrrrr�Token)r!r5r6r8rrr�test_context_subclassing_1=s��"�z&ContextTest.test_context_subclassing_1cCs�|�td��
t�d�Wd�n1swY|�td��tjddd�Wd�n1s3wY|�td��tjdd�Wd�n1sOwYtjdii��dS)Nz
any argumentsr�r$r)rrrr�r!rrr�test_context_new_1Ks���zContextTest.test_context_new_1cCs�t��}|�td��|dWd�n1swY|�td��d|vWd�n1s3wY|�td��|�d�Wd�dS1sOwYdS)NzContextVar key was expectedr)rrrr�get�r!rrrr�test_context_typerrors_1Ts
�
�"�z$ContextTest.test_context_typerrors_1cCst��}|�|tj�dSr)r�copy_contextZassertIsInstancerr?rrr�test_context_get_context_1^sz&ContextTest.test_context_get_context_1cCsBt��}|�td��
|��Wd�dS1swYdS)Nzmissing 1 required)rrrrrr?rrr�test_context_run_1bs
"�zContextTest.test_context_run_1cCs�t��}dd�}|t�|�fD]X}|�|�|�dddif�|�|�|d�dddif�|�|j|dd	�dddd
�f�|�|j|ddd	�dddd
�f�i}|�|j|dfi|��dddif�|�|i�qdS)
Nc_sd|d<|d7}||fS)N�foo�spam��barr�r	r
rrrr
ksz,ContextTest.test_context_run_2.<locals>.funcrFrErDr)rrG�r;)r$rE�)rJrG)rrr�partialrr)r!rr
�fr$rrr�test_context_run_2hs(��
��zContextTest.test_context_run_2cCs�t��}dd�}|�t��
|�|�Wd�n1swY|�t��|�|dd�Wd�n1s9wY|�t��|j|dddd�Wd�dS1sXwYdS)Nc_sdddS)NrrrrHrrrr
�sz,ContextTest.test_context_run_3.<locals>.funcrrIr%r;)rrr�ZeroDivisionErrorr�r!rr
rrr�test_context_run_3�s��"�zContextTest.test_context_run_3cspt��}t���t�d����fdd������fdd�}|�|�}��||���|�d����|�dS)N�varcs����d��dSr)�assertIsNoner>r�r!rQrr�func2�sz-ContextTest.test_context_run_4.<locals>.func2csb����d����d���������d�d�t��}��t|�d���|�d�|S)NrEr)rRr>r+rrrrA�len)Zcur��ctx2rTr!rQrr�func1�s

z-ContextTest.test_context_run_4.<locals>.func1rE)rrrrrr()r!�ctx1rXZreturned_ctxrrVr�test_context_run_4�s

zContextTest.test_context_run_4csht��}t�d����fdd�}��t��
|�|�Wd�n1s%wY����d��dS)NrQcs&����d����d�dddS)NrErr)rRr>r+rrSrrr
�s
z,ContextTest.test_context_run_5.<locals>.func)rrrrrNrrRr>rOrrSr�test_context_run_5�s
�zContextTest.test_context_run_5cs4t���tjddd�����fdd�}��|�dS)Nr$rr&csP�����d����������d������d�������d�dS)Nr�*)rr>rRr+r�r"rr!rr�fun�s

z+ContextTest.test_context_run_6.<locals>.fun�rrrr�r!r^rr]r�test_context_run_6�szContextTest.test_context_run_6cs&t������fdd������dS)Ncs<��td������Wd�dS1swYdS)Nzis already entered)r�RuntimeErrorrr�rr^r!rrr^�s"�z+ContextTest.test_context_run_7.<locals>.funrr<rrcr�test_context_run_7�szContextTest.test_context_run_7cCs�t�d�}|�t��|��Wd�n1swY|�|�d��|�d�}|�|��d�|�|�d�d�|�|j	|j
�|�|j	tjj
�|�|j|�|�d�}|�|��d�|�|�d�d�|�|j	d�|�
|�|�|��d�|�|�d�d�|�d�|�td��
|�
|�Wd�n1s�wY|�|��d�t��}|�||�|�
|�|�td��
|�
|�Wd�n1s�wY|�|�d��|�||�|�||d�|�|�|d�d�|�t|�d�|�t|���|dfg�|�t|���dg�|�t|���|g�|�t|�|g�t��}|�||�|�t��||Wd�n	1�sLwY|�|�|d�d�|�t|�d�|�t|�g�dS)	Nr"r\rEZspam2zhas already been used�aarr)rrr�LookupErrorr>rRr+r�assertIs�	old_value�MISSINGr9rQr-rrbrAr(rU�list�items�values�keysr,�KeyError)r!r"�t0r.rYrWrrr�test_context_getset_1�s\

�



�
�
�z!ContextTest.test_context_getset_1cCsZt�d�}t�d�}|�d�}|�td��|�|�Wd�dS1s&wYdS)N�v1�v2r\zby a different)rrr+r�
ValueErrorr-)r!rqrr�t1rrr�test_context_getset_2s


"�z!ContextTest.test_context_getset_2cs4tjddd��t������fdd�}��|�dS)Nr"r\r&cs�����d���t����Wd�n1swY������������d�d��������t����g���d�}��t�����g�����d���	|���t����g���t��
��Wd�dS1swYdS)Nr\rEr)
rr>rrnrRr,rjrmr+r-)r.r]rrr^s 
�


"�z.ContextTest.test_context_getset_3.<locals>.fun)rrrrr`rr]r�test_context_getset_3sz!ContextTest.test_context_getset_3cCs`tjddd�}t��}|�|jd�}|�td��|�|�Wd�dS1s)wYdS)Nr"r\r&rzdifferent Context)rrrrr+rrsr-)r!r"r�tokrrr�test_context_getset_4's"�z!ContextTest.test_context_getset_4csHtjddd����g���fdd�}t���|������g�dS)Nr"r\r&cs.��g�����d������dg�dS)Nr\)r+r>r*rr�r"r!rrr^6s
z.ContextTest.test_context_getset_5.<locals>.fun)rrr+rArrr>r`rryr�test_context_getset_51s

z!ContextTest.test_context_getset_5csDt���tjddd������fdd�}��fdd����|�dS)Nr"r\r&csz��d����}��|�d���d�����d���|�d�|�������d���|�d�dS)N�
��)r+�copyrr)rW�r"rY�ctx2_funr!rr�ctx1_funBs


z1ContextTest.test_context_copy_1.<locals>.ctx1_funcs.�����d���d������d�dS)Nr{r})rr>r+rryrrr�Ps
z1ContextTest.test_context_copy_1.<locals>.ctx2_funr_)r!r�rrr�test_context_copy_1>s
zContextTest.test_context_copy_1csjt�d����fdd�}tjjdd�}zt|�|td���}W|��n|��w��	|ttd���dS)N�cvarcsFtd�D]}��||�t�t�dd�������||�q|S)Nr{g����MbP?g�������?)�ranger+�time�sleep�random�uniformrr>)�num�i�r�r!rr�sub[s
z/ContextTest.test_context_threads_1.<locals>.subr{)�max_workers)
rr�
concurrent�futures�ThreadPoolExecutorrj�mapr��shutdownr)r!r��tp�resultsrr�r�test_context_threads_1Ws
z"ContextTest.test_context_threads_1N)r2r3r4r#rr/r:r=r@rBrCrMrPrZr[rardrprurvrxrzr�r�rrrrrs:
	

	
5


	
rc@s6eZdZdZdd�dd�Zdd�Zdd�Zd	d
�ZdS)�HashKeyN��error_on_eq_tocCs"|dksJ�||_||_||_dS)N���)rr r�)r!r rr�rrr�__init__ps
zHashKey.__init__cCsd|j�d|j�d�S)Nz
<Key name:z hash:�>)rr r<rrr�__repr__vszHashKey.__repr__cCs|jdur|jjrt�|jSr)�_crasher�
error_on_hash�HashingErrorr r<rrr�__hash__yszHashKey.__hash__cCs�t|t�stS|jdur|jjrt�|jdur&|j|ur&td|�d|����|jdur:|j|ur:td|�d|����|j|j	f|j|j	fkS)Nzcannot compare z to )
�
isinstancer��NotImplementedr��error_on_eq�EqErrorr�rsrr �r!�otherrrr�__eq__s
zHashKey.__eq__)r2r3r4r�r�r�r�r�rrrrr�msr�cs(eZdZ�fdd�Z�fdd�Z�ZS)�KeyStrcs tjdurtjjrt�t���Sr)r�r�r�r��superr�r<��	__class__rrr��s
zKeyStr.__hash__cs"tjdurtjjrt�t��|�Sr)r�r�r�r�r�r�r�r�rrr��sz
KeyStr.__eq__)r2r3r4r�r��
__classcell__rrr�rr��sr�c@s,eZdZddd�dd�Zdd�Zdd�Zd	S)
�HaskKeyCrasherF�r�r�cCs||_||_dSrr�)r!r�r�rrrr��s
zHaskKeyCrasher.__init__cCstjdur	td��|t_dS)Nzcannot nest crashers)r�r�rbr<rrr�	__enter__�s

zHaskKeyCrasher.__enter__cGs
dt_dSr)r�r�)r!�excrrr�__exit__�s
zHaskKeyCrasher.__exit__N)r2r3r4r�r�r�rrrrr��sr�c@r0)r�Nr1rrrrr��r7r�c@r0)r�Nr1rrrrr��r7r�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)Nr{rrr$�b)r�rrr �dict)r!�k1�k2�drrr�test_hashkey_helper_1�s

zHamtTest.test_hashkey_helper_1cCst�}d}dSrr�r!�hrrr�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�rr\r{rI)rrrUr+�assertIsNotrRr>)r!r��h2�h3rrr�test_hamt_basics_2�s*zHamtTest.test_hamt_basics_2cCs4t�}t�}|�d|�}|�d|�}|�||�dS)N�1)r�objectr+rg)r!r��o�h1r�rrr�test_hamt_basics_3�s
zHamtTest.test_hamt_basics_3cCsft�}|�dg�}|�dg�}|�||�|�t|�d�|�t|�d�|�|�d�|�d��dS)N�keyr)rr+r�rrUr>)r!r�r�r�rrr�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)
Nr{rr�cccr$r�ZccrerrrI�)r�rr+rr>rU)	r!r�r�Zk3r�r�r�Zh4Zh5rrr�test_hamt_collision_1�s8


zHamtTest.test_hamt_collision_1cCs�d}d}d}d}d}t|�D�]2}t�}t�}t|�D]�}	t|	�}
|	|sUtdd��#|�t��|�|
|	�Wd�n1sAwYWd�n1sPwY|�|
|	�}|	|s�tdd��$|�t��|�	t|	��Wd�n1s|wYWd�n1s�wY|	||
<|�
t|�t|��|	|s�|�
t|���t|����|�
t|���t|����q|�
t|�|�t|�D]}
|�
|�	t|
�d	�|
�q�t
t|��}t�|�t|�D]�\}}	t|	�}
||�s'tdd��#|�t��
|�|
�Wd�n	1�swYWd�n	1�s"wY||�s_tdd��%|�t��|�t|	��Wd�n	1�sJwYWd�n	1�sZwY|�|
�}|�
|�	|
d	�d	�||
=|�
t|�t|��||d
k�r�|}
|��}||�s�|�
t|���t|����|�
t|���t|����q�|�
t|�d�|�
t|�d�|D]}
|�
|
�	t|
��||
��q�|�
t|�t|
��t|�D]K\}	}
|
�t|
��}
|�
|
�	t|
�d	�d	�|�t|
�d�|�
t|�t|��|	|�s%|�
t|���t|����|�
t|���t|�����q�|�
t|�d�|�
t|�d�|�
t
|���g�qdS)NiXi��arJr�T�r��r�z	not foundrIr)r�rr�r�r�rr�r+r�r>rrUrkrjr��shuffle�	enumerate�deleter~rm�str�poprl)r!ZCOLLECTION_SIZEZTEST_ITERS_EVERYZCRASH_HASH_EVERYZCRASH_EQ_EVERYZ
RUN_XTIMES�_r�r�r�r�Zkeys_to_deleteZiter_iZhmZdmrrr�test_hamt_stresss��������

���
���

�
��zHamtTest.test_hamt_stresscCsvtdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}tdd
|d�}t�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}t|�}	|�|�}|�t|�|	d�|�td��
|�|�Wd�n1sowY|�|�}|�t|�|	d�|�|�}
|�|
|�|�|�}|�t|�|	d�|�|�	|d�d�|�|�	|�d�|�|�	|�d�dS)N�d�A�e�B�f�C�g�D�h�E����Z�Err�r$r�r"r��er�cannot comparerIr�r\)
r�rr+rUr�rrrsrgr>)r!r�r�r�r�r�r�r�r��orig_lenr�rrr�test_hamt_delete_1qs8






	�


zHamtTest.test_hamt_delete_1c
Cs�tdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}tdd
|d�}t�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}t|�}	|�td��
|�|�Wd�n1s`wY|�|�}|�t|�|	�|�|�}|�t|�|	d�|�|�}|�t|�|	d�|�|�}|�t|�|	d�|�|�|�d�|�|�|�d�|�|�}|�|�}|�|�}|�|�}|�t|�d�dS)Nr�r��)r�鉊r�r�r�r�r�r�r�r�r�r$r�r"r�r�r�rrIr�r)	r�rr+rUrrsr�rr>)
r!r�r�r�r�r�r�r�r�r�rrr�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���r�r�r�r�r$r�r"r�r�rrI)r�rr+rUr�rr>�r!r�r�r�r�r�r�r�rrr�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�r�r�r�r�r$r�r"r�r�rrIr��r)r�rr+rUr�rr�rrr�test_hamt_delete_4�s,










zHamtTest.test_hamt_delete_4cCs"t�}g}td�D]}t|t|��}|�|�|�|d|���}q	tdd�}|�|d�}|�t|�d�|�|d�}|�t|�d�|�|�}|�t|�d�|�|d�}|�t|�d�|�|d	�}|�t|�d
�|�|d	�}|�t|�d
�|D]}|�|�}q|�t|�d�dS)N�zval-�Z18Z	collision�rI�r�r)	rr�r�r�r*r+rrUr�)r!r�rmr�r�Zcollision_key16rrr�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�r�r�r�r�r�r�r�r��n�Fr$r�r"r�r�rL�r�rr+rkrrj�	r!r�r�r�r�r�r�r��itrrr�test_hamt_items_1Q�$






&�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�r�r�r�r�r�r�r$r�r"r�r�rLr�r�rrr�test_hamt_items_2fr�zHamtTest.test_hamt_items_2c	Cs�tdd�}tdd�}tdd�}tdd�}tdd�}td	d
�}t�}|�|d�}|�|d�}|�|d
�}|�|d�}|�|d�}|�|d�}|�tt|����||||||h�|�tt|��||||||h�dSr�)r�rr+rrjrm)r!r�r�r�r�r�r�r�rrr�test_hamt_keys_1{s





$$zHamtTest.test_hamt_keys_1cCs2t�}|�t|���d�|�t|���g�dS)Nr)rrrUrkrjr�rrr�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�r�r�r��xr�r$r�r"r�Zd2r�)r�rr+�assertFalse�
assertTruer�)r!r�r�r�r�r�r�r�rrr�test_hamt_eq_1�sF





zHamtTest.test_hamt_eq_1cCs�tdd�}tdd|d�}t�}|�|d�}t�}|�|d�}|�td��||kWd�n1s3wY|�td��
||kWd�dS1sNwYdS)Nr�r�r�r�r$r�)r�rr+rrs)r!r�r�r�r�rrr�test_hamt_eq_2�s

�
"�zHamtTest.test_hamt_eq_2cCs�tdd�}t�}|�dd�}t�|�}g}|�|�|�|�g}|�|�|�|�|�||�}~~~t��t��t��|�|��dS)Nr�r�r)	r�rr+�weakref�refr*�gc�collectrR)r!r�r�rr$r�rrr�test_hamt_gc_1�s 





zHamtTest.test_hamt_gc_1cCsxtdd�}tdd�}t�}|�|d�}|�||�}t�|�}|��}t|�~~t��t��t��|�	|��dS)Nr�r�r�r�r$)
r�rr+rrrk�nextrrrR)r!r�r�r�r�hirrr�test_hamt_gc_2�s


zHamtTest.test_hamt_gc_2c	Cstdd�}tdd�}tdd�}t�}|�|d�}|�||v�|�||v�|�t��!tdd��||vWd�n1s@wYWd�n1sOwY|�t��*tdd��||vWd�n1snwYWd�dSWd�dS1s�wYdS�	Nr�r�r�r�rTr�r�)	r�rr+rr�rr�r�r��r!r�ZAAr�r�rrr�test_hamt_in_1�s(



���
��"�zHamtTest.test_hamt_in_1c	CsPtdd�}tdd�}tdd�}t�}|�|d�}|�||d�|�||d�|�t��||Wd�n1s<wY|�t��!tdd��||Wd�n1s[wYWd�n1sjwY|�t��*tdd��||Wd�n1s�wYWd�dSWd�dS1s�wYdSr)	r�rr+rrrnr�r�r�rrrr�test_hamt_getitem_1s.



�
���
��"�zHamtTest.test_hamt_getitem_1N)r2r3r4r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr
r
rrrrrr��s.	%Y-4$*1/r��__main__)�concurrent.futuresr�rrrr�r�ZunittestrZ	_testcapir�ImportErrorrZTestCaserr�r�r�r��	Exceptionr�r�ZskipIfr�r2�mainrrrr�<module>s>�	V!|�
© 2025 GrazzMean