a
    ©ˆc;  ã                   @   sB   d Z ddlZddlZddlmZ ddlmZ G dd„ dejƒZdS )ú Tests for safe weakrefs. é    N)Úref)Ú	HasTraitsc                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚSafeWeakrefTestCaser   c                 C   s€   G dd„ dt ƒ}|ƒ }|  t¡� t|jƒ}W d   ƒ n1 s@0    Y  |  d |ƒ ¡ |ƒ ƒ  |  |j¡ ~|  d |ƒ ¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )zHSafeWeakrefTestCase.test_can_create_weakref_to_bound_method.<locals>.Fooc                 S   s
   d| _ d S )NT)Úmethod_called©Úself© r	   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/envisage/tests/test_safeweakref.pyÚmethod   s    zOSafeWeakrefTestCase.test_can_create_weakref_to_bound_method.<locals>.Foo.methodN©Ú__name__Ú
__module__Ú__qualname__r   r	   r	   r	   r
   ÚFoo   s   r   )	r   ÚassertWarnsÚDeprecationWarningr   r   ZassertNotEqualÚ
assertTruer   ÚassertEqual©r   r   ÚfÚrr	   r	   r
   Ú'test_can_create_weakref_to_bound_method   s    (z;SafeWeakrefTestCase.test_can_create_weakref_to_bound_methodc                 C   sd   G dd„ dt ƒ}|ƒ }|  t¡�$ t|jƒ}t|jƒ}W d   ƒ n1 sJ0    Y  |  ||¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )zPSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_identical.<locals>.Fooc                 S   s   d S ©Nr	   r   r	   r	   r
   r   1   s    zWSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_identical.<locals>.Foo.methodNr   r	   r	   r	   r
   r   0   s   r   )r   r   r   r   r   ZassertIs)r   r   r   Zref1Zref2r	   r	   r
   Ú/test_two_weakrefs_to_bound_method_are_identical/   s    
(zCSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_identicalc                 C   s�   t j}G dd„ dtƒ}|ƒ }t|ƒ}|  t¡� t |jƒ}W d   ƒ n1 sN0    Y  |  |d t|ƒ¡ ~|  d |ƒ ¡ |  |t|ƒ¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )z@SafeWeakrefTestCase.test_internal_cache_is_weak_too.<locals>.Fooc                 S   s   d S r   r	   r   r	   r	   r
   r   G   s    zGSafeWeakrefTestCase.test_internal_cache_is_weak_too.<locals>.Foo.methodNr   r	   r	   r	   r
   r   F   s   r   é   )r   Ú_cacher   Úlenr   r   r   r   )r   Úcacher   r   Z	len_cacher   r	   r	   r
   Útest_internal_cache_is_weak_too<   s    (z3SafeWeakrefTestCase.test_internal_cache_is_weak_tooc                 C   st   G dd„ dt ƒ}|ƒ }|  t¡�$ t|jƒ}t|jƒ}W d   ƒ n1 sJ0    Y  |  ||¡ |  |dk ¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )zLSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_equal.<locals>.Fooc                 S   s   d S r   r	   r   r	   r	   r
   r   `   s    zSSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_equal.<locals>.Foo.methodNr   r	   r	   r	   r
   r   _   s   r   éc   )r   r   r   r   r   r   r   ©r   r   r   Zr1Zr2r	   r	   r
   Ú+test_two_weakrefs_to_bound_method_are_equal^   s    
(z?SafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_equalc                 C   sº   G dd„ dt ƒ}|ƒ }|  t¡�$ t|jƒ}t|jƒ}W d   ƒ n1 sJ0    Y  |  t|ƒt|ƒ¡ |  t¡�  t|ƒ}t|ƒ}W d   ƒ n1 s˜0    Y  |  t|ƒt|ƒ¡ d S )Nc                   @   s   e Zd Zdd„ ZdS )zOSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_hash_equally.<locals>.Fooc                 S   s   d S r   r	   r   r	   r	   r
   r   p   s    zVSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_hash_equally.<locals>.Foo.methodNr   r	   r	   r	   r
   r   o   s   r   )r   r   r   r   r   r   Úhashr!   r	   r	   r
   Ú.test_two_weakrefs_to_bound_method_hash_equallyn   s    
(&zBSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_hash_equallyc                 C   s^   G dd„ dt ƒ}|ƒ }|  t¡� t|ƒ}W d   ƒ n1 s>0    Y  |  tjt|ƒ¡ d S )Nc                   @   s   e Zd ZdS )zNSafeWeakrefTestCase.test_get_builtin_weakref_for_non_bound_method.<locals>.FooN)r   r   r   r	   r	   r	   r
   r   „   s   r   )r   r   r   r   r   ÚweakrefÚtyper   r	   r	   r
   Ú-test_get_builtin_weakref_for_non_bound_methodƒ   s
    &zASafeWeakrefTestCase.test_get_builtin_weakref_for_non_bound_methodc                 C   s€   G dd„ dt ƒ}|ƒ }|  t¡� t|jƒ W d   ƒ n1 s@0    Y  |  t¡� t|ƒ W d   ƒ n1 sr0    Y  d S )Nc                   @   s   e Zd Zdd„ ZdS )z0SafeWeakrefTestCase.test_deprecated.<locals>.Fooc                 S   s   d S r   r	   r   r	   r	   r
   r   �   s    z7SafeWeakrefTestCase.test_deprecated.<locals>.Foo.methodNr   r	   r	   r	   r
   r   �   s   r   )r   r   r   r   r   )r   r   r   r	   r	   r
   Útest_deprecatedŽ   s    (z#SafeWeakrefTestCase.test_deprecatedN)r   r   r   Ú__doc__r   r   r   r"   r$   r'   r(   r	   r	   r	   r
   r      s   "r   )	r)   Zunittestr%   Zenvisage.safeweakrefr   Z
traits.apir   ZTestCaser   r	   r	   r	   r
   Ú<module>
   s
   