
    <e(                       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Zd dl	Z	d dl
Z
d dlZd dlmZ d dlmZmZ d dlmZ d dlmZ dadZ G d d          Z G d	 d
          Zd Zd Z G d d          Z G d d          Z G d dej                  Zej        d*d            Z G d de          Z G d de          Z  G d dej                  Z! G d de          Z"d dlm#Z#  G d de#j$                  Z% G d  d!e#j$                  Z& G d" d#ej                  Z' G d$ d%ej                  Z(d&Z)d'e)iZ*d( Z+e,d)k    r ej-                     dS dS )+    N)support)script_helper	ALWAYS_EQ)
gc_collect)threading_helperfoobarc                       e Zd Zd ZdS )Cc                     d S N selfs    (/usr/lib/python3.11/test/test_weakref.pymethodzC.method   s        N)__name__
__module____qualname__r   r   r   r   r
   r
      s#            r   r
   c                       e Zd ZdZd ZdS )CallableNc                     || _         d S r   barr   xs     r   __call__zCallable.__call__"   s    r   )r   r   r   r   r   r   r   r   r   r      s(        
C    r   r   c                      d } | S )Nc                      d S r   r   r   r   r   fzcreate_function.<locals>.f'         r   r   )r    s    r   create_functionr"   &   s    MMHr   c                  (    t                      j        S r   )r
   r   r   r   r   create_bound_methodr$   *   s    33:r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	Objectc                     || _         d S r   arg)r   r)   s     r   __init__zObject.__init__/   s    r   c                     d| j         z  S )Nz<Object %r>r(   r   s    r   __repr__zObject.__repr__1   s    tx''r   c                 Z    t          |t                    r| j        |j        k    S t          S r   
isinstancer&   r)   NotImplementedr   others     r   __eq__zObject.__eq__3   s)    eV$$ 	)8uy((r   c                 Z    t          |t                    r| j        |j        k     S t          S r   r.   r1   s     r   __lt__zObject.__lt__7   s)    eV$$ 	(8ei''r   c                 *    t          | j                  S r   )hashr)   r   s    r   __hash__zObject.__hash__;   s    DH~~r   c                     dS )N   r   r   s    r   some_methodzObject.some_method=       qr   c                     dS )N   r   r   s    r   other_methodzObject.other_method?   r<   r   N)
r   r   r   r*   r,   r3   r5   r8   r;   r?   r   r   r   r&   r&   .   s}          ( ( (            r   r&   c                       e Zd Zd ZdS )RefCyclec                     | | _         d S r   )cycler   s    r   r*   zRefCycle.__init__D   s    


r   Nr   r   r   r*   r   r   r   rA   rA   C   s#            r   rA   c                       e Zd Zd Zd ZdS )TestBasec                     d| _         d S Nr   cbcalledr   s    r   setUpzTestBase.setUpJ   s    r   c                 &    | xj         dz  c_         d S N   rI   )r   refs     r   callbackzTestBase.callbackM   s    r   N)r   r   r   rK   rP   r   r   r   rF   rF   H   s2              r   rF   -C6?c              #   8   K   d fd}t          j                    5  t          j        |          }|                                 	 dV  d|                                 n# d|                                 w xY w	 ddd           dS # 1 swxY w Y   dS )zR
    Ensure GC collections happen in a different thread, at a high frequency.
    Fc                  b    s+t          j                    t          j                     )d S d S r   )timesleepgccollect)periodplease_stops   r   rW   z"collect_in_thread.<locals>.collectX   sD     	JvJLLL  	 	 	 	 	r   )targetNT)r   
disable_gc	threadingThreadstartjoin)rX   rW   trY   s   `  @r   collect_in_threadra   Q   s      
 K     
 
			  G,,,					EEEKFFHHHH KFFHHHHH                 s)   *BA&B&A>>BBBc                   f   e Zd Zd Zd Zd Zej        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 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, Z0d- Z1d. Z2d/ Z3d0 Z4d1 Z5d2 Z6d3 Z7d4 Z8d5 Z9d6S )7ReferencesTestCasec                 $   |                      t                     |                      t                     |                      t                     t                      }t	          j        |          }t          |           ~t          |           d S r   )check_basic_refr
   r"   r$   weakrefrO   repr)r   owrs      r   test_basic_refz!ReferencesTestCase.test_basic_refi   st    Q_---0111 CC[^^RRr   c                      G d dt                     } |d          }t          j        |          }|                     dt	          |                     |                     dt          |                     d S )Nc                       e Zd Zd ZdS )>ReferencesTestCase.test_repr_failure_gh99184.<locals>.MyConfigc                     | |         S r   r   r   s     r   __getattr__zJReferencesTestCase.test_repr_failure_gh99184.<locals>.MyConfig.__getattr__y   s    Awr   N)r   r   r   ro   r   r   r   MyConfigrm   x   #            r   rp   r>   )offset)dictrf   rO   assertInrg   str)r   rp   objobj_weakrefs       r   test_repr_failure_gh99184z,ReferencesTestCase.test_repr_failure_gh99184w   s    	 	 	 	 	t 	 	 	 ha   k#&&j${"3"3444j#k"2"233333r   c                     |                      t                     |                      t                     |                      t                     d S r   )check_basic_callbackr
   r"   r$   r   s    r   test_basic_callbackz&ReferencesTestCase.test_basic_callback   sE    !!!$$$!!/222!!"566666r   c                 $   dd l }|j        } |            }t          j        |          }|                      |            |           ~|                      |                       |                     |           |                     |           d S rH   )	_testcapicreate_cfunctionrf   rO   assertIsassertIsNonere   rz   )r   r}   r~   r    ri   s        r   test_cfunctionz!ReferencesTestCase.test_cfunction   s    $5[^^bbddA""$$-...!!"233333r   c                 X   t                      }t          j        || j                  }t          j        || j                  }~t	                       |                      |            d           |                      |            d           |                     | j        dd           d S )Nz$expected reference to be invalidated   z-callback not called the right number of times)r
   rf   rO   rP   r   r   assertEqualrJ   r   rh   ref1ref2s       r   test_multiple_callbacksz*ReferencesTestCase.test_multiple_callbacks   s    CC{1dm,,{1dm,,$$&&"HIII$$&&"HIIID	F 	F 	F 	F 	Fr   c                     | fd}t                      }t          j        ||          | _        t          j        ||          }~d S )Nc                 .    |                                  d S r   rO   )objectr   s     r   rP   zDReferencesTestCase.test_multiple_selfref_callbacks.<locals>.callback   s    HHJJJJJr   )r
   rf   rO   )r   rP   cr   s       r   test_multiple_selfref_callbacksz2ReferencesTestCase.test_multiple_selfref_callbacks   sO     #' 	 	 	 	CC;q(++{1h''AAr   c                 r    t                      }|                     t          t          j        |d            d S )N)rP   )r
   assertRaises	TypeErrorrf   rO   )r   r   s     r   test_constructor_kwargsz*ReferencesTestCase.test_constructor_kwargs   s0    CC)W[!dCCCCCr   c                     t                      }d|_        t          j        || j                  }t          j        || j                  }~t                       d }|                     t          ||           |                     t          ||           t          j        t                                }t                       |                     t          t          |           | 	                    | j
        d           d S )NrN   c                     | j          d S r   r   )proxys    r   checkz0ReferencesTestCase.test_proxy_ref.<locals>.check   s    IIIIr   r   )r
   r   rf   r   rP   r   r   ReferenceErrorboolr   rJ   )r   rh   r   r   r   ref3s         r   test_proxy_refz!ReferencesTestCase.test_proxy_ref   s    CC}Q..}Q..	 	 	 	.%666.%666}QSS!!.$555*****r   c                      |            }t          j        |          }|                      |            d            |            }|                     ||d           d S )Nz,weak reference to live object should be livez-<ref>() should return original object if live)rf   rO   assertIsNotNoner   )r   factoryrh   rO   o2s        r   re   z"ReferencesTestCase.check_basic_ref   sw    GIIk!nnSSUUC	E 	E 	ESUUaD	F 	F 	F 	F 	Fr   c                     d| _          |            }t          j        || j                  }~t	                       |                     | j         dd           |                      |            d           d S )Nr   rN   z(callback did not properly set 'cbcalled'z3ref2 should be dead after deleting object reference)rJ   rf   rO   rP   r   r   r   )r   r   rh   rO   s       r   rz   z'ReferencesTestCase.check_basic_callback   s    GIIk!T]++?	A 	A 	A##%%J	L 	L 	L 	L 	Lr   c                 L   t                      }t          j        |          }t          j        |          }t          j        |          }|                     ||d           t                      }t          j        |          }t          j        |          }t          j        |          }|                     ||d           |                     t          j        |          dd           ~t                       |                     t          j        |          dd           d S )Nz1reference object w/out callback should be re-usedr   zwrong weak ref count for objectrN   z4wrong weak ref count for object after deleting proxy)r
   rf   rO   r   r   r   getweakrefcountr   )r   rh   r   r   r   s        r   test_ref_reusez!ReferencesTestCase.test_ref_reuse   s   CC{1~~ a  {1~~dDH	J 	J 	J CCa  {1~~{1~~dDH	J 	J 	J033Q6	8 	8 	8033QK	M 	M 	M 	M 	Mr   c                     t                      }t          j        |          }t          j        |          }t          j        |          }|                     ||d           d S )Nz4proxy object w/out callback should have been re-used)r
   rf   r   rO   r   )r   rh   proxy1rO   proxy2s        r   test_proxy_reusez#ReferencesTestCase.test_proxy_reuse   sb    CCq!!k!nnq!!ffK	M 	M 	M 	M 	Mr   c                    t                      }|                     |t          j        |                     t	          j                    }t          j        |          }|                     |d           |                    d           |                     t          |          d           | 
                    |d           ddg|d d <   |                     t          |          d           |                     t          |          d           |                     d|d           d|d<   |                     |d         d           |                     |d         d           t	          j        |          }t          j        |          }|                     ||           t	          j        t          d	                    }t          j        |          }|                     |d d          |d d                     |                     |dd          |dd                     |                     |d d         |d d                    |                     |dd         |dd                    d S )
Nz(proxy for empty UserList should be false   rN   z+proxy for non-empty UserList should be truer      z,proxy didn't support __contains__() properlyr>   
   )r
   check_proxyrf   r   collectionsUserListassertFalseappendr   len
assertTruert   range)r   rh   LpL2p2L3p3s           r   test_basic_proxyz#ReferencesTestCase.test_basic_proxy   s4   CCGM!,,--- ""M!FGGG	Q###HIII1v!!!Q###Q###aJKKK!1q!!!1q!!!!!$$]2B!%)),,]2AAA111&&&ABBABB(((BQBBQB(((AaC"QqS'*****r   c                     G d dt                     } |            }|                     dt          t          j        |                               |                     t          t          j        |                    d           d S )Nc                       e Zd Zd Zd ZdS )0ReferencesTestCase.test_proxy_unicode.<locals>.Cc                     dS )Nstringr   r   s    r   __str__z8ReferencesTestCase.test_proxy_unicode.<locals>.C.__str__      xr   c                     dS )N   bytesr   r   s    r   	__bytes__z:ReferencesTestCase.test_proxy_unicode.<locals>.C.__bytes__  r   r   N)r   r   r   r   r   r   r   r   r
   r     s2                      r   r
   r   r   )r   rt   dirrf   r   r   bytes)r   r
   instances      r   test_proxy_unicodez%ReferencesTestCase.test_proxy_unicode  s    	  	  	  	  	  	  	  	 
 133k3w}X'>'>#?#?@@@w}X6677BBBBBr   c                      G d d          } |            }t          j        |          }|                     t          j        |          d           d S )Nc                       e Zd Zd ZdS ).ReferencesTestCase.test_proxy_index.<locals>.Cc                     dS )Nr   r   r   s    r   	__index__z8ReferencesTestCase.test_proxy_index.<locals>.C.__index__"      rr   N)r   r   r   r   r   r   r   r
   r   !  #            r   r
   r   )rf   r   r   operatorindexr   r
   rh   r   s       r   test_proxy_indexz#ReferencesTestCase.test_proxy_index   sl    	 	 	 	 	 	 	 	 ACCM!**B/////r   c                      G d d          } |            }t          j        |          }|                     |dz  d           |dz  }|                     |d           d S )Nc                       e Zd Zd Zd ZdS ),ReferencesTestCase.test_proxy_div.<locals>.Cc                     dS N*   r   r1   s     r   __floordiv__z9ReferencesTestCase.test_proxy_div.<locals>.C.__floordiv__*  r   r   c                     dS )N   r   r1   s     r   __ifloordiv__z:ReferencesTestCase.test_proxy_div.<locals>.C.__ifloordiv__,  r   r   N)r   r   r   r   r   r   r   r   r
   r   )  s2              r   r
   r>   r   r   rf   r   r   r   s       r   test_proxy_divz!ReferencesTestCase.test_proxy_div(  s    	 	 	 	 	 	 	 	
 ACCM!a$$$	aBr   c                      G d d          } |            }t          j        |          }|                     |dz  d           |                     d|z  d           |dz  }|                     |d           d S )Nc                        e Zd Zd Zd Zd ZdS )/ReferencesTestCase.test_proxy_matmul.<locals>.Cc                     dS )N  r   r1   s     r   
__matmul__z:ReferencesTestCase.test_proxy_matmul.<locals>.C.__matmul__6      tr   c                     dS )N]r   r1   s     r   __rmatmul__z;ReferencesTestCase.test_proxy_matmul.<locals>.C.__rmatmul__8  r   r   c                     dS )N1  r   r1   s     r   __imatmul__z;ReferencesTestCase.test_proxy_matmul.<locals>.C.__imatmul__:  s    sr   N)r   r   r   r   r   r   r   r   r   r
   r   5  sA                r   r
   r>   r   r   r   r   r   s       r   test_proxy_matmulz$ReferencesTestCase.test_proxy_matmul4  s    	 	 	 	 	 	 	 	 ACCM!Q%%%Q%%%	QC     r   c                 D    |                      t          j                   d S r   )check_shared_without_callbackrf   rO   r   s    r    test_shared_ref_without_callbackz3ReferencesTestCase.test_shared_ref_without_callbackK  s    **7;77777r   c                 D    |                      t          j                   d S r   )r   rf   r   r   s    r   "test_shared_proxy_without_callbackz5ReferencesTestCase.test_shared_proxy_without_callbackN  s    **7=99999r   c                    t          d          } ||d           } ||d           }|                     ||d           ~~ ||          } ||d           }|                     ||d           ~~ ||          } ||          }|                     ||d           ~~ ||d           } ||          }|                     ||d           d S )NrN   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)r&   r   )r   makerefrh   p1r   s        r   r   z0ReferencesTestCase.check_shared_without_callbackQ  s    1IIWQWQb"EFFFWQZZWQb"FGGGWQZZWQZZb"EFFFWQWQZZb"FGGGGGr   c                    t                      }t          j        |          }|                     ||           |                     t          |          t          j        d            |d           |                     |j        dd            |d           |                     |j        dd           | 	                    t          |           | 	                    t          |ddd           d S )	Nzproxy is not of callable typez	twinkies!z1call through proxy not passed through to originalzSplat.)r   rN   r   r   )r   rf   r   r   r   typeCallableProxyTyper   r   r   r   )r   rh   r   s      r   test_callable_proxyz&ReferencesTestCase.test_callable_proxyc  s    JJ}QD!!!d4jj'";4	6 	6 	6[H	J 	J 	JxH	J 	J 	J 	)T*** 	)T1a33333r   c                    d|_         |                     |j         dd           d|_         |                     |j         dd           |` |                     t          |d          d           d|_         |                     |j         dd           d|_         |                     |j         dd           |` |                     t          |d          d	           d S )
NrN   z)proxy does not reflect attribute additionr   z-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   r   r   hasattr)r   rh   r   s      r   r   zReferencesTestCase.check_proxyx  s   A@	B 	B 	BAD	F 	F 	FE..?	A 	A 	A 	K	M 	M 	M	F	H 	H 	HIE**J	L 	L 	L 	L 	Lr   c                      G d d          } |            }t          j        |          }|d= |                     |j        d           d S )Nc                       e Zd ZdZd ZdS )3ReferencesTestCase.test_proxy_deletion.<locals>.FooNc                     || _         d S r   )result)r   accessors     r   __delitem__z?ReferencesTestCase.test_proxy_deletion.<locals>.Foo.__delitem__  s    &r   )r   r   r   r   r  r   r   r   Foor     s(        F' ' ' ' 'r   r  r   )rf   r   r   r   )r   r  gr    s       r   test_proxy_deletionz&ReferencesTestCase.test_proxy_deletion  sk    	' 	' 	' 	' 	' 	' 	' 	' CEEM!aD1%%%%%r   c                      G d dt                     } |            }|                     t          t          j        |                    t          |                     d S )Nc                       e Zd ZdS )0ReferencesTestCase.test_proxy_bool.<locals>.ListNr   r   r   r   r   r   Listr    s          r   r
  )listr   r   rf   r   )r   r
  lysts      r   test_proxy_boolz"ReferencesTestCase.test_proxy_bool  s[    4tvvgmD1122DJJ?????r   c                     d  G fdd          } |            t          j                  }|                     t                    5  d|v  d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Z fdZdS )1ReferencesTestCase.test_proxy_iter.<locals>.MyObjc                     t           S r   )r0   )r   rv   s    r   __iter__z:ReferencesTestCase.test_proxy_iter.<locals>.MyObj.__iter__  s    %%r   Nr   r   r   r  )rv   s   r   MyObjr    s.        & & & & & & &r   r  blech)rf   r   r   r   )r   r  r   rv   s      @r   test_proxy_iterz"ReferencesTestCase.test_proxy_iter  s     	& 	& 	& 	& 	& 	& 	& 	& 	& 	& eggM#y)) 	 	 qLL		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA!$A!c                     g dfd} |             G fdd          } |            }|                      t          |          g d           d S )N)r:   r>      c               3      K    E d {V  d S r   r   )arrs   r   iterator_funcz9ReferencesTestCase.test_proxy_next.<locals>.iterator_func  s      NNNNNNNNNr   c                       e Zd Z fdZdS ):ReferencesTestCase.test_proxy_next.<locals>.IteratesWeaklyc                 ,    t          j                  S r   rf   r   )r   its    r   r  zCReferencesTestCase.test_proxy_next.<locals>.IteratesWeakly.__iter__  s    }R(((r   Nr  )r   s   r   IteratesWeaklyr    s.        ) ) ) ) ) ) )r   r!  )r   r  )r   r  r!  weak_itr  r   s       @@r   test_proxy_nextz"ReferencesTestCase.test_proxy_next  s    ii	 	 	 	 	]__	) 	) 	) 	) 	) 	) 	) 	) 	) 	) !."" 	g			22222r   c                     d  G fdd          } |            }d}|                      t          |          5  t          |           d d d            d S # 1 swxY w Y   d S )Nc                      dS rH   r   r   r   r   <lambda>z8ReferencesTestCase.test_proxy_bad_next.<locals>.<lambda>  s    ! r   c                       e Zd Z fdZdS )1ReferencesTestCase.test_proxy_bad_next.<locals>.Ac                 ,    t          j                  S r   r  )r   not_an_iterators    r   r  z:ReferencesTestCase.test_proxy_bad_next.<locals>.A.__iter__  s    }_555r   Nr  )r*  s   r   Ar(    s.        6 6 6 6 6 6 6r   r+  z'Weakref proxy referenced a non-iterator)assertRaisesRegexr   r  )r   r+  amsgr*  s       @r   test_proxy_bad_nextz&ReferencesTestCase.test_proxy_bad_next  s     $)	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 ACC7##Is33 	 	GGG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AAAc           	           G d d          } |            }|                      d                    t          t          j        |                              d           d S )Nc                       e Zd Zd Zd ZdS )5ReferencesTestCase.test_proxy_reversed.<locals>.MyObjc                     dS )Nr   r   r   s    r   __len__z=ReferencesTestCase.test_proxy_reversed.<locals>.MyObj.__len__      qr   c                      t          d          S )Ncba)iterr   s    r   __reversed__zBReferencesTestCase.test_proxy_reversed.<locals>.MyObj.__reversed__  s    E{{"r   N)r   r   r   r4  r9  r   r   r   r  r2    s2          # # # # #r   r   r7  )r   r_   reversedrf   r   r   r  rv   s      r   test_proxy_reversedz&ReferencesTestCase.test_proxy_reversed  sq    	# 	# 	# 	# 	# 	# 	# 	# egg'-*<*<!=!=>>FFFFFr   c                     G d d          } |            }|                      t                    5  t          t          j        |                     d d d            n# 1 swxY w Y    G d d          } |            }|                      t                    5  t          t          j        |                     d d d            d S # 1 swxY w Y   d S )Nc                       e Zd Zd ZdS )1ReferencesTestCase.test_proxy_hash.<locals>.MyObjc                     dS r   r   r   s    r   r8   z:ReferencesTestCase.test_proxy_hash.<locals>.MyObj.__hash__  r   r   Nr   r   r   r8   r   r   r   r  r@    r   r   r  c                       e Zd ZdZdS )r@  NrB  r   r   r   r  z1ReferencesTestCase.test_proxy_hash.<locals>.MyObj  s        HHHr   )r   r   r7   rf   r   r<  s      r   test_proxy_hashz"ReferencesTestCase.test_proxy_hash  s}   	 	 	 	 	 	 	 	 eggy)) 	% 	%s##$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%	 	 	 	 	 	 	 	 eggy)) 	% 	%s##$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%s#   "A  A$'A$"CCCc                 F   t                      }t          j        |          }t          j        || j                  }|                     t          j        |          dd           t          j        |          }t          j        || j                  }|                     t          j        |          dd           ~~~~t                       |                     t          j        |          dd           |                     t          j        d          dd           d S )Nr   z*got wrong number of weak reference objectsr:   r   zAweak reference objects not unlinked from referent when discarded.rN   z2got wrong number of weak reference objects for int)r
   rf   rO   rP   r   r   r   r   )r   rh   r   r   r   r   s         r   test_getweakrefcountz'ReferencesTestCase.test_getweakrefcount  s$   CC{1~~{1dm,,033QA	C 	C 	C q!!q$-00033QA	C 	C 	C $033Q1	2 	2 	2
 	033QI	K 	K 	K 	K 	Kr   c                    t                      }t          j        || j                  }t          j        || j                  }~t	                       |                     t          j        |          |gd           t                      }t          j        || j                  }t          j        || j                  }~t	                       |                     t          j        |          |gd           ~t	                       |                     t          j        |          g d           |                     t          j        d          g d           d S )Nzlist of refs does not matchzlist of refs not clearedrN   z#list of refs does not match for int)r
   rf   rO   rP   r   r   getweakrefsr   s       r   test_getweakrefsz#ReferencesTestCase.test_getweakrefs   s@   CC{1dm,,{1dm,,,Q//$2	4 	4 	4 CC{1dm,,{1dm,,,Q//$2	4 	4 	4 ,Q///	1 	1 	1 	,Q//:	< 	< 	< 	< 	<r   c                      G d dt                     } |d          }t          j        |          }|                     |dz   d           |                     d|z   d           d S )Nc                       e Zd ZdS )6ReferencesTestCase.test_newstyle_number_ops.<locals>.FNr	  r   r   r   FrL            Dr   rM  g       @g      ?g      @)floatrf   r   r   )r   rM  r    r   s       r   test_newstyle_number_opsz+ReferencesTestCase.test_newstyle_number_ops  s    	 	 	 	 	 	 	 	AcFFM!S#&&&q#&&&&&r   c                      G d dt                     i fdfd}	  |             |                     d           n# $ r Y nw xY w	  |             |                     d           d S # $ r Y d S w xY w)Nc                       e Zd ZdS )?ReferencesTestCase.test_callbacks_protected.<locals>.BogusErrorNr	  r   r   r   
BogusErrorrS  %  rN  r   rT  c                     | = d S r   r   )kdatas    r   removez;ReferencesTestCase.test_callbacks_protected.<locals>.remove(  s    Qr   c                  >    d } d t          j        |           <   )Nc                      dS )Nr   r   r   r   r   r&  zRReferencesTestCase.test_callbacks_protected.<locals>.encapsulate.<locals>.<lambda>+  s     r   )rf   rO   )r    rT  rW  rX  s    r   encapsulatez@ReferencesTestCase.test_callbacks_protected.<locals>.encapsulate*  s&    A+/DQ''(r   zexception not properly restored)	Exceptionfail)r   r[  rT  rW  rX  s     @@@r   test_callbacks_protectedz+ReferencesTestCase.test_callbacks_protected"  s	   	 	 	 	 	 	 	 		 	 	 	 		 	 	 	 	 	 		9KMMM II78888  	 	 	D		9KMMM II788888  	 	 	DD	s#   
A AA
A3 3A<;A<c                    dd l  G d dt                    } |            }t          j        |fd          }~~ |            } |            |_        t          j        |j        fd          } |            }||_        ~~d S )Nr   c                       e Zd ZdS )0ReferencesTestCase.test_sf_bug_840829.<locals>.CNr	  r   r   r   r
   ra  H  rN  r   r
   c                 "     j                     S r   rW   ignorerV   s    r   r&  z7ReferencesTestCase.test_sf_bug_840829.<locals>.<lambda>L  s    :2:<< r   c                 "     j                     S r   rc  rd  s    r   r&  z7ReferencesTestCase.test_sf_bug_840829.<locals>.<lambda>T  s    jbjll r   )rV   r   rf   rO   ic1)r   r
   r   ri   rh  c2rV   s         @r   test_sf_bug_840829z%ReferencesTestCase.test_sf_bug_840829;  s     					 	 	 	 	 	 	 	 ACC[777788 QSSqss[::::;;QSS BBr   c                     dd l } G d dt                    } G d dt                    } |            }||_        t          j        ||j                  |_        ~~~ |j                     d S )Nr   c                       e Zd ZdS )4ReferencesTestCase.test_callback_in_cycle.<locals>.JNr	  r   r   r   Jrm  f  rN  r   rn  c                       e Zd Zd ZdS )5ReferencesTestCase.test_callback_in_cycle.<locals>.IIc                     | j          d S r   )rn  r   re  s     r   	acallbackz?ReferencesTestCase.test_callback_in_cycle.<locals>.II.acallbackj  s    r   N)r   r   r   rs  r   r   r   IIrp  i  s#            r   rt  )rV   r   rn  rf   rO   rs  ri   rW   )r   rV   rn  rt  Is        r   test_callback_in_cyclez)ReferencesTestCase.test_callback_in_cyclec  s    				 	 	 	 	 	 	 		 	 	 	 	 	 	 	 BDD{1ak**2 q"
r   c                     dd l } G d d          } |             |            }}||_        ||_        t          j        ||j                  |_        ~~ |j                     d S )Nr   c                       e Zd Zd ZdS )=ReferencesTestCase.test_callback_reachable_one_way.<locals>.Cc                 0    | j          | j         | j         d S r   merh  ri   rr  s     r   cbz@ReferencesTestCase.test_callback_reachable_one_way.<locals>.C.cb      r   Nr   r   r   r}  r   r   r   r
   ry    #            r   r
   )rV   r|  rh  rf   rO   r}  ri   rW   )r   rV   r
   rh  ri  s        r   test_callback_reachable_one_wayz2ReferencesTestCase.test_callback_reachable_one_way  s    				 	 	 	 	 	 	 	 aaccBB&&
r   c                     dd l } G d dt                    } G d d          } |             |            }}||_        ||_        t	          j        ||j                  |_        ~~~~ |j                     d S )Nr   c                       e Zd Zd ZdS )=ReferencesTestCase.test_callback_different_classes.<locals>.Cc                 0    | j          | j         | j         d S r   r{  rr  s     r   r}  z@ReferencesTestCase.test_callback_different_classes.<locals>.C.cb  r~  r   Nr  r   r   r   r
   r    r  r   r
   c                       e Zd ZdS )=ReferencesTestCase.test_callback_different_classes.<locals>.DNr	  r   r   r   Dr    rN  r   r  )	rV   r   r|  rh  rf   rO   r}  ri   rW   )r   rV   r
   r  rh  ri  s         r   test_callback_different_classesz2ReferencesTestCase.test_callback_different_classes  s    				 	 	 	 	 	 	 		 	 	 	 	 	 	 	 aaccBB&&Aq
r   c                 D   dd l }g  G fddt                    } |d           |d          }}||_        ||_        t          j        ||j                  |_        t          j        ||j                  |_        fd}t          j        ||          }~~~|                     g             |j                     |                     dg           |                      |            d            d d =  |j                     |                     g            d S )Nr   c                        e Zd Zd Z fdZdS )AReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.Cc                     || _         d S r   )	attribute)r   values     r   r*   zJReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.__init__  s    !&r   c                 <                         | j                   d S r   )r   r   r   re  alists     r   rs  zKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C.acallback  s    TV$$$$$r   N)r   r   r   r*   rs  r  s   r   r
   r    s=        ' ' '% % % % % % %r   r
   rN   r   c                 2                         d           d S )NC went awayr   re  r  s    r   C_went_awayzKReferencesTestCase.test_callback_in_cycle_resurrection.<locals>.C_went_away  s    LL'''''r   r  )	rV   r   r   rf   rO   rs  ri   r   rW   )r   rV   r
   rh  ri  r  ri   r  s          @r   #test_callback_in_cycle_resurrectionz6ReferencesTestCase.test_callback_in_cycle_resurrection  sX   			 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 1qqttBB--B--	( 	( 	( 	( 	([K((A###

 	000t$$$!!!H
#####r   c                    dd l }g fd} G fddt                    } |             |            }}||_        ||_        |j        }t	          j        ||          |_        t	          j        ||j                  |_        t	          j        ||          }|                      |            |           ~~~~|                     g             |j	                     |                     dg           |                      |            d            d d =  |j	                     |                     g            d S )Nr   c                 2                         d           d S )Nsafe_callback calledr  r  s    r   safe_callbackzDReferencesTestCase.test_callbacks_on_callback.<locals>.safe_callback  s    LL/00000r   c                       e Zd Z fdZdS )8ReferencesTestCase.test_callbacks_on_callback.<locals>.Cc                 2                         d           d S )Nz	cb calledr  r  s     r   r}  z;ReferencesTestCase.test_callbacks_on_callback.<locals>.C.cb  s    [)))))r   Nr  r  s   r   r
   r    s.        * * * * * * *r   r
   r  )
rV   r   r2   r}  rf   rO   ri   r   r   rW   )	r   rV   r  r
   r   drP   external_wrr  s	           @r   test_callbacks_on_callbackz-ReferencesTestCase.test_callbacks_on_callback  sw   			 	1 	1 	1 	1 	1	* 	* 	* 	* 	* 	* 	* 	* 	* 	* qssAACC14{1h''{8QT**k(M::kkmmX... aA###
!7 8999---!!!H
#####r   c                 D    |                      t          j                   d S r   )check_gc_during_creationrf   rO   r   s    r   test_gc_during_ref_creationz.ReferencesTestCase.test_gc_during_ref_creation  s    %%gk22222r   c                 D    |                      t          j                   d S r   )r  rf   r   r   s    r   test_gc_during_proxy_creationz0ReferencesTestCase.test_gc_during_proxy_creation  s    %%gm44444r   c                 v   t          j                    }t          j        ddd           t          j                      G d d          }d } |            } |            }||_         ||          |_        	  |            }t          j        ||           t          j        |  d S # t          j        |  w xY w)NrN   c                       e Zd ZdS )6ReferencesTestCase.check_gc_during_creation.<locals>.ANr	  r   r   r   r+  r    rN  r   r+  c                      d S r   r   )argss    r   rP   z=ReferencesTestCase.check_gc_during_creation.<locals>.callback       Dr   )rV   get_thresholdset_thresholdrW   r-  ri   rf   rO   )r   r   
thresholdsr+  rP   
referencedr-  s          r   r  z+ReferencesTestCase.check_gc_during_creation  s    %''

Aq!!!

	 	 	 	 	 	 	 		 	 	 QSS
ACCwz""	* AK
H--- j))))Bj)))s   9B( (B8c                 @     G d dt                     } |            }d S )Nc                       e Zd Zd ZdS )>ReferencesTestCase.test_ref_created_during_del.<locals>.Targetc                 .    t          j        |           ad S r   )rf   rO   ref_from_delr   s    r   __del__zFReferencesTestCase.test_ref_created_during_del.<locals>.Target.__del__8  s    &{400r   Nr   r   r   r  r   r   r   Targetr  7  s#        1 1 1 1 1r   r  )r   )r   r  ws      r   test_ref_created_during_delz.ReferencesTestCase.test_ref_created_during_del2  s=    
	1 	1 	1 	1 	1V 	1 	1 	1
 FHHr   c           	          t          j        t                    }|                     t          |j        ddddd           t          j                     d S rH   )rf   rO   r\  r   r   r*   rV   rW   )r   rs     r   	test_initzReferencesTestCase.test_init>  sD     K	"")QZAq!Q???

r   c                 *    G d dt                     }g }t          j        t                     t          j        ||j                  }d }t          j                     |                      |            d            |                     ||g           d S )Nc                       e Zd ZdS )*ReferencesTestCase.test_classes.<locals>.ANr	  r   r   r   r+  r  H  rN  r   r+  )r   rf   rO   intr   rV   rW   r   )r   r+  lr-  s       r   test_classeszReferencesTestCase.test_classesF  s    	 	 	 	 	 	 	 	CK18$$

d###QC     r   c                    t          d          }t          d          }t          d          }t          j        |          }t          j        |          }t          j        |          }t          j        |          }|                     ||k               |                     ||k               |                     ||k               |                     ||k               |                     ||k               |                     ||k               |                     ||k               |                     ||k               |                     |t
          k               |                     |t
          k               ~~~t          j                     |||fD ] }|                      |            d            !|                     ||k               |                     ||k               |                     ||k               |                     ||k               | 	                    ||k    ||u            | 	                    ||k    ||u           d S )NrN   r   )
r&   rf   rO   r   r   r   rV   rW   r   r   )	r   r   yzr-  br   r  r  s	            r   test_equalityz ReferencesTestCase.test_equalityR  s#   1II1II1IIKNNKNNKNNKNN 	Qa   a   QQa   a   QY'''i(((q!

Aq 	% 	%AMM!!##t$$$$
 	a   Qa   Qaa(((a!,,,,,r   c                    t           j        t           j        t           j        t           j        g}t          d          }t          d          }t          j        |          }t          j        |          }|D ]}|                     t          |||            ~~t          j                     |D ]}|                     t          |||            d S rM   )r   ltgtleger&   rf   rO   r   r   rV   rW   )r   opsr   r  r-  r  ops          r   test_orderingz ReferencesTestCase.test_orderingw  s    {HKhkB1II1IIKNNKNN 	3 	3BiQ2222q

 	3 	3BiQ2222	3 	3r   c                    t          d          }t          d          }t          j        |          }t          j        |          }|                     t	          |          t	          d                     ~~t          j                     |                     t	          |          t	          d                     |                     t          t          |           d S r   )	r&   rf   rO   r   r7   rV   rW   r   r   )r   r   r  r-  r  s        r   test_hashingzReferencesTestCase.test_hashing  s    2JJ2JJKNNKNNa$r((+++q

 	a$r((+++)T1-----r   c                      G d d          }t          j                    } |d           x}}t          d          D ]} ||          x||<   }~t          j                     d S )Nc                       e Zd Zd ZdS )1ReferencesTestCase.test_trashcan_16602.<locals>.Cc                 v    |sd S t          j        |           fd}t          j        ||          | _        d S )Nc                                  }d S r   r   )wparentrh   wselfs     r   r}  zFReferencesTestCase.test_trashcan_16602.<locals>.C.__init__.<locals>.cb  s    AAAr   )rf   rO   r  )r   parentr}  r  s      @r   r*   z:ReferencesTestCase.test_trashcan_16602.<locals>.C.__init__  sO     FD))         &{6266r   NrD   r   r   r   r
   r    s#        7 7 7 7 7r   r
   d   )rf   WeakKeyDictionaryr   rV   rW   )r   r
   r  rootr   ns         r   test_trashcan_16602z&ReferencesTestCase.test_trashcan_16602  s    
	7 	7 	7 	7 	7 	7 	7 	7 %''1T77qs 	 	AqttOAaD11

r   c                     t          d          }d }t          j        ||          }|                     |j        |           t          j        |          }|                     |j                   d S )NrN   c                     d S r   r   r   s    r   r&  z<ReferencesTestCase.test_callback_attribute.<locals>.<lambda>      t r   )r&   rf   rO   r   __callback__r   )r   r   rP   r   r   s        r   test_callback_attributez*ReferencesTestCase.test_callback_attribute  sg    1II##{1h''d'222{1~~$+,,,,,r   c                     t          d          }t          j        || j                  }|                     |j                   ~t          j                     |                     |j                   d S rM   )	r&   rf   rO   rP   r   r  r   r   r   )r   r   rO   s      r   &test_callback_attribute_after_deletionz9ReferencesTestCase.test_callback_attribute_after_deletion  sf    1IIk!T]++S-...#*+++++r   c                     t          d          }d }t          j        ||          }|                     t                    5  d |_        d d d            d S # 1 swxY w Y   d S )NrN   c                     d S r   r   r   s    r   r&  z@ReferencesTestCase.test_set_callback_attribute.<locals>.<lambda>  r  r   c                     d S r   r   r   s    r   r&  z@ReferencesTestCase.test_set_callback_attribute.<locals>.<lambda>  s    D r   )r&   rf   rO   r   AttributeErrorr  )r   r   rP   r   s       r   test_set_callback_attributez.ReferencesTestCase.test_set_callback_attribute  s    1II##{1h''~.. 	1 	1 0 0D	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1s   	AAAc                      G d dt                     } |d          }t          j        |d           }~t          j                     d S )Nc                       e Zd Zd ZdS );ReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDelc                     d S r   r   r   s    r   r  zCReferencesTestCase.test_callback_gcs.<locals>.ObjectWithDel.__del__  r!   r   Nr  r   r   r   ObjectWithDelr    s        #####r   r  rN   c                 (    t          j                    S r   )r   r   r   s    r   r&  z6ReferencesTestCase.test_callback_gcs.<locals>.<lambda>  s    '*<*>*> r   )r&   rf   rO   r   r   )r   r  r   r   s       r   test_callback_gcsz$ReferencesTestCase.test_callback_gcs  sh    	$ 	$ 	$ 	$ 	$F 	$ 	$ 	$M!{1>>??r   N):r   r   r   rj   rx   r{   r   cpython_onlyr   r   r   r   r   re   rz   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r#  r/  r=  rD  rF  rI  rP  r^  rj  rv  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   rc   rc   g   sh         	4 	4 	47 7 7
 	4 	4 	4	F 	F 	F  $D D D+ + +$F F F	L 	L 	LM M M.M M M+ + +8	C 	C 	C0 0 0
  
  
 ! ! !.8 8 8: : :H H H$4 4 4*L L L*	& 	& 	&@ @ @  (3 3 3  G G G% % % K K K,< < <4' ' '9 9 92& & &P& & &P  0  8,$ ,$ ,$\$$ $$ $$L3 3 35 5 5* * *2
 
 
  
! 
! 
!#- #- #-J3 3 3. . .  *- - -, , ,1 1 1    r   rc   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )SubclassableWeakrefTestCasec                     G d dt           j                  }t          d          } ||d          }|                      |            |           |                     |j                   |                     |j        d           ~t                       | 	                     |                       |                     |j                   d S )Nc                   *     e Zd Zd fd	Z fdZ xZS )=SubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRefNr   c                 Z    || _         t                                          ||           d S r   )r  superr*   )r   obrP   r  	__class__s       r   r*   zFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__init__  s*    "
  X.....r   c                 R    d| _         t                                                      S NT)calledr  r   )r   r  s    r   r   zFSubclassableWeakrefTestCase.test_subclass_refs.<locals>.MyRef.__call__  s     "ww'')))r   r   )r   r   r   r*   r   __classcell__)r  s   @r   MyRefr    sV        / / / / / /* * * * * * * * *r   r  r      r  )
rf   rO   r&   r   r   r  r   r  r   r   )r   r  rh   mrs       r   test_subclass_refsz.SubclassableWeakrefTestCase.test_subclass_refs  s    	* 	* 	* 	* 	*GK 	* 	* 	* 5MMU1BbbddA	"""2&&&""$$	"""""r   c                     G d dt           j                  }t          d          } ||          }t          j        |          }|                     ||           |                     t          j        |          ||g           |                     t          j        |          d            ||          }|                     t          j        |          d           t          j        |          }|                     t          |          d           |                     ||d                    | 	                    ||dd                     | 	                    ||dd                     d S )Nc                       e Zd ZdS )XSubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refs.<locals>.MyRefNr	  r   r   r   r  r
    rN  r   r  r   r   r   r   rN   )
rf   rO   r&   assertIsNotr   rH  r   r   r   rt   )r   r  rh   r1r2r3refss          r   -test_subclass_refs_dont_replace_standard_refszISubclassableWeakrefTestCase.test_subclass_refs_dont_replace_standard_refs  s_   	 	 	 	 	GK 	 	 	2JJU1XX[^^R   ,Q//"b:::033Q777U1XX033Q777"1%%TA&&&b$q'"""b$qrr(###b$qrr(#####r   c                 D    G d dt           j                  }t          d          } ||t                    } ||t                    }|                     ||           t          j        |          }|                     ||           |                     ||           d S )Nc                       e Zd ZdS )USubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbacks.<locals>.MyRefNr	  r   r   r   r  r    rN  r   r  r   )rf   rO   r&   idru   r  rH  rt   )r   r  rh   r  r  r  s         r   *test_subclass_refs_dont_conflate_callbackszFSubclassableWeakrefTestCase.test_subclass_refs_dont_conflate_callbacks  s    	 	 	 	 	GK 	 	 	2JJU1b\\U1c]]R   "1%%b$b$r   c                 r    G d dt           j                  }t          d          } ||d dd          }|                     |j        d           |                     |j        d           |                     |                                d           |                     t          |d                     d S )Nc                   $    e Zd ZdZd Zd Zd ZdS )HSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRefslot1slot2c                 D    t           j                            | ||          S r   )rf   rO   __new__)r   r  rP   r  r  s        r   r  zPSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__new__  s    {**4X>>>r   c                 "    || _         || _        d S r   r  )r   r  rP   r  r  s        r   r*   zQSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.__init__   s    "
"


r   c                      | j         | j        z   S r   r  r   s    r   methzMSubclassableWeakrefTestCase.test_subclass_refs_with_slots.<locals>.MyRef.meth  s    zDJ..r   N)r   r   r   	__slots__r  r*   r   r   r   r   r  r    sF        (I? ? ?# # #/ / / / /r   r  r   abcdefabcdef__dict__)	rf   rO   r&   r   r  r  r   r   r   )r   r  rh   r  s       r   test_subclass_refs_with_slotsz9SubclassableWeakrefTestCase.test_subclass_refs_with_slots  s    	/ 	/ 	/ 	/ 	/GK 	/ 	/ 	/ 2JJE!T5%((%(((%(((8,,,J//00000r   c                 b     G d dt           j                  } fd}t                      } |||          }||_        ~~                      j        d           t                      } |||          } |||          }||_        ||_        ~~~                      j        d           dS )z3Confirm https://bugs.python.org/issue3100 is fixed.c                       e Zd ZdS )HSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.MyRefNr	  r   r   r   r  r)    rN  r   r  c                 (    xj         dz  c_         d S rM   rI   )r  r   s    r   rP   zKSubclassableWeakrefTestCase.test_subclass_refs_with_cycle.<locals>.callback  s    MMQMMMMr   r   N)rf   rO   r
   rh   r   rJ   r  )r   r  rP   rh   r  r  s   `     r   test_subclass_refs_with_cyclez9SubclassableWeakrefTestCase.test_subclass_refs_with_cycle  s    	 	 	 	 	GK 	 	 	
	 	 	 	 	 CCU1h*** CCU1hU1h*****r   N)r   r   r   r  r  r  r&  r+  r   r   r   r  r    s_        # # #$$ $ $"	  	  	 1 1 1"$+ $+ $+ $+ $+r   r  c                   ^    e Zd Zd Zd Zd Zd Zd Zd Ze	j
        d             Zd Zd	 Zd
S )WeakMethodTestCasec                 ,     G d dt                     }|S )z3Return an Object subclass overriding `some_method`.c                       e Zd Zd ZdS )'WeakMethodTestCase._subclass.<locals>.Cc                     dS )Nr  r   r   s    r   r;   z3WeakMethodTestCase._subclass.<locals>.C.some_method8  r5  r   N)r   r   r   r;   r   r   r   r
   r0  7  s#            r   r
   )r&   )r   r
   s     r   	_subclasszWeakMethodTestCase._subclass5  s3    	 	 	 	 	 	 	 	 r   c                    t          d          }t          j        |j                  }|                     |t          j                   |                      |            t          |j                             |                      |            j        |           |                      |            j	        |j        j	                   | 
                      |                        d           d S )NrN   r:   )r&   rf   
WeakMethodr;   assertIsInstanceReferenceTyper   r   __self____func__r   r   rh   r  s      r   
test_alivezWeakMethodTestCase.test_alive<  s    1IIq}--a!6777aacc4#6#6777aacclA&&&aacclAM$:;;;"""""r   c                     t          d          }t          j        |j                  }~t	          j                     |                      |            d            d S rM   )r&   rf   r4  r;   rV   rW   r   r9  s      r   test_object_deadz#WeakMethodTestCase.test_object_deadE  sM    1IIq}--

aacc4     r   c                     |                                  } |d          }t          j        |j                  }|`t	          j                     |                      |            d            d S rM   )r2  rf   r4  r;   rV   rW   r   )r   r
   rh   r  s       r   test_method_deadz#WeakMethodTestCase.test_method_deadL  s`    NNAaDDq}--M

aacc4     r   c                 T   |                                  }g fd} |d          }t          j        |j        |          }~t	          j                     |                     |g           t          j        |_        t	          j                     |                     |g           d S )Nc                 2                         |            d S r   r  r)   callss    r   r}  z=WeakMethodTestCase.test_callback_when_object_dead.<locals>.cbX      LLr   rN   )r2  rf   r4  r;   rV   rW   r   r&   r   r
   r}  rh   r  rB  s        @r   test_callback_when_object_deadz1WeakMethodTestCase.test_callback_when_object_deadT  s    NN	 	 	 	 	AaDDq}b11

$$$*

$$$$$r   c                 6   |                                  }g fd} |d          }t          j        |j        |          }|`t	          j                     |                     |g           ~t	          j                     |                     |g           d S )Nc                 2                         |            d S r   r  rA  s    r   r}  z=WeakMethodTestCase.test_callback_when_method_dead.<locals>.cbh  rC  r   rN   )r2  rf   r4  r;   rV   rW   r   rD  s        @r   test_callback_when_method_deadz1WeakMethodTestCase.test_callback_when_method_deadd  s    NN	 	 	 	 	AaDDq}b11M

$$$

$$$$$r   c                     t          d          }d }t          j        |j        |          }t          j        |          }~|                      |            d            d S )NrN   c                     d S r   r   )_s    r   r}  z-WeakMethodTestCase.test_no_cycles.<locals>.cbx  r  r   )r&   rf   r4  r;   rO   r   )r   rh   r}  r  ri   s        r   test_no_cyclesz!WeakMethodTestCase.test_no_cyclest  sb     1II	 	 	q}b11[^^bbddD!!!!!r   c                      fd} fd}t          d          }t          d          }t          j        |j                  }t          j        |j                  }t          j        |j                  }t          j        |j                  } |||            |||            |||            |||            |||            |||           t          d          }	t          j        |	j                  }
t          j        |	j                  } |||
            |||            |||
            |||            |||j                    ||t
                     ~~~	t          j                     |||||
|f}|D ]?}|D ]:}                     ||k    ||u                                 ||k    ||u           ;@d S )Nc                 l                         | |k                                   | |k               d S r   r   r   r-  r  r   s     r   _eqz-WeakMethodTestCase.test_equality.<locals>._eq  7    OOAF###Q!V$$$$$r   c                 l                         | |k                                   | |k               d S r   rO  rP  s     r   _nez-WeakMethodTestCase.test_equality.<locals>._ne  rR  r   rN   r   )	r&   rf   r4  r;   r?   r   rV   rW   r   )r   rQ  rT  r   r  r-  r  r   r  r  er    r  qr  s   `              r   r  z WeakMethodTestCase.test_equality  s   	% 	% 	% 	% 	%	% 	% 	% 	% 	% 1II1IIq}--q}--q~..q~..Aq			Aq			Aq			Aq			Aq			Aq			1IIq}--q~..Aq			Aq			Aq			Aq			Aq}Ayq!

!Q1a 	5 	5A 5 5  aa000  a!44445	5 	5r   c                 N   t          d          }t          d          }t          j        |j                  }t          j        |j                  }t          j        |j                  }|                     t          |          t          |                     t          |          }~~t          j                     |                     t          |          |           |                     t          |          |           | 	                    t          t          |           d S rM   )r&   rf   r4  r;   r?   r   r7   rV   rW   r   r   )r   r   r  r-  r  r   has          r   r  zWeakMethodTestCase.test_hashing  s     1II1IIq}--q}--q~..a$q''***!WWq

a"%%%a"%%%)T1-----r   N)r   r   r   r2  r:  r<  r>  rE  rH  r   r  rL  r  r  r   r   r   r-  r-  3  s          # # #! ! !! ! !% % % % % %  " " "'5 '5 '5R. . . . .r   r-  c                   x   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 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+ e,j-                    d*             Z. e,j-                    d+             Z/ e,j-                    d,             Z0d- Z1 e,j-                    d.             Z2 e,j-                    d/             Z3 e,j-                    d0             Z4 e,j-                    d1             Z5e6j7        d2             Z8d3S )4MappingTestCaser   c                    d}d t          |          D             } |fd|D                       }|                                }	 t          |           n# t          $ r Y nw xY w~t	          j                     t          |          }~t	          j                     t          |          }|                     |d           |                     |d           d S )N   c                 *    g | ]}t                      S r   rA   .0rg  s     r   
<listcomp>z4MappingTestCase.check_len_cycles.<locals>.<listcomp>  s    ......r   c              3   .   K   | ]} |          V  d S r   r   r`  rh   conss     r   	<genexpr>z3MappingTestCase.check_len_cycles.<locals>.<genexpr>  s+      //AQ//////r   )r   rN   r   )	r   itemsnextStopIterationrV   rW   r   rt   r   )	r   	dict_typerd  Nrf  dctr   n1n2s	     `      r   check_len_cyclesz MappingTestCase.check_len_cycles  s    ..U1XX...i/////////YY[[	HHHH 	 	 	D	

XX

XXb&!!!Qs   	A 
A&%A&c                 H    |                      t          j        d            d S )Nc                 
    | dfS rM   r   rV  s    r   r&  z<MappingTestCase.test_weak_keyed_len_cycles.<locals>.<lambda>  
    Aq6 r   )rn  rf   r  r   s    r   test_weak_keyed_len_cyclesz*MappingTestCase.test_weak_keyed_len_cycles  s%    g79I9IJJJJJr   c                 H    |                      t          j        d            d S )Nc                 
    d| fS rM   r   rq  s    r   r&  z=MappingTestCase.test_weak_valued_len_cycles.<locals>.<lambda>  s
    aV r   )rn  rf   WeakValueDictionaryr   s    r   test_weak_valued_len_cyclesz+MappingTestCase.test_weak_valued_len_cycles  s%    g9;K;KLLLLLr   c                     | j         t          j        gt          j                    R   t	          dd          D ]}d}t          j        d           t          j        |||           d t	          |          D             } |fd|D                       }~|                                }	 t          |           n# t          $ r Y nw xY wt          |          }~t          |          }	| 
                    |d           |                     ||           | 
                    |	d           |                     |	|           d S )NrN   r  r\  r   c                 *    g | ]}t                      S r   r^  r_  s     r   ra  z2MappingTestCase.check_len_race.<locals>.<listcomp>  s    222AXZZ222r   c              3   .   K   | ]} |          V  d S r   r   rc  s     r   re  z1MappingTestCase.check_len_race.<locals>.<genexpr>  s+      33DDGG333333r   )
addCleanuprV   r  r  r   rW   rf  rg  rh  r   assertGreaterEqualassertLessEqual)
r   ri  rd  thrj  rf  rk  r   rl  rm  s
     `       r   check_len_racezMappingTestCase.check_len_race  sd   (>2+;+=+=>>>>3-- 	) 	)BAJqMMMRR(((22q222E)3333U33333CBR    SBSB##B***  Q'''##B***  R(((('	) 	)s   0C  
CCc                 H    |                      t          j        d            d S )Nc                 
    | dfS rM   r   rq  s    r   r&  z:MappingTestCase.test_weak_keyed_len_race.<locals>.<lambda>  s
    !Q r   )r  rf   r  r   s    r   test_weak_keyed_len_racez(MappingTestCase.test_weak_keyed_len_race  s%    G57G7GHHHHHr   c                 H    |                      t          j        d            d S )Nc                 
    d| fS rM   r   rq  s    r   r&  z;MappingTestCase.test_weak_valued_len_race.<locals>.<lambda>  rr  r   )r  rf   rv  r   s    r   test_weak_valued_len_racez)MappingTestCase.test_weak_valued_len_race  s%    G79I9IJJJJJr   c                    |                                  \  }}|D ]L}|                     t          j        |          d           |                     |||j                 d           Mt          |                                          }t          |                                                                          }|	                                 |	                                 |                     ||d           ~~|                     t          |          | j                   |d= t                       |                     t          |          | j        dz
  d           ~~t                       |                     t          |          dd           t          j                    }|                     t          |j        d           t#                      |d<   t                       |                     t          |j        d           d S )NrN   #wrong object returned by weak dict!z/cloning of weak-valued dictionary did not work!r   /deleting object did not cause dictionary updatez0deleting the values did not clear the dictionaryr   )make_weak_valued_dictr   rf   r   r   r)   r  rf  copysortr   COUNTr   rv  r   KeyError__getitem__r
   r   rs   objectsrh   items1items2s         r   test_weak_valuesz MappingTestCase.test_weak_values  s    2244g 	@ 	@AW4Q77;;;MM!T!%[>@ @ @ @djjll##diikk''))**F	H 	H 	HFTDJ///AJTDJNF	H 	H 	HQTAG	I 	I 	I *,,(D$4a888##Q(D$4a88888r   c                 f   |                                  \  }}|D ]P}|                     t          j        |          dd|z             |                     |j        ||         d           Q|                                }|                                                                }|                     t          |          t          |          d           ~~|                     t          |          | j
                   |d= t                       |                     t          |          | j
        dz
  d           ~~t                       |                     t          |          dd           t          d          }d	||<   |                     ||           |                     d
|           d S )NrN   z&wrong number of weak references to %r!r  z.cloning of weak-keyed dictionary did not work!r   r  z.deleting the keys did not clear the dictionaryr   z$What is the meaning of the universe?"   )make_weak_keyed_dictr   rf   r   r   r)   rf  r  setr   r  r   r&   rt   assertNotInr  s         r   test_weak_keyszMappingTestCase.test_weak_keys  s   
 1133g 	@ 	@AW4Q77AAEG G GMM!%a>@ @ @ @""$$Vc&kkE	G 	G 	GFTDJ///AJTTZ!^F	H 	H 	HQTAE	G 	G 	G2JJ8QaT"""""r   c                 4   |                                  \  }}|                     |           |                                }|                     t	          |          t	          |                     t          |          }|D ]n} |            }|                     ||           |                     ||           |                     |j        ||                    |                    |           o|                     t	          |          d           t          |          }|                     t	          t          |                                                    t	          |                     |                                D ]n} |            }|                     ||           |                     ||           |                     |j        ||                    |                    |           o|                     t	          |          d           d S rH   )	r  check_iterskeyrefsr   r   r  rt   r)   rX  r   rs   r  r  objects2ri   r  s          r   test_weak_keyed_itersz%MappingTestCase.test_weak_keyed_iters6  s   1133g ||~~TCLL111== 	  	 BBMM"d###MM"d###RVT"X...OOBX*** ==T$,,..1122CLLAAA,,.. 	  	 BBMM"d###MM"d###RVT"X...OOBX*****r   c                 0   |                                  \  }}|                     |           |                                }|                     t	          |          t	          |                     t          |          }|D ]m} |            }|                     |||j                            |                     |j        ||j                 j                   |                    |           n|                     t	          |          d           t          |          }|                     t	          t          |                                                    t	          |                     |                                D ]m} |            }|                     |||j                            |                     |j        ||j                 j                   |                    |           n|                     t	          |          d           d S rH   )	r  r  	valuerefsr   r   r  r)   rX  itervaluerefsr  s          r   test_weak_valued_itersz&MappingTestCase.test_weak_valued_itersQ  s   2244g ~~TCLL111== 	  	 BBRbf...RVT"&\%5666OOBX*** ==T$"4"4"6"67788#g,,GGG$$&& 	  	 BBRbf...RVT"&\%5666OOBX*****r   c                    t          |                                          }|                                D ]}|                    |           |                     |d           t          |                                          }|D ]}|                    |           |                     |d           t          |                                          }|                                D ]}|                    |           |                     |d           t          |                                          }|                                D ]}|                    |           |                     |d           d S )Nzitems() did not touch all itemsz!__iter__() did not touch all keysz!iterkeys() did not touch all keysz%itervalues() did not touch all values)r  rf  rX  r   keysvalues)r   rs   rf  itemr  rV  r  vs           r   r  zMappingTestCase.check_itersj  sh   TZZ\\""JJLL 	 	DLL ABBB DIIKK   	 	AKKNNNNBCCC DIIKK   	 	AKKNNNNBCCC dkkmm$$ 	 	AMM!<	> 	> 	> 	> 	>r   c                    t          |          }t           t          ||                                }t          |           |d= t	          j                     |                     t          t          |                    t          |          t          |          dz
  g           ~|                     t          |          |dz
             d S )NrN   )	r   r8  getattrrg  rV   rW   rt   r  r   )r   rs   r  	iter_namer  r   s         r   "check_weak_destroy_while_iteratingz2MappingTestCase.check_weak_destroy_while_iterating  s    II*'$	**,,--RBK

c$r((mmc'llCLL14D%EFFFTAE*****r   c                     |            5 \  }}|                      ||           d d d            n# 1 swxY w Y    |            5 \  }}|                     t          |j        |           d d d            n# 1 swxY w Y   |                      ||            |            5 \  }}|                     t          |j        |           d d d            n# 1 swxY w Y   |                      ||            |            5 \  }}|||<   d d d            n# 1 swxY w Y   |                     ||         |           t          j        |          } |            5 \  }}|                    |           d d d            n# 1 swxY w Y   |                     ||            |            5 \  }}|                                 d d d            n# 1 swxY w Y   |                     t          |          d           d S rH   )
r  r   r  r  popr   r  updateclearr   )r   rs   testcontextrV  r  ddicts         r   -check_weak_destroy_and_mutate_while_iteratingz=MappingTestCase.check_weak_destroy_and_mutate_while_iterating  sN    []] 	&fq!Q%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&[]] 	=fq!h(8!<<<	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=D!!![]] 	5fq!h!444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5D!!![]] 	fq!DG	 	 	 	 	 	 	 	 	 	 	 	 	 	 	a!$$$	$[]] 	fq!KK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	u%%%[]] 	fq!JJLLL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	TA&&&&&sf   155%A77A;>A;"%CCC>	DDDE==FF(GGGc                    t          d          } |            5  t          |          }|                    t          |                                                     |                     t          |          |dz
             |||<   |                     t          |          |           d d d            n# 1 swxY w Y    |            5  |                     t          |          |dz
             |                                 |                     t          |          |dz
             d d d            n# 1 swxY w Y    |            5  |                     t          |          |dz
             |t          |                                          = |                     t          |          |dz
             d d d            n# 1 swxY w Y    |            5  |                     t          |          |dz
             |                                 |                     t          |          |dz
             d d d            n# 1 swxY w Y    |            5  |                                 |                     t          |          d           d d d            n# 1 swxY w Y   |                     t          |          d           d S )	Ni@ rN   r   r   r:   r>   r  r   )r&   r   r  rg  r  r   popitemr  )r   rs   r  rh   r  s        r   &check_weak_del_and_len_while_iteratingz6MappingTestCase.check_weak_del_and_len_while_iterating  s    6NN[]] 	+ 	+D		AHHT$))++&&'''SYYA...DGSYY***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ []] 	/ 	/SYYA...LLNNNSYYA...		/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/
 []] 	/ 	/SYYA...T$))++&&'SYYA...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ []] 	/ 	/SYYA...LLNNNSYYA...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ []] 	+ 	+JJLLLSYY***	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	TA&&&&&s]   BB88B<?B<A!D::D>D>A/G

GGA!III!8J%%J),J)c                    |                                  \  |                     d           |                     d           |                     d           |                     d           |                                  \  t          j        fd            }|                     |           |                                  \  |                     |           d S )Nr  rf  r  r  c               3   J  K   	 t                                                    } t          |                                            j        }t          j                     t          |          |fV  d } t          j                     d S # d } t          j                     w xY wr   r8  rf  rg  r  r)   rV   rW   r&   )r   r  rs   r  s     r   r  zKMappingTestCase.test_weak_keys_destroy_while_iterating.<locals>.testcontext  s      	$**,,''RKKMM%
Qiil"""
 
   A/B B")r  r  
contextlibcontextmanagerr  r  r   r  rs   r  s     @@r   &test_weak_keys_destroy_while_iteratingz6MappingTestCase.test_weak_keys_destroy_while_iterating  s   1133g//gvFFF//gwGGG//gxHHH//gyIII1133g		"
	 
	 
	 
	 
	 
#	"
	 	::4MMM 1133g33D+FFFFFr   c                    |                                  \  |                     d           |                     d           |                     d           |                     d           |                     d           |                                  \  t          j        fd            }|                     |           |                                  \  |                     |           d S )Nr  rf  r  r  r  c               3   J  K   	 t                                                    } t          |                                            j        }t          j                     |t          |          fV  d } t          j                     d S # d } t          j                     w xY wr   r  )r   rV  rs   r  s     r   r  zMMappingTestCase.test_weak_values_destroy_while_iterating.<locals>.testcontext  s      	$**,,''RKKMM%
l"""
 
r  )r  r  r  r  r  r  r  s     @@r   (test_weak_values_destroy_while_iteratingz8MappingTestCase.test_weak_values_destroy_while_iterating  s   2244g//gvFFF//gwGGG//gxHHH//gOOO//g{KKK2244g		"
	 
	 
	 
	 
	 
#	"
	 	::4MMM2244g33D+FFFFFr   c                     t          d          }t          j        |di          }|                     ||         d           d S Nr   il  r&   rf   r  r   r   rh   rs   s      r   #test_make_weak_keyed_dict_from_dictz3MappingTestCase.test_make_weak_keyed_dict_from_dict  sA    1II(!C11a#&&&&&r   c                     t          d          }t          j        |di          }t          j        |          }|                     ||         d           d S r  r  r   rh   rs   dict2s       r   .test_make_weak_keyed_dict_from_weak_keyed_dictz>MappingTestCase.test_make_weak_keyed_dict_from_weak_keyed_dict  sQ    1II(!C11)$//a#&&&&&r   c                     t          j                    }t          t          t          t          | j                                      }|D ]}|j        ||<   ||fS r   )rf   r  r  mapr&   r   r  r)   r   rs   r  rh   s       r   r  z$MappingTestCase.make_weak_keyed_dict	  sW    (**s65#4#45566 	 	AeDGGW}r   c                     t          d          }t          j        d|i          }|                     |d         |           d S r  r&   rf   rv  r   r  s      r   $test_make_weak_valued_dict_from_dictz4MappingTestCase.test_make_weak_valued_dict_from_dict  sA    1II*C733cA&&&&&r   c                     t          d          }t          j        d|i          }t          j        |          }|                     |d         |           d S r  r  r  s       r   0test_make_weak_valued_dict_from_weak_valued_dictz@MappingTestCase.test_make_weak_valued_dict_from_weak_valued_dict  sQ    1II*C733+D11cA&&&&&r   c                    |                      t          t          j        j                   |                      t          t          j        i i            |                      t          t          j        dd           t          d          }dD ]g}t          j        di ||i}|                     t          |                                          |g           |                     ||         |           hd S )Nr   r   r   rs   r2   iterable)	r   r   rf   rv  r*   r&   r   r  r  )r   rh   kwr  s       r   test_make_weak_valued_dict_miscz/MappingTestCase.test_make_weak_valued_dict_misc  s    )W%@%IJJJ)W%@"bIII)W%@"bIII1II5 	' 	'B+66r1g66AT!&&((^^bT222QrUA&&&&	' 	'r   c                     t          j                    }t          t          t          t          | j                                      }|D ]}|||j        <   ||fS r   )rf   rv  r  r  r&   r   r  r)   r  s       r   r  z%MappingTestCase.make_weak_valued_dict'  sW    *,,s65#4#45566 	 	ADKKW}r   c                 "    |            }|||<   |||<   |                      t          |          d           |                                \  }}|                      t          |          d           ||u r|                     ||           n|                     ||           |                                \  }}|                      t          |          d           ||u r|                     ||           d S |                     ||           d S )Nr   rN   r   )r   r   r  r   )	r   klasskey1value1key2value2weakdictrV  r  s	            r   check_popitemzMappingTestCase.check_popitem.  s   577X***!!1X***99MM!V$$$$MM!V$$$!!1X***99MM!V$$$$$MM!V$$$$$r   c                 |    |                      t          j        dt                      dt                                 d S )Nr  r  )r  rf   rv  r
   r   s    r   test_weak_valued_dict_popitemz-MappingTestCase.test_weak_valued_dict_popitem@  s:    76!133	5 	5 	5 	5 	5r   c                 |    |                      t          j        t                      dt                      d           d S Nzvalue 1zvalue 2)r  rf   r  r
   r   s    r   test_weak_keyed_dict_popitemz,MappingTestCase.test_weak_keyed_dict_popitemD  s:    7433	133		; 	; 	; 	; 	;r   c                 d   |                      ||d            |            }|                    ||          }|                     ||           |                     ||           |                     |                    |          |           |                     ||         |           |                    ||          }|                     ||           |                     ||           |                     |                    |          |           |                     ||         |           d S )Nz9invalid test -- value parameters must be distinct objects)r  
setdefaultr   rt   get)r   r  keyr  r  r  rh   s          r   check_setdefaultz MappingTestCase.check_setdefaultH  s$   E	F 	F 	F 577V,,a   c8$$$hll3''000hsmV,,,V,,a   c8$$$hll3''000hsmV,,,,,r   c                 z    |                      t          j        dt                      t                                 d S )Nr  )r  rf   rv  r
   r   s    r    test_weak_valued_dict_setdefaultz0MappingTestCase.test_weak_valued_dict_setdefaultY  s8    g9#QSS!##	/ 	/ 	/ 	/ 	/r   c                 b    |                      t          j        t                      dd           d S r  )r  rf   r  r
   r   s    r   test_weak_keyed_dict_setdefaultz/MappingTestCase.test_weak_keyed_dict_setdefault]  s4    g7cc9i	9 	9 	9 	9 	9r   c                     |            }|                     |           |                     t          |          t          |                     |                                D ]s}|                     ||d           |                    |          }|                     |||                    |                     ||                    |                     t|                                D ]f}|                     ||d           ||         }|                     |||                    |                     ||                    |                     gd S )Nz(mysterious new key appeared in weak dictz%original key disappeared in weak dict)r  r   r   r  rt   r  r   )r   r  rs   r  rV  r  s         r   check_updatezMappingTestCase.check_updatea  s3   
 577XD		222 	. 	.AMM!T#MNNNAMM!Xa[)))MM!X\\!__---- 	. 	.AMM!X'NOOOQAMM!Xa[)))MM!X\\!__----		. 	.r   c           
      .   |                      t          j        dt                      dt                      t                      t                      i           |                     t
          t          j        j                   t          j                    }|                     t
          |j        i i            |                     t
          |j        dd           |                     t          |	                                          g            t          d          }dD ]v}t          j                    } |j        di ||i |                     t          |	                                          |g           |                     ||         |           wd S )NrN   r-  r   r   r  )r  rf   rv  r
   r   r   r  r   r  r  r&   )r   r  rh   r  s       r   test_weak_valued_dict_updatez,MappingTestCase.test_weak_valued_dict_updatet  sX   '5acc3QSS!##6	8 	8 	8 	)W%@%GHHH')))QXr2666)QXr2666affhh,,,1II5 	' 	'B+--AAHAwT!&&((^^bT222QrUA&&&&		' 	'r   c                    t                      }t                      }t                      }t          j        d|i          }t          j        ||d          }|                                }||d}d|fd|fg}||z  }	|                     t          |	          t          |          t          |          z             |                     t          |	          t          j                   ||z  }|                     ||	           ||z  }
|                     t          |
          t          |          |z             |                     t          |
          t          j                   ||z  }|                     ||
           |                                }||z  }|                     t          |          t          |          t          |          z             |                     t          |          t          j                   ||z  }|                     t          |          |t          |          z             |                     t          |          t          j                   ~|                     d|	           |                     d|
           |                     d|           |                     d|           d S )NrN   rN   r   )rN   r   r>   r  r   )	r
   rf   rv  r  r   rs   r   r   r  )r   r-  r  r   wvd1wvd2wvd3d1pairstmp1tmp2tmp3tmp4s                r    test_weak_valued_union_operatorsz0MappingTestCase.test_weak_valued_union_operators  s[   CCCCCC*Aq622*qQ<<88yy{{q\\Q!Q d{dT$ZZ$t**%<===d4jj'"=>>>t$$$bydT$ZZ"_555d4jj'"=>>>
t$$$yy{{dT$ZZ$u++%=>>>d4jj'"=>>>DydR$t**_555d4jj'"=>>>D!!!D!!!D!!!D!!!!!r   c           	          |                      t          j        t                      dt                      dt                      di           d S )NrN   r   r   )r  rf   r  r
   r   s    r   test_weak_keyed_dict_updatez+MappingTestCase.test_weak_keyed_dict_update  sE    '3331331332	4 	4 	4 	4 	4r   c                 z   t          j                    }t          d          }t          d          }d||<   d||<   |                     t	          |          d           ||= |                     t	          |          d           |                     t          |                                          |g           d S )N12	somethingr   rN   )rf   r  r&   r   r   r  r  r   r  o1r   s       r   test_weak_keyed_delitemz'MappingTestCase.test_weak_keyed_delitem  s    %''C[[C[[""Q###bEQ###affhh".....r   c                 0   t                      }t                      }t                      }t          j        |d|di          }t          j        |d|di          }|                                }|d|di}|df|dfg}||z  }	|                     t          |	          t          |          t          |          z             |                     t          |	          t          j                   ||z  }|                     ||	           ||z  }
|                     t          |
          t          |          |z             |                     t          |
          t          j                   ||z  }|                     ||
           |                                }||z  }|                     t          |          t          |          t          |          z             |                     t          |          t          j                   ||z  }|                     t          |          |t          |          z             |                     t          |          t          j                   ~|                     d|		                                           |                     d|
	                                           |                     d|	                                           |                     d|	                                           d S )	NrN   r   r   r:   56      )
r
   rf   r  r  r   rs   r   r   r  r  )r   r  r   o3wkd1wkd2wkd3r  r  r  r  r  r  s                r   test_weak_keyed_union_operatorsz/MappingTestCase.test_weak_keyed_union_operators  s   SSSSSS("aQ88("aQ88yy{{#r3a2q'"d{dT$ZZ$t**%<===d4jj'";<<<t$$$bydT$ZZ"_555d4jj'";<<<
t$$$yy{{dT$ZZ$u++%=>>>d4jj'";<<<DydR$t**_555d4jj'";<<<DKKMM***DKKMM***DKKMM***DKKMM*****r   c                 ~   t          j                    }t          d          }t          d          }||d<   ||d<   |                     t	          |          d           |d= |                     t	          |          d           |                     t          |                                          d|fg           d S )Nr  r  r  zsomething elser   rN   )rf   rv  r&   r   r   r  rf  r  s       r   test_weak_valued_delitemz(MappingTestCase.test_weak_valued_delitem  s    '))C[[C[[+ 
Q###kNQ###aggii,<b+A*BCCCCCr   c                    t          j                    }t          d          }|                     t          |j        |           |                     t          |j        |           |                     t          |j        d           |                     t          |j        d           |                     t          |j        dd           d S )Nr     )	rf   r  r&   r   r  r  r  r   __setitem__)r   r  rh   s      r   test_weak_keyed_bad_delitemz+MappingTestCase.test_weak_keyed_bad_delitem  s    %''3KK 	(AM1555(AM1555 	)Q]R888)Q]R888)Q]R<<<<<r   c                    t          j                    }d G fddt                    fdt          d          D             D ]}|j        ||<   ~t          |                                                                           dd}D ]
}|dz  }||= t                       | 	                    t          |          d           | 	                    |d	           d S )
NFc                   (    e Zd Zd Zd Z fdZdS )<MappingTestCase.test_weak_keyed_cascading_deletes.<locals>.Cc                     || _         d S r   r  )r   rg  s     r   r*   zEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__init__   s    


r   c                 *    t          | j                  S r   )r7   r  r   s    r   r8   zEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__hash__  s    DJ'''r   c                 .    rd= | j         |j         k    S )Nr  r  )r   r2   mutateobjss     r   r3   zCMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.C.__eq__  s#     ! RzU[00r   N)r   r   r   r*   r8   r3   )r  r   s   r   r
   r    sQ          ( ( (1 1 1 1 1 1 1 1r   r
   c                 &    g | ]} |          S r   r   )r`  rg  r
   s     r   ra  zEMappingTestCase.test_weak_keyed_cascading_deletes.<locals>.<listcomp>  s!    '''!'''r   r:   Tr   rN   r   )rf   r  r   r   r  r  r  reverser   r   r   )r   r  rh   countr
   r  r   s       @@@r   !test_weak_keyed_cascading_deletesz1MappingTestCase.test_weak_keyed_cascading_deletes  s#   
 %''
	1 
	1 
	1 
	1 
	1 
	1 
	1 
	1 
	1 
	1 
	1 ('''eAhh''' 	 	A7AaDDAFFHH~~ 	  	 	AQJE!Q###"""""r   c                 r    t          j                    }|                     t          |          d           d S )Nz<WeakValueDictionary at 0x.*>)rf   rv  assertRegexrg   r   rs   s     r   test_make_weak_valued_dict_reprz/MappingTestCase.test_make_weak_valued_dict_repr%  s3    *,,d%DEEEEEr   c                 r    t          j                    }|                     t          |          d           d S )Nz<WeakKeyDictionary at 0x.*>)rf   r  r&  rg   r'  s     r   test_make_weak_keyed_dict_reprz.MappingTestCase.test_make_weak_keyed_dict_repr)  s3    (**d%BCCCCCr   c                    t          j                    }t                      5  t          d          D ];}|                    dt                                }|                     |d            ~<	 d d d            d S # 1 swxY w Y   d S Ni r   )rf   rv  ra   r   r  rA   r  r   r  rg  r   s       r   $test_threaded_weak_valued_setdefaultz4MappingTestCase.test_threaded_weak_valued_setdefault-  s    '))   	 	6]]  LLXZZ00  D)))A	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA<<B B c                    t          j                    }t                      5  t          d          D ]?}t	                      |d<   |                    dd          }|                     |d            @	 d d d            d S # 1 swxY w Y   d S r,  )rf   rv  ra   r   rA   r  r  r-  s       r   test_threaded_weak_valued_popz-MappingTestCase.test_threaded_weak_valued_pop6  s    '))   	* 	*6]] * * 

"EE"bMM  D))))*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*s   AB  BBc                    t          j                    }t                      5  t          d          D ]:}t	                      }||d<   |                     t          |          d           d };	 d d d            d S # 1 swxY w Y   d S )Ni@ r   rN   )rf   rv  ra   r   rA   r   r   )r   r  rg  rh   s       r   %test_threaded_weak_valued_consistencyz5MappingTestCase.test_threaded_weak_valued_consistency?  s     '))   	 	6]]  JJ"  Q+++	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   AA;;A?A?c                    g } G d d          } G d d          }fd}d }|                      |t          j        t          j        f            |            }g }	g }
t	          d          D ]I} ||           ||          }}|	                    |           |
                    |           |||<   ~~Jt          j        |||f          }|t          j        u rt          j        ||	f          }nt          j        ||
f          }|                                 |                                 |	                                 |	                                 |r|d	         d S )
Nc                       e Zd Zd ZdS )?MappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyKeyc                     || _         d S r   ctrr   r8  s     r   r*   zHMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyKey.__init__R      r   NrD   r   r   r   DummyKeyr5  Q  rq   r   r;  c                       e Zd Zd ZdS )AMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyValuec                     || _         d S r   r7  r9  s     r   r*   zJMappingTestCase.check_threaded_weak_dict_copy.<locals>.DummyValue.__init__V  r:  r   NrD   r   r   r   
DummyValuer=  U  rq   r   r?  c                     	 du rt          j        |           }d S |                                  }d S # t          $ r }|                    |           Y d }~d S d }~ww xY wr   )r  deepcopyr\  r   )r  excrK  exrA  s       r   	dict_copyz@MappingTestCase.check_threaded_weak_dict_copy.<locals>.dict_copyY  sq    t##a((AAAAAA   

2s   3 3 
AAAc                     d}| r_t          j        dt          |           dz
            }|dz  }|                     |           |dz  dk    rt	          j                     | ]d S d S )Nr   rN   i'  )randomrandintr   r  rV   rW   )lstgc_ctrrg  s      r   pop_and_collectzFMappingTestCase.check_threaded_weak_dict_copy.<locals>.pop_and_collectb  sz    F !N1c#hhl33!


E>Q&&JLLL  ! ! ! ! !r   ip )rZ   r  r   )
rt   rf   r  rv  r   r   r\   r]   r^   r_   )r   type_rA  rB  r;  r?  rD  rJ  r  r  r  rg  rV  r  t_copy	t_collects     `             r   check_threaded_weak_dict_copyz-MappingTestCase.check_threaded_weak_dict_copyL  s    	 	 	 	 	 	 	 		 	 	 	 	 	 	 		 	 	 	 		! 	! 	! 	eg79TUVVVEGGu 	 	A8A;;

1qAKKNNNMM!AaD!!SCCCG---!(tgNNNII!(viPPPI  	a&L	 	r   c                 F    |                      t          j        d           d S NFrN  rf   r  r   s    r    test_threaded_weak_key_dict_copyz0MappingTestCase.test_threaded_weak_key_dict_copy  s#     	**7+DeLLLLLr   c                 F    |                      t          j        d           d S r   rQ  r   s    r   $test_threaded_weak_key_dict_deepcopyz4MappingTestCase.test_threaded_weak_key_dict_deepcopy  s#     	**7+DdKKKKKr   c                 F    |                      t          j        d           d S rP  rN  rf   rv  r   s    r   "test_threaded_weak_value_dict_copyz2MappingTestCase.test_threaded_weak_value_dict_copy  s#     	**7+FNNNNNr   c                 F    |                      t          j        d           d S r   rV  r   s    r   &test_threaded_weak_value_dict_deepcopyz6MappingTestCase.test_threaded_weak_value_dict_deepcopy  s#     	**7+FMMMMMr   c                 j    t          j                    }|                     |j        j                   d S r   )rf   rv  r   _remove__closure__)r   r  s     r   test_remove_closurez#MappingTestCase.test_remove_closure  s/    '))!)/00000r   N)9r   r   r   r  rn  rs  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r(  r*  r   requires_working_threadingr.  r0  r2  rN  rR  rT  rW  rY  r   r  r]  r   r   r   rZ  rZ    s       E     (K K KM M M) ) )0I I IK K K9 9 9@# # #<+ + +6+ + +2> > >4+ + +' ' '2' ' 'BG G G4G G G2' ' '
' ' '  ' ' '
' ' '
' 
' 
'  % % %$5 5 5; ; ;- - -"/ / /9 9 9. . .&' ' '"#" #" #"J4 4 4	/ 	/ 	/#+ #+ #+J	D 	D 	D= = =,# ,# ,#\F F FD D D 1022  32 1022* * 32* 1022
 
 32
; ; ;z 1022M M 32M
 1022L L 32L
 1022O O 32O
 1022N N 32N
 1 1 1 1 1r   rZ  )mapping_testsc                   h    e Zd ZdZ ed           ed           ed          dZej        Zd Z	dS )WeakValueDictionaryTestCasez?Check that WeakValueDictionary conforms to the mapping protocolrN   r   r   )r  r  key3c                 4    | j                                         S r   )!_WeakValueDictionaryTestCase__refr  r   s    r   
_referencez&WeakValueDictionaryTestCase._reference      z   r   N)
r   r   r   __doc__r&   rd  rf   rv  	type2testre  r   r   r   ra  ra    sX        IIF1IIffQiiq		BBE+I! ! ! ! !r   ra  c                   l    e Zd ZdZ ed          d ed          d ed          diZej        Zd Z	d	S )
WeakKeyDictionaryTestCasez=Check that WeakKeyDictionary conforms to the mapping protocolr  rN   r  r   rb  r   c                 4    | j                                         S r   )_WeakKeyDictionaryTestCase__refr  r   s    r   re  z$WeakKeyDictionaryTestCase._reference  rf  r   N)
r   r   r   rg  r&   rl  rf   r  rh  re  r   r   r   rj  rj    s[        GGVF^^Avvf~~aBE)I! ! ! ! !r   rj  c                   b    e Zd Z G d d          Zd Zd Zd Zd Zd Ze	d             Z
d	 Zd
S )FinalizeTestCasec                       e Zd ZdS )FinalizeTestCase.ANr	  r   r   r   r+  rp    s        r   r+  c                 Z    t           j        j        dk    rt          j                     d S d S )Ncpython)sysimplementationnamer   r   r   s    r   _collect_if_necessaryz&FinalizeTestCase._collect_if_necessary  s0    "i//      0/r   c                    fd}|                                  }g t          j        ||ddd          }|                     |j        d           |                     |                                ||dddif           |                      |            d	           |                      |            d            |                      |            d            |                     |                                d            |                     |                                d            |                     |j        d
           |                     d	g           g t          j        ||ddd          }|                     |                                ||di f           |                     |                                ||di f           |                      |            d            |                      |            d            |                     |                                d            |                     |                                d            |                     |j        d
           |                     g            g t          j        ||ddd          }~|                                  |                      |            d            |                      |            d            |                     |                                d            |                     |                                d            |                     |j        d
           |                     d	g           d S )Nc                 J                         | |z   |z              | |z   |z   S r   r  )r   r  r  ress      r   addz+FinalizeTestCase.test_finalize.<locals>.add  s+    JJq1uqy!!!q519r   C   +   Y   )r  T)r{  r|  r     F)r{  r|  r}  )r   r  r  )r+  rf   finalizer   alivepeekdetachrv  )r   rz  r-  r    ry  s       @r   test_finalizezFinalizeTestCase.test_finalize  s:   	 	 	 	 	 FFHHQRr222$'''AsGc"X#>???c"""d###d###4(((T***%(((se$$$QRR00AsJ#;<<<aj"%=>>>d###d###4(((T***%(((b!!!QrR2666""$$$d###d###4(((T***%(((se$$$$$r   c           	         fd}|                                  }g t          j        ||dddd          }|                     |                                ||ddddf            |             |                     ddddfg           |                     t                    5  t          j        ||d           d d d            n# 1 swxY w Y   |                     t                    5  t          j        ||d	           d d d            n# 1 swxY w Y   |                     t          t          j        |           |                     t          t          j                   d S )
Nc                  6                         | |f           d S r   r  )r  kwargsry  s     r   finz-FinalizeTestCase.test_arg_errors.<locals>.fin  s    JJf~&&&&&r   rN   r   r   r:   )funcrv   r  )r  r)   )rv   r  r)   )r+  rf   r  r   r  r   r   )r   r  r-  r    ry  s       @r   test_arg_errorsz FinalizeTestCase.test_arg_errors  s   	' 	' 	' 	' 	' FFHHQQq999AsFQq4I4I#JKKK	1(=(=>?@@@y)) 	1 	1QSa0000	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1 	1y)) 	5 	5!4444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5)W%5q999)W%566666s$   &C

CC/DDDc                     |                                  }g }t          j        ||j        d          }t          j        ||j        d          }t          j        ||j        d          }t          j        ||j        d          }t          j        ||j        d          }~~|                     |j                   |                     |j                   |                     |j                   |                     |                                           |                     |j                    |             |                    d            |             |                     |j                   |                    d            |             |                    d           ~|                                  |                     |j                   |                    d	            |             g d
}| 	                    ||           d S )Nf1f2f3f4f5r+  Br
   r  )r+  r  r  r
   r  r  r  r  )
r+  rf   r  r   r   r  r  r   rv  r   )	r   r-  ry  r  r  r  r  r  expecteds	            r   
test_orderzFinalizeTestCase.test_order  s   FFHHaT22aT22aT22aT22aT22 !!!!!!!!!		$$$"""


3
"""

3


3""$$$ 	"""

3
???h'''''r   c                     G d dt           j                  }|                                 }g fd} |||          }t          j        |          }t          j        |          }~~|                      |                       |                      |                       ~|                                  |                      |                       |                      |                       |                     dg           d S )Nc                       e Zd ZdS )4FinalizeTestCase.test_all_freed.<locals>.MyFinalizerNr	  r   r   r   MyFinalizerr  '  rN  r   r  c                  2                          d           d S )N{   r  )ry  s   r   rP   z1FinalizeTestCase.test_all_freed.<locals>.callback,  s    JJsOOOOOr   r  )rf   r  r+  rO   r   rv  r   r   )r   r  r-  rP   r    wr_callbackwr_fry  s          @r   test_all_freedzFinalizeTestCase.test_all_freed%  s*   	 	 	 	 	'* 	 	 	 FFHH	 	 	 	 	K8$$k(++{1~~a[[]]+++TTVV$$$""$$$++--((($$&&!!!se$$$$$r   c                 ^     fd}t          j         t          dt                    }t          j         t          dt                    }t          j         |          }t          j         t          dt                    }|j        dk    sJ d|_        |j        dk    sJ |j        dk    sJ d S )Nc                  f    t          j        t          d          } t          d           ddz   d S )Ng1f3 errorrN   r   )rf   r  print)r  clss    r   errorz,FinalizeTestCase.run_in_child.<locals>.error@  s4     !#ud33B*aCCCCr   r  r  r  TF)rf   r  r  _global_varatexit)r  r  r  r  r  r  s   `     r   run_in_childzFinalizeTestCase.run_in_child>  s    	 	 	 	 	 c5$<<c5$<<c5))c5$<<yD    	yD    yD      r   c                     d}t          j        d|          \  }}}|                    d                                          }|                     |g d           |                     d|v            d S )NzNfrom test.test_weakref import FinalizeTestCase;FinalizeTestCase.run_in_child()z-cascii)z	f4 foobarr  r  z	f1 foobars   ZeroDivisionError)r   assert_python_okdecode
splitlinesr   r   )r   progrcouterrs        r   test_atexitzFinalizeTestCase.test_atexitR  sy    2$5dDAACjj!!,,..JJJKKK,344444r   N)r   r   r   r+  rv  r  r  r  r  classmethodr  r  r   r   r   rn  rn    s               ! ! !
'% '% '%R7 7 7&%( %( %(N% % %2 ! ! [!&5 5 5 5 5r   rn  c                       e Zd Zd ZdS )ModuleTestCasec                     dD ]n}t          t          |          }|dk    r|                     |j        d           |                     |j        |           |                     |j        |           od S )N)r6  	ProxyTyper   r4  WeakSetr  rv  r  rf   )r  rf   r   r   r   r   )r   ru  rv   s      r   
test_nameszModuleTestCase.test_names\  s    Z 	5 	5D'4((Cy    ;;;S\4000S-t4444	5 	5r   N)r   r   r   r  r   r   r   r  r  [  s#        5 5 5 5 5r   r  a   Doctest for examples in the library reference: weakref.rst

>>> from test.support import gc_collect
>>> 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
>>> gc_collect()  # For PyPy or other GCs.
>>> 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
>>> gc_collect()  # For PyPy or other GCs.
>>> try:
...     id2obj(a_id)
... except KeyError:
...     print('OK')
... else:
...     print('WeakValueDictionary error')
OK


libreftestc                 R    |                     t          j                               |S r   )addTestdoctestDocTestSuite)loadertestspatterns      r   
load_testsr    s"    	MM'&(()))Lr   __main__)rQ   ).rV   rs  r  unittestr   rf   r   r  r  r\   rT   rF  testr   test.supportr   r   r   r   r  r  r
   r   r"   r$   r&   rA   TestCaserF   r  ra   rc   r  r-  rZ  r_  BasicTestMappingProtocolra  rj  rn  r  r  __test__r  r   mainr   r   r   <module>r     s   				 



                          1 1 1 1 1 1 1 1 # # # # # # ) ) ) ) ) )         
                  *       
    x        *a a a a a a a aHe+ e+ e+ e+ e+( e+ e+ e+PF. F. F. F. F.* F. F. F.Rh1 h1 h1 h1 h1h h1 h1 h1V      ! ! ! ! !-"H ! ! !! ! ! ! ! F ! ! !`5 `5 `5 `5 `5x( `5 `5 `5F5 5 5 5 5X& 5 5 5T
l :&  
 zHMOOOOO r   