a
    «ˆc'  ã                   @   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   sF   t  ¡ } z dV  W | r t  ¡  qBt  ¡  n| r8t  ¡  nt  ¡  0 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/wcpy/lib/python3.9/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                    sv   g ‰d}‡fdd„‰‡ ‡‡fdd„}t ƒ � t ¡  |ƒ }W d  ƒ n1 sN0    Y  |  ˆd ¡ |  |ƒ ¡ 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   ˆ   d¡ d S )NT)Úappend)Úweakref)Úobject_collectedr   r   Úobject_collected_callback-   s    zWTestGarbageCollection.check_object_garbage_collected.<locals>.object_collected_callbackc                     s"   ˆƒ } t  | ˆ¡}ˆ 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   Ú
assertTrueZ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   Zunittestr   Úcontextmanagerr   ZTestCaser	   r   r   r   r   Ú<module>   s   
