
    ;ez                        d dl Zd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	m
Z
 	 d dlmZ n# e$ r dZY nw xY wd Z G d dej                  Z G d d          Z G d	 d
e          Z G d d          Z G d de          Z G d de          Z ej        edu d           G d dej                              Zedk    r ej                     dS dS )    N)threading_helperhamtc                 F     t          j                    fd            }|S )z*Needed to make reftracking test mode work.c                  L    t          j                    } |j        g| R i |S NcontextvarsContextrun)argskwargsctxfuncs      (/usr/lib/python3.11/test/test_context.pywrapperz!isolated_context.<locals>.wrapper   s3    !##swt-d---f---    )	functoolswraps)r   r   s   ` r   isolated_contextr      s8    _T. . . . . Nr   c                   0   e Zd Zd Zed             Zd Zd Zd Zd Z	d Z
d Zd	 Zed
             Zd Zd Zd Zed             Zed             Zed             Zed             Zed             Zd Ze ej                    d                         ZdS )ContextTestc                 P   |                      t          d          5  t          j                     d d d            n# 1 swxY w Y   |                      t          d          5  t          j        d           d d d            n# 1 swxY w Y   t          j        d          }|                     |j        d           |                     t                    5  d|_        d d d            n# 1 swxY w Y   |                     t          |          t          d                     d S )Nztakes exactly 1zmust be a str   aaabbb)
assertRaisesRegex	TypeErrorr
   
ContextVarassertEqualnameassertRaisesAttributeErrorassertNotEqualhash)selfcs     r   test_context_var_new_1z"ContextTest.test_context_var_new_1   s   ##I/@AA 	% 	%"$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ##I?? 	& 	&"1%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& "5))'''~.. 	 	AF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	DGGT%[[11111s3   <A A "BB
BC++C/2C/c                    t          j        d          }|                     dt          |                     t          j        dd          }|                     dt          |                     g }t          j        d|          }|                    |           |                     dt          |                     |                     dt          |                     |                    d          }|                     t          |          t          |                     |                     dt          |                     |                    |           |                     dt          |                     d S )Na{   default123z...r   z used )r
   r   assertInreprappendsetassertNotInreset)r&   r'   lstts       r   test_context_var_repr_1z#ContextTest.test_context_var_repr_1*   s2   "3''c477###"3444eT!WW%%%"3444

1eT!WW%%%eT#YY'''EE!HHd1ggtAww'''477+++	


hQ(((((r   c                    |                      t          d          5   G d dt          j                  }d d d            n# 1 swxY w Y   |                      t          d          5   G d dt          j                  }d d d            n# 1 swxY w Y   |                      t          d          5   G d dt          j                  }d d d            d S # 1 swxY w Y   d S )Nznot an acceptable base typec                       e Zd ZdS )<ContextTest.test_context_subclassing_1.<locals>.MyContextVarN__name__
__module____qualname__ r   r   MyContextVarr:   @   s        r   r@   c                       e Zd ZdS )9ContextTest.test_context_subclassing_1.<locals>.MyContextNr;   r?   r   r   	MyContextrB   E           r   rC   c                       e Zd ZdS )7ContextTest.test_context_subclassing_1.<locals>.MyTokenNr;   r?   r   r   MyTokenrF   I   rD   r   rG   )r   r   r
   r   r   Token)r&   r@   rC   rG   s       r   test_context_subclassing_1z&ContextTest.test_context_subclassing_1>   s   ##I/LMM 	 	    {5   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	
 ##I/LMM 	 	    K/   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ##I/LMM 	 	    ++   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s5   AAA'BBB2CCCc                    |                      t          d          5  t          j        d           d d d            n# 1 swxY w Y   |                      t          d          5  t          j        dd           d d d            n# 1 swxY w Y   |                      t          d          5  t          j        d           d d d            n# 1 swxY w Y   t          j        di i  d S )Nzany argumentsr   r*   r?   )r   r   r
   r   r&   s    r   test_context_new_1zContextTest.test_context_new_1L   s   ##I?? 	# 	#"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	###I?? 	( 	(Q''''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(##I?? 	% 	%!$$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%!!b!!!!!s3   =AA#BB
B
,CCCc                    t          j                    }|                     t          d          5  |d          d d d            n# 1 swxY w Y   |                     t          d          5  d|v  d d d            n# 1 swxY w Y   |                     t          d          5  |                    d           d d d            d S # 1 swxY w Y   d S )NzContextVar key was expectedr   )r
   r   r   r   getr&   r   s     r   test_context_typerrors_1z$ContextTest.test_context_typerrors_1U   s   !####I/LMM 	 	FF	 	 	 	 	 	 	 	 	 	 	 	 	 	 	##I/LMM 	 	HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	##I/LMM 	 	GGAJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s5   	AAA*A;;A?A?!CCCc                 l    t          j                    }|                     |t           j                   d S r   )r
   copy_contextassertIsInstancer   rP   s     r   test_context_get_context_1z&ContextTest.test_context_get_context_1_   s/    &((c;#677777r   c                     t          j                    }|                     t          d          5  |                                 d d d            d S # 1 swxY w Y   d S )Nzmissing 1 required)r
   r   r   r   r   rP   s     r   test_context_run_1zContextTest.test_context_run_1c   s    !####I/CDD 	 	GGIII	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc                 Z   t          j                    }d }|t          j        |          fD ]}|                     |                    |          dddif           |                     |                    |d          dddif           |                     |                    |d          dddd	f           |                     |                    |d
d          dddd	f           i }|                      |j        |d
fi |dddif           |                     |i            d S )Nc                      d|d<   | dz  } | |fS )Nfoospambarr?   r   r   s     r   r   z,ContextTest.test_context_run_2.<locals>.funcl   s    "F6NHD<r   r\   r[   rZ   r   )r   r]      rK   )r*   r[      )r`   r]   )r
   r   r   partialr    r   )r&   r   r   fr*   s        r   test_context_run_2zContextTest.test_context_run_2i   sw   !##	  	  	 
 	)$//0 	$ 	$A SWWQZZ(VUO)DEEESWWQ]]Z&%,IJJJQE2235 5 5 2##Au5568 8 8 A2####vuo.0 0 0 Q####%	$ 	$r   c                    t          j                    }d }|                     t                    5  |                    |           d d d            n# 1 swxY w Y   |                     t                    5  |                    |dd           d d d            n# 1 swxY w Y   |                     t                    5  |                    |ddd           d d d            d S # 1 swxY w Y   d S )Nc                      ddz   d S )Nr   r   r?   r^   s     r   r   z,ContextTest.test_context_run_3.<locals>.func   s    EEEEr   r   r_   r+   rK   )r
   r   r"   ZeroDivisionErrorr   )r&   r   r   s      r   test_context_run_3zContextTest.test_context_run_3   s   !##	 	 	 011 	 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	011 	  	 GGD!Q	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 011 	' 	'GGD!Q#G&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	's5   AAA8BB #B C((C,/C,c                 X    t          j                    }t          j                    t          j        d           fd fd}|                    |          }                     ||                                |         d                                |           d S )Nvarc                  X                                              d                      d S r   )assertIsNonerO   r&   ri   s   r   func2z-ContextTest.test_context_run_4.<locals>.func2   s'    cggdmm,,,,,r   c                                                              d                                          d                                                                                  d           d           t          j                    }                     t          |           d                               |          d           | S )Nr[   r   )rk   rO   r2   r   r    r
   rS   len)curctx2rm   r&   ri   s    r   func1z-ContextTest.test_context_run_4.<locals>.func1   s    cggdmm,,,GGFOOOHHUOOOSWWT]]F333*,,CSXXq)))SXv...Jr   r[   )r
   r   r   r   r    r/   )r&   ctx1rr   returned_ctxrq   rm   ri   s   `   @@@r   test_context_run_4zContextTest.test_context_run_4   s    "$$"$$$U++	- 	- 	- 	- 	- 	-		 		 		 		 		 		 		 		 xx|,,,c*F333c<(((((r   c                 B    t          j                    }t          j        d           fd}                     t                    5  |                    |           d d d            n# 1 swxY w Y                                            d                      d S )Nri   c                                                                d                                          d           ddz   d S )Nr[   r   r   )rk   rO   r2   rl   s   r   r   z,ContextTest.test_context_run_5.<locals>.func   s=    cggdmm,,,GGFOOOEEEEr   )r
   r   r   r"   rf   r   rk   rO   )r&   r   r   ri   s   `  @r   test_context_run_5zContextTest.test_context_run_5   s    !##$U++	 	 	 	 	 	
 011 	 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	#''$--(((((s   
A,,A03A0c                      t          j                    t          j        dd           fd}                    |           d S )Nr*   r   r,   c                  t                                                         d                                                                                              d                                                                 d                                                               d           d S )Nr   *   )r    rO   rk   r2   )r'   r   r&   s   r   funz+ContextTest.test_context_run_6.<locals>.fun   s    QUUWWa(((cggajj)))EE"IIIQUUWWb)))SWWQZZ,,,,,r   r
   r   r   r   r&   r|   r'   r   s   ` @@r   test_context_run_6zContextTest.test_context_run_6   s`    !##"3222	- 	- 	- 	- 	- 	- 	- 	r   c                 j     t          j                     fd                               d S )Nc                                           t          d          5                                  d d d            d S # 1 swxY w Y   d S )Nzis already entered)r   RuntimeErrorr   )r   r|   r&   s   r   r|   z+ContextTest.test_context_run_7.<locals>.fun   s    ''6JKK                   s   A  AAr	   )r&   r   r|   s   `@@r   test_context_run_7zContextTest.test_context_run_7   sK    !##	 	 	 	 	 	 	 	r   c                    t          j        d          }|                     t                    5  |                                 d d d            n# 1 swxY w Y   |                     |                    d                      |                    d          }|                     |                                d           |                     |                    d           d           |                     |j	        |j
                   |                     |j	        t           j        j
                   |                     |j        |           |                    d          }|                     |                                d           |                     |                    d           d           |                     |j	        d           |                    |           |                     |                                d           |                     |                    d           d           |                    d           |                     t          d          5  |                    |           d d d            n# 1 swxY w Y   |                     |                                d           t          j                    }|                     ||           |                    |           |                     t          d          5  |                    |           d d d            n# 1 swxY w Y   |                     |                    d                      |                     ||           |                     ||         d           |                     |                    |d          d           |                     t%          |          d           |                     t'          |                                          |dfg           |                     t'          |                                          dg           |                     t'          |                                          |g           |                     t'          |          |g           t          j                    }|                     ||           |                     t0                    5  ||          d d d            n# 1 swxY w Y   |                     |                    |d          d           |                     t%          |          d           |                     t'          |          g            d S )	Nr'   r{   r[   spam2zhas already been usedaar   r   )r
   r   r"   LookupErrorrO   rk   r2   r    assertIs	old_valueMISSINGrH   ri   r4   r   r   rS   r/   ro   listitemsvalueskeysr3   KeyError)r&   r'   t0r6   rs   rq   s         r   test_context_getset_1z!ContextTest.test_context_getset_1   sc   "3''{++ 	 	EEGGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!%%++&&&UU2YY"%%%tb)))blBJ///blK$5$=>>>bfa   EE&MM&)))tf---b)))	


"%%%tb)))	g##L2IJJ 	 	GGAJJJ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	'***'))a	##L2IJJ 	 	GGBKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!%%++&&&aa'***!T**G444TA&&&djjll++q'l^<<<dkkmm,,wi888diikk**QC000daS)))'))D!!!x(( 	 	GG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	!T**D111TA&&&dR(((((sG   AAA%JJJL55L9<L92	TTTc                    t          j        d          }t          j        d          }|                    d          }|                     t          d          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nv1v2r{   zby a different)r
   r   r2   r   
ValueErrorr4   )r&   r   r   t1s       r   test_context_getset_2z!ContextTest.test_context_getset_2  s    #D))#D))VVBZZ##J0@AA 	 	HHRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A<<B B c                      t          j        dd          t          j                     fd}                    |           d S )Nr'   r{   r,   c                                                                          d                               t                    5            d d d            n# 1 swxY w Y                                                                                                         d          d                                                               t                                                    g                                d          }                      t                                                    g                                         d           	                    |                                 t                                                    g                                t                    5            d d d            d S # 1 swxY w Y   d S )Nr{   r[   r   )
r    rO   r"   r   rk   r3   r   r   r2   r4   )r6   r'   r   r&   s    r   r|   z.ContextTest.test_context_getset_3.<locals>.fun  s   QUUWWb)))""8,,  A              cggajj)))SWWQ//888Q$$$T#((**--r222aAT#((**--s333SVQ'''GGAJJJT#((**--r222""8,,  A                 s$   	AA A	G""G&)G&)r
   r   r   r   r~   s   ` @@r   test_context_getset_3z!ContextTest.test_context_getset_3  s`    "3333!##	 	 	 	 	 	 	$ 	r   c                     t          j        dd          }t          j                    }|                    |j        d          }|                     t          d          5  |                    |           d d d            d S # 1 swxY w Y   d S )Nr'   r{   r,   r   zdifferent Context)r
   r   r   r   r2   r   r   r4   )r&   r'   r   toks       r   test_context_getset_4z!ContextTest.test_context_getset_4(  s    "3333!##ggaeQ##J0CDD 	 	GGCLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    BB
Bc                     t          j        dd                              g             fd}t          j                                        |                                                                g            d S )Nr'   r{   r,   c                                            g                                                                 d                                                                dg           d S )Nr{   )r2   rO   r1   r    r'   r&   s   r   r|   z.ContextTest.test_context_getset_5.<locals>.fun7  sR    EE"IIIEEGGNN2QUUWWrd+++++r   )r
   r   r2   rS   r   r    rO   )r&   r|   r'   s   ` @r   test_context_getset_5z!ContextTest.test_context_getset_52  s    "3333	b				, 	, 	, 	, 	, 	,
 	 ""&&s+++"%%%%%r   c                      t          j                    t          j        dd           fd} fd                    |           d S )Nr'   r{   r,   c                                          d                                           }                     |          d                                d                                        d                               |          d           |                                                             d                               |          d           d S )N
         )r2   copyr    r   )rq   r'   rs   ctx2_funr&   s    r   ctx1_funz1ContextTest.test_context_copy_1.<locals>.ctx1_funC  s    EE"III99;;DT!Wb)))EE"IIIT!Wb)))T!Wb)))HHXT!Wb)))T!Wb)))))r   c                                                                            d                                d                                                                 d           d S )Nr   r   )r    rO   r2   r   s   r   r   z1ContextTest.test_context_copy_1.<locals>.ctx2_funQ  sT    QUUWWb)))EE"IIIQUUWWb)))))r   r}   )r&   r   r'   rs   r   s   ` @@@r   test_context_copy_1zContextTest.test_context_copy_1?  s    "$$"3333	* 	* 	* 	* 	* 	* 	* 	*	* 	* 	* 	* 	* 	*
 	r   c                     t          j        d           fd}t          j                            d          }	 t          |                    |t          d                              }|                                 n# |                                 w xY w 	                    |t          t          d                               d S )Ncvarc                     t          d          D ]l}                    | |z              t          j        t	          j        dd                                                                         | |z              m| S )Nr   gMbP?g?)ranger2   timesleeprandomuniformr    rO   )numir   r&   s     r   subz/ContextTest.test_context_threads_1.<locals>.sub]  st    2YY 6 6q!!!
6>%66777  S1W5555Jr   r   )max_workers)
r
   r   
concurrentfuturesThreadPoolExecutorr   mapr   shutdownr    )r&   r   tpresultsr   s   `   @r   test_context_threads_1z"ContextTest.test_context_threads_1X  s     %f--	 	 	 	 	 	 22r2BB	266#uRyy1122GKKMMMMBKKMMMM$uRyy//22222s   0B BN)r<   r=   r>   r(   r   r7   rI   rM   rQ   rU   rW   rc   rg   ru   rx   r   r   r   r   r   r   r   r   r   requires_working_threadingr   r?   r   r   r   r      s       2 2 2 ) ) )&  " " "  8 8 8  $ $ $8' ' ' ) ) )0) ) )     3) 3) 3)j      0    
& 
& 
&  2 00223 3 32 3 3 3r   r   c                   0    e Zd ZdZdddZd Zd Zd ZdS )HashKeyNerror_on_eq_toc                @    |dk    sJ || _         || _        || _        d S )N)r!   r%   r   )r&   r%   r!   r   s       r   __init__zHashKey.__init__r  s+    rzzzz		,r   c                 (    d| j          d| j         dS )Nz
<Key name:z hash:>)r!   r%   rL   s    r   __repr__zHashKey.__repr__x  s    9DI99TY9999r   c                 D    | j         | j         j        rt          | j        S r   )_crashererror_on_hashHashingErrorr%   rL   s    r   __hash__zHashKey.__hash__{  s"    =$)D$yr   c                 >   t          |t                    st          S | j        | j        j        rt
          | j        | j        |u rt          d| d|          |j        |j        | u rt          d|d|           | j        | j	        f|j        |j	        fk    S )Nzcannot compare z to )

isinstancer   NotImplementedr   error_on_eqEqErrorr   r   r!   r%   )r&   others     r   __eq__zHashKey.__eq__  s    %)) 	"!!=$)B$M*t/Be/K/KDtDD5DDEEE+0D0L0LDuDDDDDEEE	49%%*ej)AAAr   )r<   r=   r>   r   r   r   r   r   r?   r   r   r   r   o  sg        H59 - - - - -: : :  B B B B Br   r   c                   (     e Zd Z fdZ fdZ xZS )KeyStrc                     t           j        t           j        j        rt          t	                                                      S r   )r   r   r   r   superr   )r&   	__class__s    r   r   zKeyStr.__hash__  s3    'G,<,J'ww!!!r   c                     t           j        t           j        j        rt          t	                                          |          S r   )r   r   r   r   r   r   )r&   r   r   s     r   r   zKeyStr.__eq__  s2    'G,<,H'Mww~~e$$$r   )r<   r=   r>   r   r   __classcell__)r   s   @r   r   r     sQ        " " " " "
% % % % % % % % %r   r   c                   (    e Zd ZddddZd Zd ZdS )HaskKeyCrasherFr   r   c                "    || _         || _        d S r   r   )r&   r   r   s      r   r   zHaskKeyCrasher.__init__  s    *&r   c                 T    t           j        t          d          | t           _        d S )Nzcannot nest crashers)r   r   r   rL   s    r   	__enter__zHaskKeyCrasher.__enter__  s(    '5666r   c                     d t           _        d S r   )r   r   )r&   excs     r   __exit__zHaskKeyCrasher.__exit__  s    r   N)r<   r=   r>   r   r   r   r?   r   r   r   r     sP        (-5 ' ' ' ' '     
         r   r   c                       e Zd ZdS )r   Nr;   r?   r   r   r   r             Dr   r   c                       e Zd ZdS )r   Nr;   r?   r   r   r   r     r   r   r   z!_testcapi lacks "hamt()" functionc                       e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )HamtTestc                 r   t          dd          }t          dd          }|                     ||           |                     t          |          t          |                     t	                      }d||<   d||<   |                     ||         d           |                     ||         d           d S )Nr   r   r   r*   b)r   r$   r    r%   dict)r&   k1k2ds       r   test_hashkey_helper_1zHamtTest.test_hashkey_helper_1  s    RRB###b488,,,FF""2$$$2$$$$$r   c                 &    t                      }d }d S r   r   r&   hs     r   test_hamt_basics_1zHamtTest.test_hamt_basics_1  s    FFr   c                 ^   t                      }|                     t          |          d           |                    dd          }|                     ||           |                     t          |          d           |                     t          |          d           |                     |                    d                     |                     |                    dd          d           |                     |                    d          d           |                    dd          }|                     ||           |                     t          |          d           |                     t          |          d           |                     t          |          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d                     |                     |                    d                     |                     |                    d                     |                     |                    d          d           d x}x}}d S )Nr   r*   r   r   r{   r   r_   )r   r    ro   r2   assertIsNotrk   rO   )r&   r   h2h3s       r   test_hamt_basics_2zHamtTest.test_hamt_basics_2  s.   FFQ###UU3__BQ###R!$$$!%%**%%%sB,,,c***VVC__R   Q###R!$$$R!$$$c***b)))!%%**%%%"&&++&&&!%%**%%%c***Br   c                     t                      }t                      }|                    d|          }|                    d|          }|                     ||           d S )N1)r   objectr2   r   )r&   r   oh1r   s        r   test_hamt_basics_3zHamtTest.test_hamt_basics_3  sP    FFHHUU3]]VVC^^b"r   c                    t                      }|                    dg           }|                    dg           }|                     ||           |                     t	          |          d           |                     t	          |          d           |                     |                    d          |                    d                     d S )Nkeyr   )r   r2   r   r    ro   rO   )r&   r   r   r   s       r   test_hamt_basics_4zHamtTest.test_hamt_basics_4  s    FFUU5"VVE2R   R!$$$R!$$$u66666r   c                 ^   t          dd          }t          dd          }t          dd          }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           d S )Nr   r   r   cccr*   r   ccr   r   r   r_      )r   r   r2   r    rO   ro   )	r&   r   r   k3r   r   r   h4h5s	            r   test_hamt_collision_1zHamtTest.test_hamt_collision_1  s   RRRFFUU2s^^VVB__rD)))rD)))S)))T***S)))S)))VVBVVBS)))S)))S)))T***T***S)))T***T***T***Q###R!$$$R!$$$R!$$$R!$$$$$r   c                 n   t          dd          }t          dd          }t          dd          }t                      }|                    |d          }|                    |d          }|                    |d          }|                     d |                                D             h d           d S )Nl        CDr   Ec                     h | ]	}|j         
S r?   )r!   ).0ks     r   	<setcomp>z1HamtTest.test_hamt_collision_3.<locals>.<setcomp>;  s    333Q!&333r   >   r  r  r  )r   r   r2   r    r   )r&   r  r  r  r   s        r   test_hamt_collision_3zHamtTest.test_hamt_collision_3  s     93??93??93??FFEE!SMMEE!SMMEE!SMM* 	33!&&((333___EEEEEr   c           	         d}d}d}d}d}t          |          D ]}t                      }t                      }t          |          D ] }	t          |	          }
|	|z  spt	          d          5  |                     t                    5  |                    |
|	           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                    |
|	          }|	|z  s|t	          d          5  |                     t                    5  |	                    t          |	                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |	||
<   | 
                    t          |          t          |                     |	|z  s| 
                    t          |                                          t          |                                                     | 
                    t          |                                          t          |                                                     | 
                    t          |          |           t          |          D ]9}
| 
                    |	                    t          |
          d	          |
           :t          t          |                    }t          j        |           t!          |          D ]H\  }}	t          |	          }
||z  sot	          d          5  |                     t                    5  |                    |
           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   ||z  s|t	          d          5  |                     t                    5  |                    t          |	                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                    |
          }| 
                    |	                    |
d	          d	           ||
= | 
                    t          |          t          |                     ||d
z  k    r|}|                                }||z  s| 
                    t          |                                          t          |                                                     | 
                    t          |                                          t          |                                                     J| 
                    t          |          d           | 
                    t          |          d           |D ]>}
| 
                    |	                    t)          |
                    ||
                    ?| 
                    t          |          t          |                     t!          |          D ]_\  }	}
|                    t)          |
                    }| 
                    |	                    t)          |
          d	          d	           |                    t)          |
          d            | 
                    t          |          t          |                     |	|z  s| 
                    t          |                                          t          |                                                     | 
                    t          |                                          t          |                                                     a| 
                    t          |          d           | 
                    t          |          d           | 
                    t          |                                          g            d S )NiX  i  a   r`   r  Tr   r   z	not foundr_   r   )r   r   r   r   r   r"   r   r2   r   rO   r    ro   r   r   r   shuffle	enumeratedeleter   r   strpopr   )r&   COLLECTION_SIZETEST_ITERS_EVERYCRASH_HASH_EVERYCRASH_EQ_EVERY
RUN_XTIMES_r   r   r   r  keys_to_deleteiter_ihmdms                  r   test_hamt_stresszHamtTest.test_hamt_stress=  s   
z"" P	2 P	2AAA?++ E EQii,, *'d;;; * *!..|<< * *EE#qMMM* * * * * * * * * * * * * * ** * * * * * * * * * * * * * * EE#qMMN* -'D999 - -!..w77 - -EE&)),,,- - - - - - - - - - - - - - -- - - - - - - - - - - - - - - #  QQ000,, E$$S^^S^^DDD$$S^^S^^DDDSVV_555_-- G G  vc{{K!@!@#FFFF!%"8"899NN>***&~66 C C	Qii!11 *'d;;; * *!..|<< * *HHSMMM* * * * * * * * * * * * * * ** * * * * * * * * * * * * * * / 0'D999 0 0!..w77 0 0HHVAYY///0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0 0 0 0 0 0 HHSMM  sK!8!8+FFFcF  QQ000_111BB!11 C$$S]]CMMBBB$$S]]CMMBBBSVVQ'''SVVQ'''  < <  C!1!12c7;;;;SWWc"gg...#N33 G G3YYs3xx((  C+!>!>LLLs3xx&&&  QQ000,, G$$S__c!((**ooFFF$$S__c!((**ooFFFSVVQ'''SVVQ'''T!''))__b1111aP	2 P	2s   /C
B-	!C-B11C4B15CCC:E#E	8EEEEEE"EM3:M	M3M  M3#M $M33M7:M7O4.#O	O4O!!O4$O!%O44O8;O8c                 @   t          dd          }t          dd          }t          dd          }t          dd          }t          d	d
          }t          dd          }t          dd|          }t                      }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }t          |          }	|                    |          }|                     t          |          |	dz
             |                     t          d          5  |                    |           d d d            n# 1 swxY w Y   |                    |          }|                     t          |          |	dz
             |                    |          }
|                     |
|           |                    |          }|                     t          |          |	dz
             |                     |	                    |d          d           |                     |	                    |          d           |                     |	                    |          d           d S )Nd   Ae   Bf   r  g   r  h   r  ZErr   r*   r   r'   r   er   cannot comparer_   r  r{   )
r   r   r2   ro   r  r    r   r   r   rO   )r&   r,  r.  r  r  r  r3  r4  r   orig_lenr   s              r   test_hamt_delete_1zHamtTest.test_hamt_delete_1  sp   CCCCCD#S$q111FFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMq66 HHQKKQA...##J0@AA 	 	HHRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 HHQKKQA...XXa[[b!HHQKKQA...q"r***q3'''q3'''''s   E66E:=E:c                    t          dd          }t          dd          }t          dd          }t          dd          }t          d	d
          }t          dd          }t          dd|          }t                      }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }t          |          }	|                     t
          d          5  |                    |           d d d            n# 1 swxY w Y   |                    |          }|                     t          |          |	           |                    |          }|                     t          |          |	dz
             |                    |          }|                     t          |          |	dz
             |                    |          }|                     t          |          |	dz
             |                     |                    |          d           |                     |                    |          d           |                    |          }|                    |          }|                    |          }|                    |          }|                     t          |          d           d S )Nr+  r,  ) r.  鉊 r  r0  r  r1  r  r2  r3  r4  r   r*   r   r'   r   r5  r6  r   r_   r  r   )	r   r   r2   ro   r   r   r  r    rO   )
r&   r,  r.  r  r  r  r3  r4  r   r7  s
             r   test_hamt_delete_2zHamtTest.test_hamt_delete_2  s   CFC  FC  CCD#VT!444FFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMq66 ##J0@AA 	 	HHRLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 HHQKKQ***HHQKKQA...HHQKKQA...HHQKKQA...q3'''q3'''HHQKKHHQKKHHQKKHHQKKQ#####s   D;;D?D?c                 L   t          dd          }t          dd          }t          dd          }t          dd          }t          dd	          }t                      }|                    |d
          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }t          |          }|                    |          }|                     t          |          |dz
             |                    |          }|                     t          |          |dz
             |                     |                    |          d           |                     |                    |          d           d S )Nr+  r,  r-  r.   r  r  r1  r  r*   r   r'   r   r5  r   r_   )r   r   r2   ro   r  r    rO   r&   r,  r.  r  r  r  r   r7  s           r   test_hamt_delete_3zHamtTest.test_hamt_delete_3  s\   CCFC  FC  CFFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMq66 HHQKKQA...HHQKKQA...q3'''q3'''''r   c                    t          dd          }t          dd          }t          dd          }t          dd          }t          dd          }t                      }|                    |d	          }|                    |d
          }|                    |d          }|                    |d          }|                    |d          }t          |          }|                    |          }|                     t          |          |dz
             |                    |          }|                     t          |          |dz
             |                    |          }|                     t          |          |dz
             |                    |          }|                     t          |          |dz
             |                    |          }|                     t          |          d           d S )Nr+  r,  r-  r.  r>  r  r  r  r*   r   r'   r   r5  r   r_   r     r   )r   r   r2   ro   r  r    r?  s           r   test_hamt_delete_4zHamtTest.test_hamt_delete_4  s   CCFC  FC  FC  FFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMq66 HHQKKQA...HHQKKQA...HHQKKQA...HHQKKQA...HHQKKQ#####r   c                 L   t                      }g }t          d          D ]M}t          |t          |                    }|                    |           |                    |d|           }Nt          dd          }|                    |d          }|                     t          |          d           |                    |d                   }|                     t          |          d           |                    |          }|                     t          |          d           |                    |d                   }|                     t          |          d           |                    |d	                   }|                     t          |          d
           |                    |d	                   }|                     t          |          d
           |D ]}|                    |          }|                     t          |          d           d S )N   zval-   18	collision   r_      r      r   )	r   r   r   r  r1   r2   r    ro   r  )r&   r   r   r   r  collision_key16s         r   test_hamt_delete_5zHamtTest.test_hamt_delete_5E  s   FFr 	' 	'A!SVV$$CKKc:!::&&AA!"d++EE/;//( 	Q$$$HHT!WQ$$$HH_%%Q$$$HHT"XQ$$$HHT!WQ$$$HHT!WQ$$$ 	 	CAAQ#####r   c           
         t          dd          }t          dd          }t          dd          }t          dd          }t          d	d
          }t          dd          }t                      }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                                }|                     t          t          |                    |df|df|df|df|df|dfh           d S )Nr+  r,  r:  r.  r;  r  r0  r  r1  r  n   Fr*   r   r'   r   r5  rb   r   r   r2   r   r    r   	r&   r,  r.  r  r  r  rP  r   its	            r   test_hamt_items_1zHamtTest.test_hamt_items_1v  s6   CFC  FC  CCCFFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMWWYYRMMX3x!SAs8aX3xH	J 	J 	J 	J 	Jr   c           
         t          dd          }t          dd          }t          dd          }t          dd          }t          dd          }t          d	d
          }t                      }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                                }|                     t          t          |                    |df|df|df|df|df|dfh           d S Nr+  r,  r-  r.  r>  r  r  r  rO  rP  r*   r   r'   r   r5  rb   rQ  rR  s	            r   test_hamt_items_2zHamtTest.test_hamt_items_2  s6   CCFC  FC  FC  CFFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMWWYYRMMX3x!SAs8aX3xH	J 	J 	J 	J 	Jr   c           	         t          dd          }t          dd          }t          dd          }t          dd          }t          dd          }t          d	d
          }t                      }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                    |d          }|                     t          t	          |                                                    ||||||h           |                     t          t	          |                    ||||||h           d S rV  )r   r   r2   r    r   r   )r&   r,  r.  r  r  r  rP  r   s           r   test_hamt_keys_1zHamtTest.test_hamt_keys_1  s9   CCFC  FC  FC  CFFEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMEE!SMMT!&&((^^,,q!Q1a.@AAAT!WW1aAq'9:::::r   c                     t                      }|                     t          |                                          d           |                     t	          |                                          g            d S )Nr   )r   r    ro   r   r   r   s     r   test_hamt_items_3zHamtTest.test_hamt_items_3  sY    FFQWWYY+++aggii"-----r   c                    t          dd          }t          dd          }t          dd          }t          dd          }t          dd	          }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               d S )Nr+  r,  r-  r.  r>  r  r  x   r  r*   r   r'   r   d2r5  )r   r   r2   assertFalse
assertTruer  )r&   r,  r.  r  r  r  r   r   s           r   test_hamt_eq_1zHamtTest.test_hamt_eq_1  s   CCFC  FC  CVVVVAs^^VVAs^^VVAs^^VVAs^^VVVVAs^^r"""b!!!VVAs^^r"""b!!!VVAs^^r"""b!!!VVAt__r"""b!!!VVAs^^b!!!r"""VVAs^^r"""b!!!YYq\\r"""b!!!VVAs^^r"""b!!!!!r   c                    t          dd          }t          dd|          }t                      }|                    |d          }t                      }|                    |d          }|                     t          d          5  ||k     d d d            n# 1 swxY w Y   |                     t          d          5  ||k     d d d            d S # 1 swxY w Y   d S )Nr+  r,  r4  r   r*   r6  )r   r   r2   r   r   )r&   r,  r4  r   r   s        r   test_hamt_eq_2zHamtTest.test_hamt_eq_2  sT   CS$q111VVVVAs^^VVVVB__##J0@AA 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ##J0@AA 	 	"HH	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s$   BB B?CCCc                 $   t          dd          }t                      }|                    dd          }t          j        |          }g }|                    |           |                    |           g }|                    |           |                    |           |                    ||          }~~~t          j                     t          j                     t          j                     |                      |                       d S )Nr+  r,  r   )	r   r   r2   weakrefrefr1   gccollectrk   )r&   r,  r   rf  r*   r   s         r   test_hamt_gc_1zHamtTest.test_hamt_gc_1  s    CFFEE!QKKk!nn				EE!QKKq!





##%%     r   c                    t          dd          }t          dd          }t                      }|                    |d          }|                    ||          }t          j        |          }|                                }t          |           ~~t          j                     t          j                     t          j                     | 	                     |                       d S )Nr+  r,  r-  r.  r*   )
r   r   r2   re  rf  r   nextrg  rh  rk   )r&   r,  r.  r   rf  his         r   test_hamt_gc_2zHamtTest.test_hamt_gc_2  s    CCFFEE!SMMEE!QKKk!nnWWYYRr





##%%     r   c                    t          dd          }t          dd          }t          dd          }t                      }|                    |d          }|                     ||v            |                     ||v            |                     t                    5  t          d          5  ||v  d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t                    5  t          d          5  ||v  d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S 	Nr+  r,  r-  r.  r   Tr  r  )	r   r   r2   r`  r_  r"   r   r   r   r&   r,  AAr.  r   s        r   test_hamt_in_1zHamtTest.test_hamt_in_1"  s8   CS#CFFEE!QKKQa   w'' 	 	D111  a              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 |,, 	 	d333  a              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sl   C.B?3C?C	CC	CCC;D5DD5D!	!D5$D!	%D55D9<D9c                    t          dd          }t          dd          }t          dd          }t                      }|                    |d          }|                     ||         d           |                     ||         d           |                     t
                    5  ||          d d d            n# 1 swxY w Y   |                     t                    5  t          d          5  ||          d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   |                     t                    5  t          d          5  ||          d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S ro  )	r   r   r2   r    r"   r   r   r   r   rp  s        r   test_hamt_getitem_1zHamtTest.test_hamt_getitem_16  s   CS#CFFEE!QKK1q!!!2"""x(( 	 	aDD	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 w'' 	 	D111  "              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 |,, 	 	d333  "              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s~   '	B<<C C !D2	D;DD	DD	DD"%D"F	E)F)E-	-F0E-	1FFFN)r<   r=   r>   r   r   r   r  r  r  r  r)  r8  r<  r@  rC  rM  rT  rW  rY  r[  ra  rc  ri  rm  rr  rt  r?   r   r   r   r     s       % % %    <  7 7 7#% #% #%J!F !F !FFW2 W2 W2r+( +( +(Z2$ 2$ 2$h"( "( "(H($ ($ ($T/$ /$ /$bJ J J*J J J*; ; ;&. . .
-" -" -"^   ! ! !.! ! !(  (    r   r   __main__)concurrent.futuresr   r
   r   rg  r   r   unittestre  test.supportr   	_testcapir   ImportErrorr   TestCaser   r   r  r   r   	Exceptionr   r   skipIfr   r<   mainr?   r   r   <module>r     s?               				     ) ) ) ) ) )   DDD  O3 O3 O3 O3 O3(# O3 O3 O3j
B B B B B B B BB	% 	% 	% 	% 	%S 	% 	% 	%               	 	 	 	 	9 	 	 		 	 	 	 	i 	 	 	 BCCX
 X
 X
 X
 X
x  X
 X
 DCX
v zHMOOOOO s   / 99