a
    «ˆcr  ã                   @   s¨   d Z ddlZddlmZmZmZ ddlmZmZ ddl	m
Z
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ G dd„ deƒZdS )z@ Tests for the garbage collection of objects in mayavi package.
é    N)ÚsqrtÚsinÚmgrid)ÚInstanceÚ	HasTraits)ÚViewÚItem)Ú	ETSConfig)ÚSceneEditor)ÚTestGarbageCollection©ÚMayaviScene)ÚEngine)Ú
NullEngine©ÚMlabSceneModelc                   @   sR   e Zd ZdZe ejdkd¡dd„ ƒZdd„ Z	dd	„ Z
d
d„ Zdd„ Zdd„ ZdS )ÚTestMayaviGarbageCollectionz2 See: tvtk.tests.common.TestGarbageCollection
    Únullz0Test should not run when the ETS toolkit is nullc                    s4   G dd„ dt ƒ‰ dd„ }‡ fdd„}|  ||¡ dS )z; Tests if MlabSceneModel with GUI can be garbage collected.c                	   @   sH   e Zd ZeedƒZeedee	d�ddddd�dd�Z
d	d
„ Zdd„ ZdS )zKTestMayaviGarbageCollection.test_mlab_scene_model_with_gui.<locals>.MlabApp© Úscene)Zscene_classFTiô  )ÚnameZeditorZ
show_labelÚ	resizableÚheightÚwidth)r   c                 [   s   |   ¡  d S ©N)Úgenerate_data)ÚselfZtraitsr   r   úg/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_garbage_collection.pyÚ__init__*   s    zTTestMayaviGarbageCollection.test_mlab_scene_model_with_gui.<locals>.MlabApp.__init__c                 S   sZ   t ddd…ddd…f \}}dt|d |d  ƒ }t|ƒ| }| jjj|||dd� d S )Néþÿÿÿé   y              Y@é
   Z
gist_earth)Zcolormap)r   r   r   r   ZmlabZsurf)r   ÚXÚYÚRÚZr   r   r   r   -   s    zYTestMayaviGarbageCollection.test_mlab_scene_model_with_gui.<locals>.MlabApp.generate_dataN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r
   r   Úviewr   r   r   r   r   r   ÚMlabApp   s   
ûú	r*   c                 S   s$   d | j _tjdkrd | _|  ¡  d S )NZqt4)ÚownerZuir	   ÚtoolkitÚcontrolZdispose©Úor   r   r   Úclose_fn4   s    
zLTestMayaviGarbageCollection.test_mlab_scene_model_with_gui.<locals>.close_fnc                     s   ˆ ƒ } |   ¡ S r   )Zedit_traits)Zapp©r*   r   r   Ú	create_fn:   s    zMTestMayaviGarbageCollection.test_mlab_scene_model_with_gui.<locals>.create_fnN)r   Úcheck_object_garbage_collected)r   r0   r2   r   r1   r   Útest_mlab_scene_model_with_gui   s    z:TestMayaviGarbageCollection.test_mlab_scene_model_with_guic                 C   s    dd„ }dd„ }|   ||¡ dS )z2 Tests if MlabSceneModel can be garbage collected.c                   S   s   t ƒ S r   r   r   r   r   r   r2   C   s    zDTestMayaviGarbageCollection.test_mlab_scene_model.<locals>.create_fnc                 S   s
   d| _ d S ©NT©Úclosingr.   r   r   r   r0   F   s    zCTestMayaviGarbageCollection.test_mlab_scene_model.<locals>.close_fnN©r3   ©r   r2   r0   r   r   r   Útest_mlab_scene_model@   s    z1TestMayaviGarbageCollection.test_mlab_scene_modelc                 C   s    dd„ }dd„ }|   ||¡ dS )z. Tests if core Scene can be garbage collected.c                  S   s   t ƒ } |  ¡  |  ¡ }|S r   ©r   ÚstartZ	new_scene)Úer   r   r   r   r2   M   s    z9TestMayaviGarbageCollection.test_scene.<locals>.create_fnc                 S   s
   d| _ d S r5   r6   r.   r   r   r   r0   S   s    z8TestMayaviGarbageCollection.test_scene.<locals>.close_fnNr8   r9   r   r   r   Ú
test_sceneK   s    z&TestMayaviGarbageCollection.test_scenec                 C   s   dd„ }dd„ }dS )z3 Tests if Mayavi UI Scene can be garbage collected.c                  S   s   t d d�} | S )N)Úparentr   )r   r   r   r   r2   Z   s    
z@TestMayaviGarbageCollection.test_mayavi_scene.<locals>.create_fnc                 S   s
   d| _ d S r5   r6   r.   r   r   r   r0   ^   s    z?TestMayaviGarbageCollection.test_mayavi_scene.<locals>.close_fnNr   r9   r   r   r   Útest_mayavi_sceneX   s    z-TestMayaviGarbageCollection.test_mayavi_scenec                 C   s    dd„ }dd„ }|   ||¡ dS )z4 Tests if core Null Engine can be garbage collected.c                  S   s*   t ƒ } |  ¡  |  ¡  |  ¡  |  ¡  | S r   r;   ©r=   r   r   r   r2   c   s    z?TestMayaviGarbageCollection.test_null_engine.<locals>.create_fnc                 S   s   |   ¡  d S r   ©Ústopr.   r   r   r   r0   k   s    z>TestMayaviGarbageCollection.test_null_engine.<locals>.close_fnNr8   r9   r   r   r   Útest_null_enginea   s    z,TestMayaviGarbageCollection.test_null_enginec                 C   s    dd„ }dd„ }|   ||¡ dS )z/ Tests if core Engine can be garbage collected.c                  S   s   t ƒ } |  ¡  | S r   )r   r<   rA   r   r   r   r2   r   s    z:TestMayaviGarbageCollection.test_engine.<locals>.create_fnc                 S   s   |   ¡  d S r   rB   r.   r   r   r   r0   w   s    z9TestMayaviGarbageCollection.test_engine.<locals>.close_fnNr8   r9   r   r   r   Útest_enginep   s    z'TestMayaviGarbageCollection.test_engineN)r&   r'   r(   Ú__doc__ÚunittestZskipIfr	   r,   r4   r:   r>   r@   rD   rE   r   r   r   r   r      s   ÿ
&	r   )rF   rG   Únumpyr   r   r   Z
traits.apir   r   Ztraitsui.apir   r   Ztraits.etsconfig.apir	   Ztvtk.pyface.scene_editorr
   Ztvtk.tests.commonr   Zmayavi.core.ui.mayavi_scener   Zmayavi.core.enginer   Zmayavi.core.null_enginer   Zmayavi.tools.mlab_scene_modelr   r   r   r   r   r   Ú<module>   s   