3
ÌœŸW'  ã               @   sH   d Z ddlZddlZddlZddlZejdd„ ƒZG dd„ dejƒZdS )z Test utilities
é    Nc           
   c   s0   t jƒ } z
dV  W d| r"t jƒ  nt jƒ  X dS )z?Ensure that gc state is restored on exit of the with statement.N)ÚgcÚ	isenabledÚenableÚdisable)Zoriginally_enabled© r   úT/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/tvtk/tests/common.pyÚrestore_gc_state   s    

r   c               @   s   e Zd ZdZddd„ZdS )ÚTestGarbageCollectionz¤ This is a base class to use when testing garbage collection.
        See: tvtk.tests.test_garbage_collection
             mayavi.tests.test_garbage_collection
    Nc          
      sb   g ‰d}‡fdd„‰‡ ‡‡fdd„}t ƒ � tjƒ  |ƒ }W dQ R X | jˆd ƒ | j|ƒ ƒ dS )a”   Call this from a test function to test for garbage collection
            passing the following parameters:

            obj_create_fn: function
                A function with no parameters that creates the object

            obj_close_fn: function
                A function of 1 parameter which is the object created by
                obj_create_fn, to handling the object closing, if any.
        Nc                s   ˆ j dƒ d S )NT)Úappend)Úweakref)Úobject_collectedr   r   Úobject_collected_callback-   s    zWTestGarbageCollection.check_object_garbage_collected.<locals>.object_collected_callbackc                 s"   ˆƒ } t j| ˆƒ}ˆ rˆ | ƒ |S )N)r   Úref)ÚobjÚ	reference)Úobj_close_fnÚobj_create_fnr   r   r   Údo0   s
    z@TestGarbageCollection.check_object_garbage_collected.<locals>.dor   )r   r   r   Ú
assertTrueÚassertIsNone)Úselfr   r   Zobject_weakrefr   r   )r   r   r   r   r   Úcheck_object_garbage_collected   s    z4TestGarbageCollection.check_object_garbage_collected)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	      s   r	   )	r   Ú
contextlibr   Úunittestr   Úcontextmanagerr   ÚTestCaser	   r   r   r   r   Ú<module>   s   