Your IP : 216.73.217.129


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_weakref.cpython-35.opt-2.pyc



���]��@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZda
dZGdd�d�ZGdd�d�Zd	d
�Zdd�ZGd
d�d�ZGdd�d�ZGdd�dej�Zejddd��ZGdd�de�ZGdd�de�ZGdd�dej�ZGdd�de�Zddl	mZGdd �d ej�ZGd!d"�d"ej�Z Gd#d$�d$ej�Z!d%Z"d&e"iZ#d'd(�Z$e%d)kre$�dS)*�N)�support)�
script_helperZfoobarc@seZdZdd�ZdS)�CcCsdS)N�)�selfrr�1/opt/alt/python35/lib64/python3.5/test_weakref.py�methodszC.methodN)�__name__�
__module__�__qualname__rrrrrrsrc@s"eZdZdZdd�ZdS)�CallableNcCs
||_dS)N)�bar)r�xrrr�__call__szCallable.__call__)r	r
rr
rrrrrrsrcCsdd�}|S)NcSsdS)Nrrrrr�f"szcreate_function.<locals>.fr)rrrr�create_function!srcCs
t�jS)N)rrrrrr�create_bound_method%src@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�ObjectcCs
||_dS)N)�arg)rrrrr�__init__*szObject.__init__cCsd|jS)Nz<Object %r>)r)rrrr�__repr__,szObject.__repr__cCs#t|t�r|j|jkStS)N)�
isinstancerr�NotImplemented)r�otherrrr�__eq__.sz
Object.__eq__cCs#t|t�r|j|jkStS)N)rrrr)rrrrr�__lt__2sz
Object.__lt__cCs
t|j�S)N)�hashr)rrrr�__hash__6szObject.__hash__cCsdS)N�r)rrrr�some_method8szObject.some_methodcCsdS)N�r)rrrr�other_method:szObject.other_methodN)
r	r
rrrrrrrr!rrrrr)src@seZdZdd�ZdS)�RefCyclecCs
||_dS)N)�cycle)rrrrr?szRefCycle.__init__N)r	r
rrrrrrr">sr"c@s(eZdZdd�Zdd�ZdS)�TestBasecCs
d|_dS)Nr)�cbcalled)rrrr�setUpEszTestBase.setUpcCs|jd7_dS)N�)r%)r�refrrr�callbackHszTestBase.callbackN)r	r
rr&r)rrrrr$Csr$g-C��6?c#s{tjd�}d���fdd�}tj��>|jd|�}|j�z	dVWdd�|j�XWdQRXdS)N�	threadingFcs(x!�s#tj��tj�qWdS)N)�time�sleep�gc�collectr)�period�please_stoprrr.Ts	
z"collect_in_thread.<locals>.collect�targetT)r�
import_moduleZ
disable_gc�Thread�start�join)r/r*r.�tr)r/r0r�collect_in_threadLs

	r7c@sVeZdZdd�Zdd�Zejdd��Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!d;d<�Z"d=d>�Z#ej$d?d@��Z%dAdB�Z&dCdD�Z'dEdF�Z(dGdH�Z)dIdJ�Z*dKdL�Z+dMdN�Z,dOdP�Z-dQdR�Z.dSdT�Z/dUdV�Z0dWdX�Z1dYdZ�Z2d[d\�Z3d]d^�Z4d_S)`�ReferencesTestCasecCsZ|jt�|jt�|jt�t�}tj|�}t|�~t|�dS)N)�check_basic_refrrr�weakrefr(�repr)r�o�wrrrr�test_basic_refes


	
z!ReferencesTestCase.test_basic_refcCs+|jt�|jt�|jt�dS)N)�check_basic_callbackrrr)rrrr�test_basic_callbackss

z&ReferencesTestCase.test_basic_callbackcCsqddl}|j}|�}tj|�}|j|�|�~|j|��|j|�|j|�dS)Nr)�	_testcapi�create_cfunctionr:r(�assertIs�assertIsNoner9r?)rrArBrr=rrr�test_cfunctionxs		
z!ReferencesTestCase.test_cfunctioncCsvt�}tj||j�}tj||j�}~|j|�d�|j|�d�|j|jdd�dS)Nz$expected reference to be invalidated�z-callback not called the right number of times)rr:r(r)rD�assertEqualr%)rr<�ref1�ref2rrr�test_multiple_callbacks�s	z*ReferencesTestCase.test_multiple_callbackscCsF|dd�}t�}tj||�|_tj||�}~dS)NcSs|j�dS)N)r()�objectrrrrr)�szDReferencesTestCase.test_multiple_selfref_callbacks.<locals>.callback)rr:r()rr)�crHrrr�test_multiple_selfref_callbacks�s
	z2ReferencesTestCase.test_multiple_selfref_callbackscCs)t�}|jttj|dd�dS)Nr))r�assertRaises�	TypeErrorr:r()rrLrrr�test_constructor_kwargs�s	z*ReferencesTestCase.test_constructor_kwargscCs�t�}d|_tj||j�}tj||j�}~dd�}|jt||�|jt||�|jtttjt���|j|j	d�dS)Nr'cSs|jdS)N)r
)�proxyrrr�check�sz0ReferencesTestCase.test_proxy_ref.<locals>.checkrF)
rr
r:rQr)rN�ReferenceError�boolrGr%)rr<rHrIrRrrr�test_proxy_ref�s		z!ReferencesTestCase.test_proxy_refcCsK|�}tj|�}|j|�d�|�}|j||d�dS)Nz,weak reference to live object should be livez-<ref>() should return original object if live)r:r(�assertIsNotNonerC)r�factoryr<r(�o2rrrr9�s		z"ReferencesTestCase.check_basic_refcCsWd|_|�}tj||j�}~|j|jdd�|j|�d�dS)Nrr'z(callback did not properly set 'cbcalled'z3ref2 should be dead after deleting object reference)r%r:r(r)rGrD)rrWr<r(rrrr?�s		z'ReferencesTestCase.check_basic_callbackcCs�t�}tj|�}tj|�}tj|�}|j||d�t�}tj|�}tj|�}tj|�}|j||d�|jtj|�dd�~|jtj|�dd�dS)Nz1reference object w/out callback should be re-usedrFzwrong weak ref count for objectr'z4wrong weak ref count for object after deleting proxy)rr:r(rQrCrG�getweakrefcount)rr<rHrQrIrrr�test_ref_reuse�s"		z!ReferencesTestCase.test_ref_reusecCsMt�}tj|�}tj|�}tj|�}|j||d�dS)Nz4proxy object w/out callback should have been re-used)rr:rQr(rC)rr<�proxy1r(�proxy2rrr�test_proxy_reuse�s	z#ReferencesTestCase.test_proxy_reusecCs�t�}|j|tj|��tj�}tj|�}|j|d�|jd�|jt	|�d�|j
|d�ddg|dd�<|jt	|�d�|jt	|�d�|jd|d�d|d<|j|dd�|j|dd�tj|�}tj|�}|j||�tjtd	��}tj|�}|j|dd�|dd��|j|dd�|dd��|j|dd�|dd��|j|dd�|dd��dS)
Nz(proxy for empty UserList should be false�r'z+proxy for non-empty UserList should be truerF�z,proxy didn't support __contains__() properlyr �
)
r�check_proxyr:rQ�collections�UserList�assertFalse�appendrG�len�
assertTrue�assertIn�range)rr<�L�pZL2�p2ZL3Zp3rrr�test_basic_proxy�s0	

$$$z#ReferencesTestCase.test_basic_proxycCsaGdd�dt�}|�}|jdttj|���|jttj|��d�dS)Nc@s(eZdZdd�Zdd�ZdS)z0ReferencesTestCase.test_proxy_unicode.<locals>.CcSsdS)N�stringr)rrrr�__str__sz8ReferencesTestCase.test_proxy_unicode.<locals>.C.__str__cSsdS)Nsbytesr)rrrr�	__bytes__sz:ReferencesTestCase.test_proxy_unicode.<locals>.C.__bytes__N)r	r
rrorprrrrrsrrpsbytes)rKrh�dirr:rQrG�bytes)rr�instancerrr�test_proxy_unicodes	z%ReferencesTestCase.test_proxy_unicodecCsHGdd�d�}|�}tj|�}|jtj|�d�dS)Nc@seZdZdd�ZdS)z.ReferencesTestCase.test_proxy_index.<locals>.CcSsdS)Nr`r)rrrr�	__index__
sz8ReferencesTestCase.test_proxy_index.<locals>.C.__index__N)r	r
rrurrrrrsrr`)r:rQrG�operator�index)rrr<rkrrr�test_proxy_indexs	z#ReferencesTestCase.test_proxy_indexcCs]Gdd�d�}|�}tj|�}|j|dd�|d}|j|d�dS)Nc@s(eZdZdd�Zdd�ZdS)z,ReferencesTestCase.test_proxy_div.<locals>.CcSsdS)N�*r)rrrrr�__floordiv__sz9ReferencesTestCase.test_proxy_div.<locals>.C.__floordiv__cSsdS)N�r)rrrrr�
__ifloordiv__sz:ReferencesTestCase.test_proxy_div.<locals>.C.__ifloordiv__N)r	r
rrzr|rrrrrsrr ryr{)r:rQrG)rrr<rkrrr�test_proxy_divs	
z!ReferencesTestCase.test_proxy_divcCs|jtj�dS)N)�check_shared_without_callbackr:r()rrrr� test_shared_ref_without_callback'sz3ReferencesTestCase.test_shared_ref_without_callbackcCs|jtj�dS)N)r~r:rQ)rrrr�"test_shared_proxy_without_callback*sz5ReferencesTestCase.test_shared_proxy_without_callbackcCs�td�}||d�}||d�}|j||d�~~||�}||d�}|j||d�~~||�}||�}|j||d�~~||d�}||�}|j||d�dS)Nr'z%both callbacks were None in the C APIz&callbacks were NULL, None in the C APIz%both callbacks were NULL in the C APIz&callbacks were None, NULL in the C API)rrC)r�makerefr<Zp1rlrrrr~-s z0ReferencesTestCase.check_shared_without_callbackcCs�t�}tj|�}|j||�|jt|�tjd�|d�|j|jdd�|dd�|j|jdd�|j	t
|�|j	t
|ddd�dS)	Nzproxy is not of callable typez	twinkies!z1call through proxy not passed through to originalrzSplat.r'rFr_)rr:rQrarC�type�CallableProxyTyperGr
rNrO)rr<rHrrr�test_callable_proxy?s	

z&ReferencesTestCase.test_callable_proxycCs�d|_|j|jdd�d|_|j|jdd�|`|jt|d�d�d|_|j|jdd�d|_|j|jdd�|`|jt|d�d	�dS)
Nr'z)proxy does not reflect attribute additionrFz-proxy does not reflect attribute modification�fooz(proxy does not reflect attribute removalz4object does not reflect attribute addition via proxyz8object does not reflect attribute modification via proxyz3object does not reflect attribute removal via proxy)r�rGrd�hasattr)rr<rQrrrraTs$				zReferencesTestCase.check_proxycCsIGdd�d�}|�}tj|�}|d=|j|jd�dS)Nc@s"eZdZdZdd�ZdS)z3ReferencesTestCase.test_proxy_deletion.<locals>.FooNcSs
||_dS)N)�result)rZaccessorrrr�__delitem__msz?ReferencesTestCase.test_proxy_deletion.<locals>.Foo.__delitem__)r	r
rr�r�rrrr�Fooksr�r)r:rQrGr�)rr��grrrr�test_proxy_deletionis
	z&ReferencesTestCase.test_proxy_deletioncCsHGdd�dt�}|�}|jttj|��t|��dS)Nc@seZdZdS)z0ReferencesTestCase.test_proxy_bool.<locals>.ListN)r	r
rrrrr�Listvsr�)�listrGrTr:rQ)rr�Zlystrrr�test_proxy_boolts	z"ReferencesTestCase.test_proxy_boolcCs�t�}tj|�}tj||j�}|jtj|�dd�tj|�}tj||j�}|jtj|�dd�~~~~|jtj|�dd�|jtjd�dd�dS)NrFz*got wrong number of weak reference objectsrrzAweak reference objects not unlinked from referent when discarded.r'z2got wrong number of weak reference objects for int)rr:r(r)rGrYrQ)rr<rHrIr[r\rrr�test_getweakrefcountzs	z'ReferencesTestCase.test_getweakrefcountcCs�t�}tj||j�}tj||j�}~|jtj|�|gd�t�}tj||j�}tj||j�}~|jtj|�|gd�~|jtj|�gd�|jtjd�gd�dS)Nzlist of refs does not matchzlist of refs not clearedr'z#list of refs does not match for int)rr:r(r)rG�getweakrefs)rr<rHrIrrr�test_getweakrefs�s"		z#ReferencesTestCase.test_getweakrefscCs]Gdd�dt�}|d�}tj|�}|j|dd�|jd|d�dS)Nc@seZdZdS)z6ReferencesTestCase.test_newstyle_number_ops.<locals>.FN)r	r
rrrrr�F�sr�g@g�?g@)�floatr:rQrG)rr�rrkrrr�test_newstyle_number_ops�s
z+ReferencesTestCase.test_newstyle_number_opscs�Gdd�dt��i��fdd�����fdd�}y|�Wn�k
reYnX|jd�y|�Wn�k
r�YnX|jd�dS)Nc@seZdZdS)z?ReferencesTestCase.test_callbacks_protected.<locals>.BogusErrorN)r	r
rrrrr�
BogusError�sr�cs�|=dS)Nr)�k)�datarr�remove�sz;ReferencesTestCase.test_callbacks_protected.<locals>.removecs,dd�}d�tj|��<��dS)NcSsfS)Nrrrrr�<lambda>�szRReferencesTestCase.test_callbacks_protected.<locals>.encapsulate.<locals>.<lambda>)r:r()r)r�r�r�rr�encapsulate�sz@ReferencesTestCase.test_callbacks_protected.<locals>.encapsulatezexception not properly restored)�	ExceptionZfail)rr�r)r�r�r�r�test_callbacks_protected�s


z+ReferencesTestCase.test_callbacks_protectedcs�ddl�Gdd�dt�}|�}tj|�fdd��}~~|�}|�|_tj|j�fdd��}|�}||_~~dS)Nrc@seZdZdS)z0ReferencesTestCase.test_sf_bug_840829.<locals>.CN)r	r
rrrrrr�srcs
�j�S)N)r.)�ignore)r-rrr��sz7ReferencesTestCase.test_sf_bug_840829.<locals>.<lambda>cs
�j�S)N)r.)r�)r-rrr��s)r-rKr:r(�i�c1)rrrLr=r��c2r)r-r�test_sf_bug_840829�s		!			z%ReferencesTestCase.test_sf_bug_840829cCsyddl}Gdd�dt�}Gdd�dt�}|�}||_tj||j�|_~~~|j�dS)Nrc@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_1.<locals>.JN)r	r
rrrrr�J�sr�c@seZdZdd�ZdS)z7ReferencesTestCase.test_callback_in_cycle_1.<locals>.IIcSs|jdS)N)r�)rr�rrr�	acallback�szAReferencesTestCase.test_callback_in_cycle_1.<locals>.II.acallbackN)r	r
rr�rrrr�II�sr�)r-rKr�r:r(r�r=r.)rr-r�r��Irrr�test_callback_in_cycle_1�s			z+ReferencesTestCase.test_callback_in_cycle_1cCsvddl}Gdd�dt�}Gdd�d�}|�}||_tj||j�|_~~~|j�dS)Nrc@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_2.<locals>.JN)r	r
rrrrrr�&sr�c@seZdZdd�ZdS)z7ReferencesTestCase.test_callback_in_cycle_2.<locals>.IIcSs|jdS)N)r�)rr�rrrr�*szAReferencesTestCase.test_callback_in_cycle_2.<locals>.II.acallbackN)r	r
rr�rrrrr�)sr�)r-rKr�r:r(r�r=r.)rr-r�r�r�rrr�test_callback_in_cycle_2s			z+ReferencesTestCase.test_callback_in_cycle_2cCspddl}Gdd�d�}|�|�}}||_||_tj||j�|_~~|j�dS)Nrc@seZdZdd�ZdS)z6ReferencesTestCase.test_callback_in_cycle_3.<locals>.CcSs|j|j|jdS)N)�mer�r=)rr�rrr�cb>sz9ReferencesTestCase.test_callback_in_cycle_3.<locals>.C.cbN)r	r
rr�rrrrr=sr)r-r�r�r:r(r�r=r.)rr-rr�r�rrr�test_callback_in_cycle_34s		z+ReferencesTestCase.test_callback_in_cycle_3cCs�ddl}Gdd�dt�}Gdd�d�}|�|�}}||_||_tj||j�|_~~~~|j�dS)Nrc@seZdZdd�ZdS)z6ReferencesTestCase.test_callback_in_cycle_4.<locals>.CcSs|j|j|jdS)N)r�r�r=)rr�rrrr�Wsz9ReferencesTestCase.test_callback_in_cycle_4.<locals>.C.cbN)r	r
rr�rrrrrVsrc@seZdZdS)z6ReferencesTestCase.test_callback_in_cycle_4.<locals>.DN)r	r
rrrrr�D\sr�)	r-rKr�r�r:r(r�r=r.)rr-rr�r�r�rrr�test_callback_in_cycle_4Ls			z+ReferencesTestCase.test_callback_in_cycle_4cs!ddl}g�G�fdd�dt�}|d�|d�}}||_||_tj||j�|_tj||j�|_�fdd�}tj||�}~~~|j�g�|j�|j�dg�|j|�d��dd�=|j�|j�g�dS)	Nrcs.eZdZdd�Z�fdd�ZdS)zAReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.CcSs
||_dS)N)Z	attribute)r�valuerrrrwszJReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.__init__cs�j|j�dS)N)rerL)rr�)�alistrrr�zszKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.acallbackN)r	r
rrr�r)r�rrrvsrr'rFcs�jd�dS)NzC went away)re)r�)r�rr�C_went_away�szKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C_went_awayzC went away)	r-rKrLr:r(r�r=rGr.)rr-rr�r�r�r=r)r�r�#test_callback_in_cycle_resurrectionhs$			


z6ReferencesTestCase.test_callback_in_cycle_resurrectioncs7ddl}g��fdd�}G�fdd�dt�}|�|�}}||_||_|j}tj||�|_tj||j�|_tj||�}|j|�|�~~~~|j�g�|j	�|j�dg�|j|�d��dd�=|j	�|j�g�dS)Nrcs�jd�dS)Nzsafe_callback called)re)r�)r�rr�
safe_callback�szDReferencesTestCase.test_callbacks_on_callback.<locals>.safe_callbackcs"eZdZ�fdd�ZdS)z8ReferencesTestCase.test_callbacks_on_callback.<locals>.Ccs�jd�dS)Nz	cb called)re)rr�)r�rrr��sz;ReferencesTestCase.test_callbacks_on_callback.<locals>.C.cbN)r	r
rr�r)r�rrr�srzsafe_callback called)
r-rKrr�r:r(r=rCrGr.)rr-r�rrL�dr)Zexternal_wrr)r�r�test_callbacks_on_callback�s(				


z-ReferencesTestCase.test_callbacks_on_callbackcCs|jtj�dS)N)�check_gc_during_creationr:r()rrrr�test_gc_during_ref_creation�sz.ReferencesTestCase.test_gc_during_ref_creationcCs|jtj�dS)N)r�r:rQ)rrrr�test_gc_during_proxy_creation�sz0ReferencesTestCase.test_gc_during_proxy_creationcCs�tj�}tjddd�tj�Gdd�d�}dd�}|�}|�}||_||�|_z|�}tj||�Wdtj|�XdS)Nr'c@seZdZdS)z6ReferencesTestCase.check_gc_during_creation.<locals>.AN)r	r
rrrrr�A�sr�cWsdS)Nr)�argsrrrr)�sz=ReferencesTestCase.check_gc_during_creation.<locals>.callback)r-�
get_threshold�
set_thresholdr.�ar=r:r()rr�Z
thresholdsr�r)Z
referencedr�rrrr��s
				z+ReferencesTestCase.check_gc_during_creationcCs#Gdd�dt�}|�}dS)Nc@seZdZdd�ZdS)z>ReferencesTestCase.test_ref_created_during_del.<locals>.TargetcSstj|�adS)N)r:r(�ref_from_del)rrrr�__del__�szFReferencesTestCase.test_ref_created_during_del.<locals>.Target.__del__N)r	r
rr�rrrr�Target�sr�)rK)rr��wrrr�test_ref_created_during_del�sz.ReferencesTestCase.test_ref_created_during_delcCs?tjt�}|jt|jddddd�tj�dS)Nr)r:r(r�rNrOrr-r.)r�rrrr�	test_init�s"zReferencesTestCase.test_initcCsxGdd�dt�}g}tjt�tj||j�}d}tj�|j|�d�|j||g�dS)Nc@seZdZdS)z*ReferencesTestCase.test_classes.<locals>.AN)r	r
rrrrrr��sr�)rKr:r(�intrer-r.rG)rr��lr�rrr�test_classes�s

zReferencesTestCase.test_classesc	Cs�td�}td�}td�}tj|�}tj|�}tj|�}tj|�}|j||k�|j||k�|j||k�|j||k�|j||k�|j||k�~~~tj�x*|||fD]}|j|�d�q�W|j||k�|j||k�|j||k�|j||k�|j||k||k�|j||k||k	�dS)Nr'rF)	rr:r(rgrdr-r.rCrG)	rr�y�zr��brLr�r�rrr�
test_equality�s.	
z ReferencesTestCase.test_equalitycCs�tjtjtjtjg}td�}td�}tj|�}tj|�}x$|D]}|jt	|||�q[W~~t
j�x$|D]}|jt	|||�q�WdS)Nr')rv�lt�gt�le�gerr:r(rNrOr-r.)rZopsrr�r�r��oprrr�
test_orderings


z ReferencesTestCase.test_orderingcCs�td�}td�}tj|�}tj|�}|jt|�td��~~tj�|jt|�td��|jtt|�dS)Nry)	rr:r(rGrr-r.rNrO)rrr�r�r�rrr�test_hashing,s
zReferencesTestCase.test_hashingcCskGdd�d�}tj�}|d�}}x(td�D]}||�||<}q<W~tj�dS)Nc@seZdZdd�ZdS)z1ReferencesTestCase.test_trashcan_16602.<locals>.CcsD|s
dStj|���fdd�}tj||�|_dS)Ncs
��}dS)Nr)�wparentr<)�wselfrrr�EszFReferencesTestCase.test_trashcan_16602.<locals>.C.__init__.<locals>.cb)r:r(r�)r�parentr�r)r�rrAs
z:ReferencesTestCase.test_trashcan_16602.<locals>.C.__init__N)r	r
rrrrrrr@sr�d)r:�WeakKeyDictionaryrir-r.)rrr��rootrL�nrrr�test_trashcan_16602;s	z&ReferencesTestCase.test_trashcan_16602cCs`td�}dd�}tj||�}|j|j|�tj|�}|j|j�dS)Nr'cSsdS)Nr)r(rrrr�Rsz<ReferencesTestCase.test_callback_attribute.<locals>.<lambda>)rr:r(rC�__callback__rD)rrr)rHrIrrr�test_callback_attributePsz*ReferencesTestCase.test_callback_attributecCsRtd�}tj||j�}|j|j�~tj�|j|j�dS)Nr')	rr:r(r)rVr�r�
gc_collectrD)rrr(rrr�&test_callback_attribute_after_deletionYs
z9ReferencesTestCase.test_callback_attribute_after_deletionc	CsTtd�}dd�}tj||�}|jt��dd�|_WdQRXdS)Nr'cSsdS)Nr)r(rrrr�csz@ReferencesTestCase.test_set_callback_attribute.<locals>.<lambda>cSsdS)Nr)r(rrrr�fs)rr:r(rN�AttributeErrorr�)rrr)rHrrr�test_set_callback_attributeas
z.ReferencesTestCase.test_set_callback_attributecCsKGdd�dt�}|d�}tj|dd��}~tj�dS)Nc@seZdZdd�ZdS)z;ReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDelcSsdS)Nr)rrrrr�jszCReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDel.__del__N)r	r
rr�rrrr�
ObjectWithDelisr�r'cSs
tj�S)N)rr�)r(rrrr�lsz6ReferencesTestCase.test_callback_gcs.<locals>.<lambda>)rr:r(rr�)rr�rrHrrr�test_callback_gcshs
z$ReferencesTestCase.test_callback_gcsN)5r	r
rr>r@r�cpython_onlyrErJrMrPrUr9r?rZr]rmrtrxr}rr�r~r�rar�r�r�r�r�r�r�r�r�r�r�Zrequires_type_collectingr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr8cs^
	
((/&!	r8c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�SubclassableWeakrefTestCasecCs�Gdd�dtj�}td�}||dd�}|j|�|�|j|j�|j|jd�~|j|��|j|j�dS)Ncs:eZdZdd�fdd�Z�fdd�Z�S)z=SubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRefNrycs ||_t�j||�dS)N)r��superr)r�obr)r�)�	__class__rrrus	zFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__init__csd|_t�j�S)NT)�calledr�r)r)r�rrrxs	zFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__call__)r	r
rrrrr)r�r�MyReftsr�r�r��)	r:r(rrCrgr�rGr�rD)rr�r<�mrrrr�test_subclass_refsssz.SubclassableWeakrefTestCase.test_subclass_refscCsGdd�dtj�}td�}||�}tj|�}|j||�|jtj|�||g�|jtj|�d�||�}|jtj|�d�tj|�}|jt|�d�|j||d�|j	||dd��|j	||dd��dS)Nc@seZdZdS)zXSubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refs.<locals>.MyRefN)r	r
rrrrrr��sr�ryrFr_rr')
r:r(r�assertIsNotrGr�rYrfrCrh)rr�r<�r1�r2Zr3�refsrrr�-test_subclass_refs_dont_replace_standard_refs�szISubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refscCs�Gdd�dtj�}td�}||t�}||t�}|j||�tj|�}|j||�|j||�dS)Nc@seZdZdS)zUSubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbacks.<locals>.MyRefN)r	r
rrrrrr��sr�ry)r:r(r�id�strr�r�rh)rr�r<r�r�r�rrr�*test_subclass_refs_dont_conflate_callbacks�szFSubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbackscCs�Gdd�dtj�}td�}||ddd�}|j|jd�|j|jd�|j|j�d�|jt|d��dS)Nc@s:eZdZd
Zdd�Zdd�Zdd�Zd	S)zHSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef�slot1�slot2cSstjj|||�S)N)r:r(�__new__)r�r�r)r�r�rrrr��szPSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__new__cSs||_||_dS)N)r�r�)rr�r)r�r�rrrr�s	zQSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__init__cSs|j|jS)N)r�r�)rrrr�meth�szMSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.methN)r�r�)r	r
r�	__slots__r�rr�rrrrr��sr�ry�abc�defZabcdef�__dict__)	r:r(rrGr�r�r�rdr�)rr�r<r�rrr�test_subclass_refs_with_slots�s	z9SubclassableWeakrefTestCase.test_subclass_refs_with_slotscs�Gdd�dtj�}�fdd�}t�}|||�}||_~~�j�jd�t�}|||�}|||�}||_||_~~~�j�jd�dS)Nc@seZdZdS)zHSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.MyRefN)r	r
rrrrrr��sr�cs�jd7_dS)Nr')r%)r�)rrrr)�szKSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.callbackr)r:r(rr<rGr%r�)rr�r)r<r�r�r)rr�test_subclass_refs_with_cycle�s"					z9SubclassableWeakrefTestCase.test_subclass_refs_with_cycleN)r	r
rr�r�r�r�r�rrrrr�qs
r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
d
d��Zdd�Zdd�Z
dS)�WeakMethodTestCasecCsGdd�dt�}|S)Nc@seZdZdd�ZdS)z'WeakMethodTestCase._subclass.<locals>.CcSsdS)N�r)rrrrr�sz3WeakMethodTestCase._subclass.<locals>.C.some_methodN)r	r
rrrrrrr�sr)r)rrrrr�	_subclass�szWeakMethodTestCase._subclasscCs�td�}tj|j�}|j|tj�|j|�t|j��|j|�j|�|j|�j	|jj	�|j
|��d�dS)Nr'r)rr:�
WeakMethodrZassertIsInstance�
ReferenceTyper�rC�__self__�__func__rG)rr<r�rrr�
test_alive�szWeakMethodTestCase.test_alivecCsBtd�}tj|j�}~tj�|j|�d�dS)Nr')rr:rrr-r.rC)rr<r�rrr�test_object_dead�s

z#WeakMethodTestCase.test_object_deadcCsQ|j�}|d�}tj|j�}|`tj�|j|�d�dS)Nr')r�r:rrr-r.rC)rrr<r�rrr�test_method_dead�s
z#WeakMethodTestCase.test_method_deadcs�|j�}g��fdd�}|d�}tj|j|�}~tj�|j�|g�tj|_tj�|j�|g�dS)Ncs�j|�dS)N)re)r)�callsrrr��sz=WeakMethodTestCase.test_callback_when_object_dead.<locals>.cbr')r�r:rrr-r.rGr)rrr�r<r�r)rr�test_callback_when_object_dead�s

z1WeakMethodTestCase.test_callback_when_object_deadcs�|j�}g��fdd�}|d�}tj|j|�}|`tj�|j�|g�~tj�|j�|g�dS)Ncs�j|�dS)N)re)r)rrrr�
sz=WeakMethodTestCase.test_callback_when_method_dead.<locals>.cbr')r�r:rrr-r.rG)rrr�r<r�r)rr�test_callback_when_method_dead	s

z1WeakMethodTestCase.test_callback_when_method_deadcCsVtd�}dd�}tj|j|�}tj|�}~|j|�d�dS)Nr'cSsdS)Nr)�_rrrr�sz-WeakMethodTestCase.test_no_cycles.<locals>.cb)rr:rrr(rC)rr<r�r�r=rrr�test_no_cyclessz!WeakMethodTestCase.test_no_cyclescs��fdd�}�fdd�}td�}td�}tj|j�}tj|j�}tj|j�}tj|j�}|||�|||�|||�|||�|||�|||�td�}	tj|	j�}
tj|	j�}|||
�|||�|||
�|||�~~~	tj�|||||
|f}xW|D]O}
xF|D]>}�j|
|k|
|k��j|
|k|
|k	�quWqhWdS)Ncs*�j||k��j||k�dS)N)rgrd)r�r�)rrr�_eq%sz-WeakMethodTestCase.test_equality.<locals>._eqcs*�j||k��j||k�dS)N)rgrd)r�r�)rrr�_ne(sz-WeakMethodTestCase.test_equality.<locals>._ner'rF)rr:rrr!r-r.rG)rrr
rr�r�r�rLr�r��err��qr�r)rrr�$s8









	


z WeakMethodTestCase.test_equalitycCs�td�}td�}tj|j�}tj|j�}tj|j�}|jt|�t|��t|�}~~tj�|jt|�|�|jt|�|�|j	t
t|�dS)Nr')rr:rrr!rGrr-r.rNrO)rrr�r�r�rLZharrrr�Js
zWeakMethodTestCase.test_hashingN)r	r
rr�rrrrr	rr�rr�r�rrrrr��s	&r�c@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�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.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z d<d=�Z!d>d?�Z"d@dA�Z#dBdC�Z$dDdE�Z%dFdG�Z&dHdI�Z'dJdK�Z(dLdM�Z)dNdO�Z*dPdQ�Z+dRdS�Z,dTS)U�MappingTestCaser`c	s�d}dd�t|�D�}|�fdd�|D��}|j�}yt|�Wntk
rlYnX~tj�t|�}~tj�t|�}|j|d�|j|d�dS)	N�cSsg|]}t��qSr)r")�.0r�rrr�
<listcomp>ds	z4MappingTestCase.check_len_cycles.<locals>.<listcomp>c3s|]}�|�VqdS)Nr)rr<)�consrr�	<genexpr>esz3MappingTestCase.check_len_cycles.<locals>.<genexpr>rr')rr')	ri�items�next�
StopIterationr-r.rfrhrG)	r�	dict_typer�Nr�dct�it�n1�n2r)rr�check_len_cyclesbs 


z MappingTestCase.check_len_cyclescCs|jtjdd��dS)NcSs
|dfS)Nr'r)r�rrrr�wsz<MappingTestCase.test_weak_keyed_len_cycles.<locals>.<lambda>)rr:r�)rrrr�test_weak_keyed_len_cyclesvsz*MappingTestCase.test_weak_keyed_len_cyclescCs|jtjdd��dS)NcSs
d|fS)Nr'r)r�rrrr�zsz=MappingTestCase.test_weak_valued_len_cycles.<locals>.<lambda>)rr:�WeakValueDictionary)rrrr�test_weak_valued_len_cyclesysz+MappingTestCase.test_weak_valued_len_cyclesc
s"|jtjtj��xtdd�D]�}d}tjd�tj|||�dd�t|�D�}|�fdd�|D��}~|j�}yt|�Wntk
r�YnXt	|�}~t	|�}	|j
|d�|j||�|j
|	d�|j|	|�q)WdS)	Nr'r�rrcSsg|]}t��qSr)r")rr�rrrr�s	z2MappingTestCase.check_len_race.<locals>.<listcomp>c3s|]}�|�VqdS)Nr)rr<)rrrr�sz1MappingTestCase.check_len_race.<locals>.<genexpr>)Z
addCleanupr-r�r�rir.rrrrfZassertGreaterEqualZassertLessEqual)
rrr�thrrrrrrr)rr�check_len_race|s(

zMappingTestCase.check_len_racecCs|jtjdd��dS)NcSs
|dfS)Nr'r)r�rrrr��sz:MappingTestCase.test_weak_keyed_len_race.<locals>.<lambda>)r$r:r�)rrrr�test_weak_keyed_len_race�sz(MappingTestCase.test_weak_keyed_len_racecCs|jtjdd��dS)NcSs
d|fS)Nr'r)r�rrrr��sz;MappingTestCase.test_weak_valued_len_race.<locals>.<lambda>)r$r:r!)rrrr�test_weak_valued_len_race�sz)MappingTestCase.test_weak_valued_len_racecCsU|j�\}}xA|D]9}|jtj|�d�|j|||jd�qWt|j��}t|j�j��}|j	�|j	�|j||d�~~|jt
|�|j�|d=|jt
|�|jdd�~~|jt
|�dd�tj�}|j
t|jd�t�|d<|j
t|jd�dS)Nr'z#wrong object returned by weak dict!z/cloning of weak-valued dictionary did not work!rz/deleting object did not cause dictionary updatez0deleting the values did not clear the dictionaryrF)�make_weak_valued_dictrGr:rYrCrr�r�copy�sortrf�COUNTr!rN�KeyError�__getitem__r)r�dict�objectsr<�items1�items2rrr�test_weak_values�s.



z MappingTestCase.test_weak_valuescCs9|j�\}}xH|D]@}|jtj|�dd|�|j|j||d�qW|j�}|j�j�}|jt|�t|�d�~~|jt	|�|j
�|d=|jt	|�|j
dd�~~|jt	|�dd�td�}d	||<|j||�|j
d
|�dS)Nr'z&wrong number of weak references to %r!z#wrong object returned by weak dict!z.cloning of weak-keyed dictionary did not work!rz/deleting object did not cause dictionary updatez.deleting the keys did not clear the dictionaryryz$What is the meaning of the universe?�")�make_weak_keyed_dictrGr:rYrCrrr(�setrfr*rrh�assertNotIn)rr-r.r<r/r0rrr�test_weak_keys�s,

zMappingTestCase.test_weak_keyscCsy|j�\}}|j|�|j�}|jt|�t|��t|�}x[|D]S}|�}|j||�|j||�|j|j||�|j|�qZW|jt|�d�t|�}|jtt|j���t|��xa|j�D]S}|�}|j||�|j||�|j|j||�|j|�qW|jt|�d�dS)Nr)	r3�check_iters�keyrefsrGrfr�rhrr�)rr-r.r��objects2r=r�rrr�test_weak_keyed_iters�s*

	(	z%MappingTestCase.test_weak_keyed_iterscCss|j�\}}|j|�|j�}|jt|�t|��t|�}xX|D]P}|�}|j|||j�|j|j||jj�|j|�qZW|jt|�d�t|�}|jtt|j���t|��x^|j�D]P}|�}|j|||j�|j|j||jj�|j|�qW|jt|�d�dS)Nr)	r'r7�	valuerefsrGrfr�rr��
itervaluerefs)rr-r.r�r9r=r�rrr�test_weak_valued_iters�s&

	(	z&MappingTestCase.test_weak_valued_iterscCst|j��}x!|j�D]}|j|�qW|j|d�t|j��}x|D]}|j|�q_W|j|d�t|j��}x!|j�D]}|j|�q�W|j|d�t|j��}x!|j�D]}|j|�q�W|j|d�dS)Nzitems() did not touch all itemsz!__iter__() did not touch all keysz!iterkeys() did not touch all keysz%itervalues() did not touch all values)r�rr�rd�keys�values)rr-r�itemr>r�r?�vrrrr7s"
	zMappingTestCase.check_iterscCs�t|�}tt||���}t|�|d=tj�|jtt|��t|�t|�dg�~|jt|�|d�dS)Nr'���)	rf�iter�getattrrr-r.rhr�rG)rr-r.Z	iter_namer�rrrr�"check_weak_destroy_while_iterating!s

2z2MappingTestCase.check_weak_destroy_while_iteratingc-Cs`|��\}}|j||�WdQRX|��#\}}|jt|j|�WdQRX|j||�|��#\}}|jt|j|�WdQRX|j||�|��\}}|||<WdQRX|j|||�tj|�}|��\}}|j|�WdQRX|j||�|��\}}|j�WdQRX|jt	|�d�dS)Nr)
r5rNr+r��poprGr(�update�clearrf)rr-�testcontextr�rAZddictrrr�-check_weak_destroy_and_mutate_while_iterating.s$z=MappingTestCase.check_weak_destroy_and_mutate_while_iteratingc&Cs�td�}|��Ut|�}|j�|jt|�|d�|||<|jt|�|�WdQRX|��R|jt|�|d�|jt|j���|jt|�|d�WdQRX|��L|jt|�|d�|t|j��=|jt|�|d�WdQRX|��C|jt|�|d�|j�|jt|�|d�WdQRX|��%|j�|jt|�d�WdQRX|jt|�d�dS)	Ni@�r'rFr_rr r�r)rrf�popitemrGrFrr>rH)rr-rIr<r�rrr�&check_weak_del_and_len_while_iteratingGs.



!
!

!

z6MappingTestCase.check_weak_del_and_len_while_iteratingcs�|j�\��|j��d�|j��d�|j��d�|j��d�|j�\��tj��fdd��}|j�|�|j�\��|j�|�dS)Nr>rr?r8c
3sbzJt�j��}t|��j�j}tj�t|�|fVWdd}tj�XdS)N)rCrrrFrr-r.r)rrA)r-r.rrrIms

zKMappingTestCase.test_weak_keys_destroy_while_iterating.<locals>.testcontext)r3rE�
contextlib�contextmanagerrJrL)rrIr)r-r.r�&test_weak_keys_destroy_while_iteratingesz6MappingTestCase.test_weak_keys_destroy_while_iteratingcs�|j�\��|j��d�|j��d�|j��d�|j��d�|j��d�|j�\��tj��fdd��}|j�|�|j�\��|j�|�dS)Nr>rr?r<r;c
3sbzJt�j��}t|��j�j}tj�|t|�fVWdd}tj�XdS)N)rCrrrFrr-r.r)rr�)r-r.rrrI�s

zMMappingTestCase.test_weak_values_destroy_while_iterating.<locals>.testcontext)r'rErMrNrJrL)rrIr)r-r.r�(test_weak_values_destroy_while_iteratingsz8MappingTestCase.test_weak_values_destroy_while_iteratingcCs9td�}tj|di�}|j||d�dS)Nr_il)rr:r�rG)rr<r-rrr�#test_make_weak_keyed_dict_from_dict�sz3MappingTestCase.test_make_weak_keyed_dict_from_dictcCsHtd�}tj|di�}tj|�}|j||d�dS)Nr_il)rr:r�rG)rr<r-�dict2rrr�.test_make_weak_keyed_dict_from_weak_keyed_dict�sz>MappingTestCase.test_make_weak_keyed_dict_from_weak_keyed_dictcCsRtj�}tttt|j���}x|D]}|j||<q1W||fS)N)r:r�r��maprrir*r)rr-r.r<rrrr3�s

z$MappingTestCase.make_weak_keyed_dictcCs9td�}tjd|i�}|j|d|�dS)Nr_il)rr:r!rG)rr<r-rrr�$test_make_weak_valued_dict_from_dict�sz4MappingTestCase.test_make_weak_valued_dict_from_dictcCsHtd�}tjd|i�}tj|�}|j|d|�dS)Nr_il)rr:r!rG)rr<r-rRrrr�0test_make_weak_valued_dict_from_weak_valued_dict�sz@MappingTestCase.test_make_weak_valued_dict_from_weak_valued_dictcCs�|jttjj�|jttjii�|jttjff�td�}xVdD]N}tj||i�}|jt|j��|g�|j|||�q[WdS)Nr_rr-r�iterable)rr-rrW)	rNrOr:r!rrrGr�r>)rr<�kwr�rrr�test_make_weak_valued_dict_misc�s
z/MappingTestCase.test_make_weak_valued_dict_misccCsRtj�}tttt|j���}x|D]}|||j<q1W||fS)N)r:r!r�rTrrir*r)rr-r.r<rrrr'�s

z%MappingTestCase.make_weak_valued_dictc	Cs�|�}|||<|||<|jt|�d�|j�\}}|jt|�d�||krz|j||�n|j||�|j�\}}|jt|�d�||kr�|j||�n|j||�dS)NrFr'r)rGrfrKrC)	r�klass�key1�value1�key2�value2�weakdictr�rArrr�
check_popitem�s	

zMappingTestCase.check_popitemcCs&|jtjdt�dt��dS)Nr[r])r`r:r!r)rrrr�test_weak_valued_dict_popitem�sz-MappingTestCase.test_weak_valued_dict_popitemcCs&|jtjt�dt�d�dS)Nzvalue 1zvalue 2)r`r:r�r)rrrr�test_weak_keyed_dict_popitem�sz,MappingTestCase.test_weak_keyed_dict_popitemcCs�|j||d�|�}|j||�}|j||�|j||�|j|j|�|�|j|||�|j||�}|j||�|j||�|j|j|�|�|j|||�dS)Nz9invalid test -- value parameters must be distinct objects)r��
setdefaultrCrh�get)rrZ�keyr\r^r_r<rrr�check_setdefault�s	z MappingTestCase.check_setdefaultcCs#|jtjdt�t��dS)Nre)rfr:r!r)rrrr� test_weak_valued_dict_setdefault�sz0MappingTestCase.test_weak_valued_dict_setdefaultcCs |jtjt�dd�dS)Nzvalue 1zvalue 2)rfr:r�r)rrrr�test_weak_keyed_dict_setdefault�sz/MappingTestCase.test_weak_keyed_dict_setdefaultcCs�|�}|j|�|jt|�t|��xc|j�D]U}|j||d�|j|�}|j|||�|j||j|��q?Wx^|j�D]P}|j||d�||}|j|||�|j||j|��q�WdS)Nz(mysterious new key appeared in weak dictz%original key disappeared in weak dict)rGrGrfr>rhrdrC)rrZr-r_r�rArrr�check_update�s	

zMappingTestCase.check_updatecCs|jtjdt�dt�t�t�i�|jttjj�tj�}|jt|jii�|jt|jff�|jt|j	��g�t
d�}x`dD]X}tj�}|j||i�|jt|j	��|g�|j|||�q�WdS)	Nr'r�r_rr-rrW)rr-rrW)rir:r!rrNrOrGrGr�r>r)rr�r<rXrrr�test_weak_valued_dict_updates%
z,MappingTestCase.test_weak_valued_dict_updatecCs2|jtjt�dt�dt�di�dS)Nr'rFr_)rir:r�r)rrrr�test_weak_keyed_dict_updatesz+MappingTestCase.test_weak_keyed_dict_updatecCs�tj�}td�}td�}d||<d||<|jt|�d�||=|jt|�d�|jt|j��|g�dS)N�1�2�	somethingrFr')r:r�rrGrfr�r>)rr��o1rXrrr�test_weak_keyed_delitem#s

z'MappingTestCase.test_weak_keyed_delitemcCs�tj�}td�}td�}||d<||d<|jt|�d�|d=|jt|�d�|jt|j��d|fg�dS)Nrlrmrnzsomething elserFr')r:r!rrGrfr�r)rr�rorXrrr�test_weak_valued_delitem.s

z(MappingTestCase.test_weak_valued_delitemcCs�tj�}td�}|jt|j|�|jt|j|�|jt|jd�|jt|jd�|jt|jdd�dS)Nrl�
)	r:r�rrNr+r�r,rO�__setitem__)rr�r<rrr�test_weak_keyed_bad_delitem9sz+MappingTestCase.test_weak_keyed_bad_delitemcs�tj�}d�G��fdd�dt���fdd�td�D��x�D]}|j||<qWW~t|j����j�d�d}x�D]}|d	7}||=q�W|jt	|�d�|j|d
�dS)NFcs=eZdZdd�Zdd�Z��fdd�ZdS)z<MappingTestCase.test_weak_keyed_cascading_deletes.<locals>.CcSs
||_dS)N)r�)rr�rrrrPszEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__init__cSs
t|j�S)N)rr�)rrrrrRszEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__hash__cs�r
�d=|j|jkS)Nr'rB)r�)rr)�mutate�objsrrrTszCMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__eq__N)r	r
rrrrr)rurvrrrOsrcsg|]}�|��qSrr)rr�)rrrr[s	zEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.<listcomp>rTrr'rF)
r:r�rKrir�r�r>�reverserGrf)rr�r<�countr)rrurvr�!test_weak_keyed_cascading_deletesGs 

	

z1MappingTestCase.test_weak_keyed_cascading_deletescCs&tj�}|jt|�d�dS)Nz<WeakValueDictionary at 0x.*>)r:r!�assertRegexr;)rr-rrr�test_make_weak_valued_dict_reprtsz/MappingTestCase.test_make_weak_valued_dict_reprcCs&tj�}|jt|�d�dS)Nz<WeakKeyDictionary at 0x.*>)r:r�rzr;)rr-rrr�test_make_weak_keyed_dict_reprxsz.MappingTestCase.test_make_weak_keyed_dict_reprcCs`tj�}t��Dx<td�D].}|jdt��}|j|d�~q#WWdQRXdS)Ni��r`)r:r!r7rircr"r�)rr�r�rrrr�$test_threaded_weak_valued_setdefault|s
z4MappingTestCase.test_threaded_weak_valued_setdefaultcCsgtj�}t��KxCtd�D]5}t�|d<|jdd�}|j|d�q#WWdQRXdS)Ni��r`)r:r!r7rir"rFr�)rr�r�rrrr�test_threaded_weak_valued_pop�s

z-MappingTestCase.test_threaded_weak_valued_popcCsgtj�}t��KxCtd�D]5}t�}||d<|jt|�d�d}q#WWdQRXdS)Ni@
r`r')r:r!r7rir"rGrf)rr�r�r<rrr�%test_threaded_weak_valued_consistency�s
	
z5MappingTestCase.test_threaded_weak_valued_consistencyN)-r	r
rr*rr r"r$r%r&r1r6r:r=r7rErJrLrOrPrQrSr3rUrVrYr'r`rarbrfrgrhrirjrkrprqrtryr{r|r}r~rrrrrr^sT
-r)�
mapping_testsc@sOeZdZded�ded�ded�iZejZdd�Zd	S)
�WeakValueDictionaryTestCaser[r'r]rF�key3r_cCs
|jj�S)N)�!_WeakValueDictionaryTestCase__refr()rrrr�
_reference�sz&WeakValueDictionaryTestCase._referenceN)	r	r
rrr�r:r!�	type2testr�rrrrr��s*	r�c@sOeZdZed�ded�ded�diZejZdd�Zd	S)
�WeakKeyDictionaryTestCaser[r'r]rFr�r_cCs
|jj�S)N)�_WeakKeyDictionaryTestCase__refr()rrrrr��sz$WeakKeyDictionaryTestCase._referenceN)	r	r
rrr�r:r�r�r�rrrrr��s*	r�c@sqeZdZGdd�d�Zdd�Zdd�Zdd�Zd	d
�Zedd��Z	d
d�Z
dS)�FinalizeTestCasec@seZdZdS)zFinalizeTestCase.AN)r	r
rrrrrr��sr�cCs tjjdkrtj�dS)NZcpython)�sys�implementation�namerr�)rrrr�_collect_if_necessary�sz&FinalizeTestCase._collect_if_necessaryc	s��fdd�}|j�}g�tj||dddd�}|j|jd�|j|j�||dddif�|j|�d�|j|�d�|j|�d�|j|j�d�|j|j�d�|j|jd	�|j�dg�g�tj||ddd�}|j|j�||d
if�|j|j�||dif�|j|�d�|j|�d�|j|j�d�|j|j�d�|j|jd	�|j�g�g�tj||d
ddddd�}~|j�|j|�d�|j|�d�|j|j�d�|j|j�d�|j|jd	�|j�dg�dS)Ncs!�j|||�|||S)N)re)rr�r�)�resrr�add�sz+FinalizeTestCase.test_finalize.<locals>.add�C�+r��YT��Frr�)r�r�)r�r�r�)r�r�r�)r�r:�finalizerG�alive�peek�detachr�)rr�r�rr)r�r�
test_finalize�sB(""$
zFinalizeTestCase.test_finalizec	Cs�|j�}g}tj||jd�}tj||jd�}tj||jd�}tj||jd�}tj||jd�}~~|j|j�|j|j�|j|j�|j|j��|j|j�|�|jd�|�|j|j�|jd�|�|jd�~|j�|j|j�|jd	�|�dddddddd	g}|j	||�dS)
N�f1�f2�f3�f4�f5r��Brr�)
r�r:r�rergr�r�rdr�rG)	rr�r�r�r�r�r�r�Zexpectedrrr�
test_order�s6




zFinalizeTestCase.test_ordercs�Gdd�dtj�}|j�}g��fdd�}|||�}tj|�}tj|�}~~|j|��|j|��~|j�|j|��|j|��|j�dg�dS)Nc@seZdZdS)z4FinalizeTestCase.test_all_freed.<locals>.MyFinalizerN)r	r
rrrrr�MyFinalizersr�cs�jd�dS)N�{)rer)r�rrr)sz1FinalizeTestCase.test_all_freed.<locals>.callbackr�)r:r�r�r(rVr�rDrG)rr�r�r)rZwr_callbackZwr_fr)r�r�test_all_freeds
zFinalizeTestCase.test_all_freedcsy�fdd�}tj�tdt�}tj�tdt�}tj�|�}tj�tdt�}d|_dS)Ncs+tj�td�}td�dddS)N�g1zf3 errorr'r)r:r��print)r�)�clsrr�errors
z,FinalizeTestCase.run_in_child.<locals>.errorr�r�r�F)r:r�r��_global_var�atexit)r�r�r�r�r�r�r)r�r�run_in_childs	zFinalizeTestCase.run_in_childcCsmdd}tjd|�\}}}|jd�j�}|j|ddddg�|jd	|k�dS)
Nz/from test.test_weakref import FinalizeTestCase;zFinalizeTestCase.run_in_child()z-c�asciiz	f4 foobarzf3 errorr�z	f1 foobarsZeroDivisionError)rZassert_python_ok�decode�
splitlinesrGrg)r�prog�rc�out�errrrr�test_atexit1szFinalizeTestCase.test_atexitN)r	r
rr�r�r�r�r��classmethodr�r�rrrrr��s)'r�a� Doctest for examples in the library reference: weakref.rst

>>> import weakref
>>> class Dict(dict):
...     pass
...
>>> obj = Dict(red=1, green=2, blue=3)   # this object is weak referencable
>>> r = weakref.ref(obj)
>>> print(r() is obj)
True

>>> import weakref
>>> class Object:
...     pass
...
>>> o = Object()
>>> r = weakref.ref(o)
>>> o2 = r()
>>> o is o2
True
>>> del o, o2
>>> print(r())
None

>>> import weakref
>>> class ExtendedRef(weakref.ref):
...     def __init__(self, ob, callback=None, **annotations):
...         super().__init__(ob, callback)
...         self.__counter = 0
...         for k, v in annotations.items():
...             setattr(self, k, v)
...     def __call__(self):
...         '''Return a pair containing the referent and the number of
...         times the reference has been called.
...         '''
...         ob = super().__call__()
...         if ob is not None:
...             self.__counter += 1
...             ob = (ob, self.__counter)
...         return ob
...
>>> class A:   # not in docs from here, just testing the ExtendedRef
...     pass
...
>>> a = A()
>>> r = ExtendedRef(a, foo=1, bar="baz")
>>> r.foo
1
>>> r.bar
'baz'
>>> r()[1]
1
>>> r()[1]
2
>>> r()[0] is a
True


>>> import weakref
>>> _id2obj_dict = weakref.WeakValueDictionary()
>>> def remember(obj):
...     oid = id(obj)
...     _id2obj_dict[oid] = obj
...     return oid
...
>>> def id2obj(oid):
...     return _id2obj_dict[oid]
...
>>> a = A()             # from here, just testing
>>> a_id = remember(a)
>>> id2obj(a_id) is a
True
>>> del a
>>> try:
...     id2obj(a_id)
... except KeyError:
...     print('OK')
... else:
...     print('WeakValueDictionary error')
OK

�
libreftestcCs7tjttttttt�tj	t
jt�dS)N)
rZrun_unittestr8r�rr�r�r�r�Zrun_doctestr��modulesr	rrrr�	test_main�sr��__main__)&r-r�Zunittestrbr:rvrMr(r+ZtestrZtest.supportrr�r�rrrrrr"ZTestCaser$rNr7r8r�r�rr�ZBasicTestMappingProtocolr�r�r�r�Z__test__r�r	rrrr�<module>sN	���g���=�