a
    «ˆcc  ã                   @   s¶   d dl mZ d dlmZ d dlZd dlZd dl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 d dlmZ G dd„ dejƒZedkr²e ¡  dS )é    )Úabspath)ÚBytesION)Ú
NullEngine)ÚContour)ÚOptional)Ú
Collection)ÚPolyDataNormals)ÚSurface)ÚVTKDataSource)Údatasetsc                   @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚTestOptionalCollectionc           	      C   s�   t ƒ }| ¡  | ¡  || _t ¡ }t|d�}| |¡ tƒ }t	dd�}t
|dd�}t||gdd�}| |¡ tƒ }| |¡ || _|j| _dS )	zlInitial setting up of test fixture, automatically called by TestCase before any other test method is invoked)ÚdataZNormals)ÚnamezCompute normals)ÚfilterZ
label_textZ
IsoSurface)Úfiltersr   N)r   ÚstartZ	new_sceneÚer   ZgenerateStructuredGridr
   Z
add_sourcer   r   r   r   Z
add_filterr	   Z
add_moduleÚcollÚcurrent_sceneÚscene)	Úselfr   ZsgridÚsrcÚcÚnÚor   Ús© r   úh/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_optional_collection.pyÚsetUp   s"    




zTestOptionalCollection.setUpc                 C   s   | j  ¡  dS )zaFor necessary clean up, automatically called by TestCase after the test methods have been invokedN)r   Ústop)r   r   r   r   ÚtearDown3   s    
zTestOptionalCollection.tearDownc                 C   s  | j }|j\}}|j}|j}| ¡ jjj}|  tj	|ddd�d¡ |j
 d¡ |  tj	|ddgdd�d¡ |  |jd |jd u d¡ d|_|  d	|jv d¡ |  |jd |jd u d¡ |j
 ¡  d|_|  tj	|ddd�d¡ |  |jd |jd u d¡ |  d	|jvd¡ d
S )zDo the actual testing.)ç\�Âõ(\@r!   gÎp>?ŒP?)ZatolTé
   r!   r   FÚdisabledN)r   r   r   Zget_output_datasetZ
point_dataZscalarsÚrangeÚassertEqualÚnpZallcloseZcontoursÚappendÚoutputsZenabledr   Úpop)r   r   r   r   r   r   Úrr   r   r   Úcheck8   s"    

zTestOptionalCollection.checkc                 C   s   | j }|  |¡ dS )zTest if the test fixture worksN)r   r+   )r   r   r   r   r   Útest_optional_collectionT   s    z/TestOptionalCollection.test_optional_collectionc                 C   sl   | j }| j}tƒ }tdƒ|_| |¡ | d¡ | |¡ | |¡ |j	| _| jj
d j
d }|  |¡ dS )z6Test if saving a visualization and restoring it works.ztest.mv2r   N)r   r   r   r   r   Zsave_visualizationÚseekZclose_sceneZload_visualizationr   Úchildrenr+   )r   Zenginer   Úfr   r   r   r   Útest_save_and_restore]   s    




z,TestOptionalCollection.test_save_and_restorec                 C   sh   | j }|j ¡ }|j |¡ |jd jd }|  |¡ t |¡}||jd< |jd jd }|  |¡ dS )z5Test if the MayaVi2 visualization can be deep-copied.r   N)r   r.   r)   r'   r+   ÚcopyÚdeepcopy)r   r   Úsourcer   Zsource1r   r   r   Útest_deepcopiedt   s    



z&TestOptionalCollection.test_deepcopiedN)	Ú__name__Ú
__module__Ú__qualname__r   r    r+   r,   r0   r4   r   r   r   r   r      s   	r   Ú__main__)Úos.pathr   Úior   r1   Únumpyr&   ZunittestZmayavi.core.null_enginer   Zmayavi.filters.contourr   Zmayavi.filters.optionalr   Zmayavi.filters.collectionr   Zmayavi.filters.apir   Zmayavi.modules.apir	   Zmayavi.sources.vtk_data_sourcer
   Zmayavi.testsr   ZTestCaser   r5   Úmainr   r   r   r   Ú<module>   s   w