Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_context.cpython-39.pyc

a

��g�z�@sddlZddlZddlZddlZddlZddlZddlZddlZzddl	m
Z
WneyfdZ
Yn0dd�ZGdd�dej
�ZGdd�d�ZGd	d
�d
e�ZGdd�d�ZGd
d�de�ZGdd�de�Ze�e
dud�Gdd�dej
��Zedk�re��dS)�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/lib/python3.9/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�n1s*0Y|�td��t�d�Wd�n1s`0Yt�d�}|�|jd�|�t��d|_Wd�n1s�0Y|�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�n1s40Y|�td��"Gdd�dtj�}Wd�n1sr0Y|�td��"Gdd�dtj�}Wd�n1s�0YdS)Nznot an acceptable base typec@seZdZdS)z<ContextTest.test_context_subclassing_1.<locals>.MyContextVarN��__name__�
__module__�__qualname__rrrr�MyContextVar?sr4c@seZdZdS)z9ContextTest.test_context_subclassing_1.<locals>.MyContextNr0rrrr�	MyContextDsr5c@seZdZdS)z7ContextTest.test_context_subclassing_1.<locals>.MyTokenNr0rrrr�MyTokenHsr6)rrrrr�Token)r!r4r5r6rrr�test_context_subclassing_1=s00z&ContextTest.test_context_subclassing_1cCs�|�td��t�d�Wd�n1s,0Y|�td��tjddd�Wd�n1sf0Y|�td��tjdd�Wd�n1s�0Ytjfii��dS)Nz
any argumentsr�r$)rrrr�r!rrr�test_context_new_1Ks(,*zContextTest.test_context_new_1cCs�t��}|�td��|dWd�n1s20Y|�td��d|vWd�n1sf0Y|�td��|�d�Wd�n1s�0YdS)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_1cCs@t��}|�td��|��Wd�n1s20YdS)Nzmissing 1 required)rrrrrr=rrr�test_context_run_1bszContextTest.test_context_run_1cCs�t��}dd�}|t�|�fD]�}|�|�|�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>.funcrDrCrBr)rrE�r9)r$rC�)rHrE)rrr�partialrr)r!rr
�fr$rrr�test_context_run_2hs&��
�zContextTest.test_context_run_2cCs�t��}dd�}|�t��|�|�Wd�n1s:0Y|�t��|�|dd�Wd�n1sr0Y|�t��"|j|dddd�Wd�n1s�0YdS)Nc_sdddS)NrrrrFrrrr
�sz,ContextTest.test_context_run_3.<locals>.funcrrGr%r9)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!rOrr�func2�sz-ContextTest.test_context_run_4.<locals>.func2csb����d����d���������d�d�t��}��t|�d���|�d�|S)NrCr)rPr<r+rrrr?�len)Zcur��ctx2rRr!rOrr�func1�s

z-ContextTest.test_context_run_4.<locals>.func1rC)rrrrrr()r!�ctx1rVZreturned_ctxrrTr�test_context_run_4�s

zContextTest.test_context_run_4csht��}t�d����fdd�}��t��|�|�Wd�n1sJ0Y����d��dS)NrOcs&����d����d�dddS)NrCrr)rPr<r+rrQrrr
�s
z,ContextTest.test_context_run_5.<locals>.func)rrrrrLrrPr<rMrrQr�test_context_run_5�s
(zContextTest.test_context_run_5cs4t���tjddd�����fdd�}��|�dS)Nr$rr&csP�����d����������d������d�������d�dS)Nr�*)rr<rPr+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�n1s,0YdS)Nzis already entered)r�RuntimeErrorrr�rr\r!rrr\�sz+ContextTest.test_context_run_7.<locals>.funrr:rrar�test_context_run_7�szContextTest.test_context_run_7cCs�t�d�}|�t��|��Wd�n1s20Y|�|�d��|�d�}|�|��d�|�|�d�d�|�|j	|j
�|�|j	tjj
�|�|j|�|�d�}|�|��d�|�|�d�d�|�|j	d�|�
|�|�|��d�|�|�d�d�|�d�|�td��|�
|�Wd�n1�sF0Y|�|��d�t��}|�||�|�
|�|�td��|�
|�Wd�n1�s�0Y|�|�d��|�||�|�||d�|�|�|d�d�|�t|�d�|�t|���|dfg�|�t|���dg�|�t|���|g�|�t|�|g�t��}|�||�|�t��||Wd�n1�s�0Y|�|�|d�d�|�t|�d�|�t|�g�dS)	Nr"rZrCZspam2zhas already been used�aarr)rrr�LookupErrorr<rPr+r�assertIs�	old_value�MISSINGr7rOr-rr`r?r(rS�list�items�values�keysr,�KeyError)r!r"�t0r.rWrUrrr�test_context_getset_1�sT
&



*
*(z!ContextTest.test_context_getset_1cCsXt�d�}t�d�}|�d�}|�td��|�|�Wd�n1sJ0YdS)N�v1�v2rZzby a different)rrr+r�
ValueErrorr-)r!rorp�t1rrr�test_context_getset_2s



z!ContextTest.test_context_getset_2cs4tjddd��t������fdd�}��|�dS)Nr"rZr&cs
�����d���t����Wd�n1s80Y������������d�d��������t����g���d�}��t�����g�����d���	|���t����g���t����Wd�n1s�0YdS)NrZrCr)
rr<rrlrPr,rhrkr+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�n1sP0YdS)Nr"rZr&rzdifferent Context)rrrrr+rrqr-)r!r"r�tokrrr�test_context_getset_4's
z!ContextTest.test_context_getset_4csHtjddd����g���fdd�}t���|������g�dS)Nr"rZr&cs.��g�����d������dg�dS)NrZ)r+r<r*rr�r"r!rrr\6s
z.ContextTest.test_context_getset_5.<locals>.fun)rrr+r?rrr<r^rrwr�test_context_getset_51s

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


z1ContextTest.test_context_copy_1.<locals>.ctx1_funcs.�����d���d������d�dS)Nryr{)rr<r+rrwrrr~Ps
z1ContextTest.test_context_copy_1.<locals>.ctx2_funr])r!rrr}r�test_context_copy_1>s
zContextTest.test_context_copy_1csjt�d����fdd�}tjjdd�}z t|�|td���}W|��n
|��0��	|ttd���dS)N�cvarcsFtd�D]8}��||�t�t�dd�������||�q|S)Nryg����MbP?g�������?)�ranger+�time�sleep�random�uniformrr<)�num�i�r�r!rr�sub[s
z/ContextTest.test_context_threads_1.<locals>.subry)�max_workers)
rr�
concurrent�futures�ThreadPoolExecutorrh�mapr��shutdownr)r!r��tp�resultsrr�r�test_context_threads_1Ws
z"ContextTest.test_context_threads_1N)r1r2r3r#rr/r8r;r>r@rArKrNrXrYr_rbrnrsrtrvrxr�r�rrrrrs8
	


	
5


	
rc@s6eZdZdZdd�dd�Zdd�Zdd�Zd	d
�ZdS)�HashKeyN��error_on_eq_tocCs"|dksJ�||_||_||_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$|jjr$t�|jdurL|j|urLtd|�d|����|jdurt|j|urttd|�d|����|j|j	f|j|j	fkS)Nzcannot compare z to )
�
isinstancer��NotImplementedr��error_on_eq�EqErrorr�rqrr �r!�otherrrr�__eq__s
zHashKey.__eq__)r1r2r3r�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��szKeyStr.__hash__cs"tjdurtjjrt�t��|�Sr)r�r�r�r�r�r�r�r�rrr��sz
KeyStr.__eq__)r1r2r3r�r��
__classcell__rrr�rr��sr�c@s,eZdZddd�dd�Zdd�Zdd�Zd	S)
�HaskKeyCrasherF�r�r�cCs||_||_dSrr�)r!r�r�rrrr��szHaskKeyCrasher.__init__cCstjdurtd��|t_dS)Nzcannot nest crashers)r�r�r`r:rrr�	__enter__�s
zHaskKeyCrasher.__enter__cGs
dt_dSr)r�r�)r!�excrrr�__exit__�szHaskKeyCrasher.__exit__N)r1r2r3r�r�r�rrrrr��sr�c@seZdZdS)r�Nr0rrrrr��sr�c@seZdZdS)r�Nr0rrrrr��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-d.�Zd/S)0�HamtTestcCsntdd�}tdd�}|�||�|�t|�t|��t�}d||<d||<|�||d�|�||d�dS)Nryrrr$�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�rrZryrG)rrrSr+�assertIsNotrPr<)r!r��h2�h3rrr�test_hamt_basics_2�s*zHamtTest.test_hamt_basics_2cCs4t�}t�}|�d|�}|�d|�}|�||�dS)N�1)r�objectr+re)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�rrSr<)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)
Nryrr�cccr$r�ZccrcrrrG�)r�rr+rr<rS)	r!r�r�Zk3r�r�r�Zh4Zh5rrr�test_hamt_collision_1�s8


zHamtTest.test_hamt_collision_1cCsjtdd�}tdd�}tdd�}t�}|�|d�}|�|d�}|�|d�}|�dd�|��D�hd��dS)	Nl�C�Dr�EcSsh|]
}|j�qSr)r)�.0�krrr�	<setcomp>9�z1HamtTest.test_hamt_collision_3.<locals>.<setcomp>>r�r�r�)r�rr+rrk)r!r�r�r�r�rrr�test_hamt_collision_3s


zHamtTest.test_hamt_collision_3cCs�d}d}d}d}d}t|�D�]p}t�}t�}t|�D�]J}	t|	�}
|	|s�tdd��F|�t��|�|
|	�Wd�n1s�0YWd�n1s�0Y|�|
|	�}|	|�s&tdd��H|�t��|�	t|	��Wd�n1s�0YWd�n1�s0Y|	||
<|�
t|�t|��|	|s6|�
t|���t|����|�
t|���t|����q6|�
t|�|�t|�D]}
|�
|�	t|
�d	�|
��q�t
t|��}t�|�t|�D�]�\}}	t|	�}
||�sXtdd��F|�t��|�|
�Wd�n1�s.0YWd�n1�sN0Y||�s�tdd��J|�t��|�t|	��Wd�n1�s�0YWd�n1�s�0Y|�|
�}|�
|�	|
d	�d	�||
=|�
t|�t|��||d
k�r|}
|��}||�s�|�
t|���t|����|�
t|���t|�����q�|�
t|�d�|�
t|�d�|D] }
|�
|
�	t|
��||
��q�|�
t|�t|
��t|�D]�\}	}
|
�t|
��}
|�
|
�	t|
�d	�d	�|�t|
�d�|�
t|�t|��|	|�s�|�
t|���t|����|�
t|���t|�����q�|�
t|�d�|�
t|�d�|�
t
|���g�qdS)NiXi��arHr�T�r��r�z	not foundrGr)r�rr�r�r�rr�r+r�r<rrSrirhr��shuffle�	enumerate�deleter|rk�str�poprj)r!ZCOLLECTION_SIZEZTEST_ITERS_EVERYZCRASH_HASH_EVERYZCRASH_EQ_EVERYZ
RUN_XTIMES�_r�r�r�r�Zkeys_to_deleteZiter_iZhmZdmrrr�test_hamt_stress;s�H
L

J
N

 
 zHamtTest.test_hamt_stresscCsvtdd�}tdd�}tdd�}tdd�}td	d
�}tdd�}tdd
|d�}t�}|�|d�}|�|d�}|�|d�}|�|d�}|�|d�}t|�}	|�|�}|�t|�|	d�|�td��|�|�Wd�n1s�0Y|�|�}|�t|�|	d�|�|�}
|�|
|�|�|�}|�t|�|	d�|�|�	|d�d�|�|�	|�d�|�|�	|�d�dS)N�d�A�e�B�fr��gr��hr�����Z�Err�r$r�r"r��er�cannot comparerGr�rZ)
r�rr+rSr�rrrqrer<)r!r�r�r�r�r�r�r�r��orig_lenr�rrr�test_hamt_delete_1�s6





	
(


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�0Y|�|�}|�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�rrGr�r)	r�rr+rSrrqr�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�rrG)r�rr+rSr�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�rrGr��r)r�rr+rSr�rr�rrr�test_hamt_delete_4s,









zHamtTest.test_hamt_delete_4cCs"t�}g}td�D].}t|t|��}|�|�|�|d|���}qtdd�}|�|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�rG�r�r)	rr�r�r�r*r+rrSr�)r!r�rkr�r�Zcollision_key16rrr�test_hamt_delete_5Cs,


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�rJ�r�rr+rirrh�	r!r�r�r�r�r�r�r��itrrr�test_hamt_items_1ts$






&�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�rJr�r�rrr�test_hamt_items_2�s$






&�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+rrhrk)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)rrrSrirhr�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�n1sf0Y|�td��||kWd�n1s�0YdS)Nr�r�r�r�r$r�)r�rr+rrq)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�collectrP)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+rrri�nextrrrP)r!r�r�r�r�hirrr�test_hamt_gc_2s


zHamtTest.test_hamt_gc_2c	Cstdd�}tdd�}tdd�}t�}|�|d�}|�||v�|�||v�|�t��Btdd��||vWd�n1s�0YWd�n1s�0Y|�t��Btdd��||vWd�n1s�0YWd�n1s�0YdS�	Nr�r�r�r�rTr�r�)	r�rr+rrrr�r�r��r!r�ZAAr�r�rrr�test_hamt_in_1 s


DzHamtTest.test_hamt_in_1c	CsBtdd�}tdd�}tdd�}t�}|�|d�}|�||d�|�||d�|�t��||Wd�n1sx0Y|�t��Btdd��||Wd�n1s�0YWd�n1s�0Y|�t��Dtdd��||Wd�n1�s0YWd�n1�s40YdSr
)	r�rr+rrrlr�r�r�rrrr�test_hamt_getitem_14s


&DzHamtTest.test_hamt_getitem_1N)r1r2r3r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr	rrrrrrrr��s.	%#Y-4$*1/r��__main__)�concurrent.futuresr�rrrr�r�ZunittestrZ	_testcapir�ImportErrorrZTestCaserr�r�r�r��	Exceptionr�r�ZskipIfr�r1�mainrrrr�<module>s:
	V! 


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists