3
6฿L]I  ใ               @   sV   d Z ddlZddlmZ ddlmZ ddlmZ G dd dejZ	e
dkrRej  dS )	z Tests for safe weakrefs. ้    N)ฺref)ฺ	HasTraits)ฺunittestc               @   sP   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d ZdS )ฺSafeWeakrefTestCasez Tests for safe weakrefs. c             C   s   dS )z> Prepares the test fixture before each test method is called. Nฉ )ฺselfr   r   ๚J/tmp/pip-install-5sebvq2j/envisage/envisage/tests/safeweakref_test_case.pyฺsetUp   s    zSafeWeakrefTestCase.setUpc             C   s   dS )z< Called immediately after each test method has been called. Nr   )r   r   r   r   ฺtearDown   s    zSafeWeakrefTestCase.tearDownc             C   sV   G dd dt }| }t|j}| jd |  |   | j|j ~| 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)r   r   r   r   ฺ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   r   r   ZassertNotEqualฺassert_r   ฺ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   s2   G dd dt }| }| jt|jt|j 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   ;   s    zWSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_identical.<locals>.Foo.methodN)r   r   r   r   r   r   r   r   r   :   s   r   )r   ZassertIsr   r   )r   r   r   r   r   r   ฺ/test_two_weakrefs_to_bound_method_are_identical9   s    zCSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_identicalc             C   sf   t j}G dd dt}| }t|}t |j}| j|d t| ~| jd |  | j|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 )Nr   )r   r   r   r   r   O   s    zGSafeWeakrefTestCase.test_internal_cache_is_weak_too.<locals>.Foo.methodN)r   r   r   r   r   r   r   r   r   N   s   r   ้   )r   ฺ_cacher   ฺlenr   r   )r   ฺcacher   r   Z	len_cacher   r   r   r   ฺtest_internal_cache_is_weak_tooD   s    
z3SafeWeakrefTestCase.test_internal_cache_is_weak_tooc             C   sJ   G dd dt }| }t|j}t|j}| j|| | j|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 )Nr   )r   r   r   r   r   i   s    zSSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_equal.<locals>.Foo.methodN)r   r   r   r   r   r   r   r   r   h   s   r   ้c   )r   r   r   r   r   )r   r   r   ฺr1ฺr2r   r   r   ฺ+test_two_weakrefs_to_bound_method_are_equalg   s    

z?SafeWeakrefTestCase.test_two_weakrefs_to_bound_method_are_equalc             C   sf   G dd dt }| }t|j}t|j}| jt|t| t|}t|}| j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 )Nr   )r   r   r   r   r   z   s    zVSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_hash_equally.<locals>.Foo.methodN)r   r   r   r   r   r   r   r   r   y   s   r   )r   r   r   r   ฺhash)r   r   r   r   r   r   r   r   ฺ.test_two_weakrefs_to_bound_method_hash_equallyx   s    

zBSafeWeakrefTestCase.test_two_weakrefs_to_bound_method_hash_equallyc             C   s4   G dd dt }| }t|}| j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   ฺweakrefฺtype)r   r   r   r   r   r   r   ฺ-test_get_builtin_weakref_for_non_bound_method   s
    zASafeWeakrefTestCase.test_get_builtin_weakref_for_non_bound_methodN)r   r   r   ฺ__doc__r	   r
   r   r   r   r   r!   r$   r   r   r   r   r      s   	#r   ฺ__main__)r%   r"   Zenvisage.safeweakrefr   Z
traits.apir   Ztraits.testing.unittest_toolsr   ZTestCaser   r   ฺmainr   r   r   r   ฺ<module>   s    