a
    «ˆcø  ã                   @   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 G dd	„ d	ejƒZed
kr‚e ¡  dS )é    )Úabspath)ÚBytesION)Ú
NullEngine)ÚArraySource)ÚOutline)Ú
Streamlinec                   @   sL   e 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 )ÚTestStreamlinec                 C   sR   t  ddd¡}t  |d¡}t  |¡}t  dd¡}d|dd	d
…< t  |d¡}||fS )zkTrivial data -- creates an elementatry scalar field and a
        constant vector field along the 'x' axis.g        g      $@g{®Gáz„?)é
   r	   r	   i¸  Údç      ð?é   Né   )r	   r	   r	   r   )ÚnumpyZarangeZreshapeZ	transposeÚzeros)ÚselfÚsÚv© r   ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_streamline.pyÚ	make_data   s    
zTestStreamline.make_datac           
      C   sL  t ƒ }| ¡  | ¡ }|| _|| _tƒ }|  ¡ \}}d|_||_||_	| 
|¡ tƒ }| |¡ tƒ }| |¡ |jj}|jddddd� tdd�}|j}	|	jd |	_| |¡ |	jjd	d
d� d|j_tdd�}|j}	|	jd |	_| |¡ |	jjdd� d|j_tdd�}|j}	|	jd |	_| |¡ d|	j_d|j_|| _|j| _dS )zlInitial setting up of test fixture, automatically called by TestCase before any other test method is invoked)éûÿÿÿr   r   r   )ç      Àr   r   é   )ÚradiusÚcenterZtheta_resolutionZphi_resolutionÚribbon)Ústreamline_typer   ©ç      Àç      Àr   ©r   r   g      @)Úpoint1Úpoint2ç      Ð?Útubeé   ©r   g      ø?g      À)r   ç333333Ã?r   ©r   ç      @r)   çš™™™™™É?N)r   ÚstartZ	new_sceneÚer   r   r   ÚoriginZscalar_dataZvector_dataZ
add_sourcer   Z
add_moduler   ÚseedÚwidgetZ	trait_setÚwidget_listÚribbon_filterÚwidthÚtube_filterr   ÚpositionÚstÚcurrent_sceneÚscene)
r   r,   r   r
   ZscZvecÚor5   r/   r.   r   r   r   ÚsetUp"   sP    


ÿ





zTestStreamline.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   ÚtearDownZ   s    
zTestStreamline.tearDownc                 C   sN  | j }|jd }|jd jd }|  |jd¡ |  |jjd¡ |  |jj|jjd ¡ |  t	 
|jjjd¡d¡ |  t	 
|jjjd¡d¡ |jd jd	 }|  |jd
¡ |  |jjd¡ |  |jj|jjd ¡ |  t	 
|jjjd¡d¡ |jd jd }|  |jd
¡ |  |jjd¡ |  |jj|jjd	 ¡ |  t	 
|jjjd¡d¡ dS )zDo the actual testing.r   r%   r   r#   r   r   Tr    r   r$   r'   r&   r   r*   r(   N)r7   ÚchildrenÚassertEqualr   r1   r2   r.   r/   r0   r   Zallcloser!   r"   r3   r   r   r4   )r   r   Úsrcr5   r   r   r   Úcheck_   sD    
ÿÿÿÿÿÿÿÿzTestStreamline.checkc                 C   s   |   ¡  dS )zTest if the test fixture worksN)r@   r;   r   r   r   Útest_streamline}   s    zTestStreamline.test_streamlinec                 C   sl   | j }|j}| ¡ |_||_|j ¡ |_|j}| ¡ |_||_|j ¡ |_|j}| ¡ |_||_|  ¡  dS )zQTest if the modules respond correctly when the components
           are changed.N)r5   r3   Ú	__class__r1   r.   ZactorZstream_tracerr@   )r   r5   Útfr.   Ztracerr   r   r   Útest_components_changed�   s    


z&TestStreamline.test_components_changedc                 C   sX   | j }| j}tƒ }tdƒ|_| |¡ | d¡ | |¡ | |¡ |j	| _|  
¡  dS )z6Test if saving a visualization and restoring it works.ztest.mv2r   N)r,   r7   r   r   ÚnameZsave_visualizationÚseekZclose_sceneZload_visualizationr6   r@   )r   Zenginer7   Úfr   r   r   Útest_save_and_restore”   s    




z$TestStreamline.test_save_and_restorec                 C   sJ   | j }|j}g |_|j |¡ |  ¡  t |¡}||jdd…< |  ¡  dS )z5Test if the MayaVi2 visualization can be deep-copied.N)r7   r=   Úextendr@   ÚcopyÚdeepcopy)r   r   ÚsourcesZsources1r   r   r   Útest_deepcopied¨   s    
zTestStreamline.test_deepcopiedN)Ú__name__Ú
__module__Ú__qualname__r   r9   r<   r@   rA   rD   rH   rM   r   r   r   r   r      s   8r   Ú__main__)Úos.pathr   Úior   rJ   r   ZunittestZmayavi.core.null_enginer   Zmayavi.sources.array_sourcer   Zmayavi.modules.outliner   Zmayavi.modules.streamliner   ZTestCaser   rN   Úmainr   r   r   r   Ú<module>   s    -