3
ÐÆ‘[ø  ã               @   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jƒ  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 jdddƒ}t j|dƒ}t j|ƒ}t jddƒ}d|dd	d
…< t j|dƒ}||fS )zkTrivial data -- creates an elementatry scalar field and a
        constant vector field along the 'x' axis.g        g      $@g{®Gáz„?é
   i¸  Údg      ð?é   Né   )r	   r	   r	   )r	   r	   r	   r   )ÚnumpyÚarangeÚreshapeÚ	transposeÚzeros)ÚselfÚsÚv© r   ú_/home/yuhw/wc/wire-cell-python/venv/lib/python3.6/site-packages/mayavi/tests/test_streamline.pyÚ	make_data   s    
zTestStreamline.make_datac       
      C   sL  t ƒ }|jƒ  |jƒ }|| _|| _tƒ }| jƒ \}}d|_||_||_	|j
|ƒ tƒ }|j|ƒ tƒ }|j|ƒ |jj}|jddddd� tdd�}|j}	|	jd |	_|j|ƒ |	jjd"d%d� d|j_tdd�}|j}	|	jd |	_|j|ƒ |	jjd(d� d|j_tdd�}|j}	|	jd |	_|j|ƒ d*|	j_d|j_|| _|j| _dS )+zlInitial setting up of test fixture, automatically called by TestCase before any other test method is invokedé   g      ð?ç      @é   )ÚradiusÚcenterZtheta_resolutionZphi_resolutionÚribbon)Ústreamline_typer   g      @g      @)Úpoint1Úpoint2g      Ð?Útubeé   ç      ø?g      @)r   g333333Ã?r   ç      @gš™™™™™É?Néûÿÿÿr%   r%   )r%   r%   r%   ç      Àç      Àç      À)r&   r'   r(   ç      Àç      Àç      À)r)   r*   r+   ç      Àç      À)r,   r-   r   ç      Àç      À)r.   r#   r/   ç      À)r0   r$   r$   )r   ÚstartZ	new_sceneÚer   r   r   ÚoriginZscalar_dataZvector_dataZ
add_sourcer   Z
add_moduler   ÚseedÚwidgetÚ	trait_setÚwidget_listÚribbon_filterÚwidthÚtube_filterr   ÚpositionÚstÚcurrent_sceneÚscene)
r   r2   r   r
   ÚscÚvecÚor<   r5   r4   r   r   r   ÚsetUp"   sN    









zTestStreamline.setUpc             C   s   | j jƒ  dS )zaFor necessary clean up, automatically called by TestCase after the test methods have been invokedN)r2   Ústop)r   r   r   r   ÚtearDownZ   s    
zTestStreamline.tearDownc             C   sN  | j }|jd }|jd jd }| j|jdƒ | j|jjdƒ | j|jj|jjd ƒ | jt	j
|jjjdƒd	ƒ | jt	j
|jjjdƒd	ƒ |jd jd
 }| j|jdƒ | j|jjdƒ | j|jj|jjd ƒ | jt	j
|jjjdƒd	ƒ |jd jd }| j|jdƒ | j|jjdƒ | j|jj|jjd
 ƒ | jt	j
|jjjdƒd	ƒ dS )zDo the actual testing.r   r"   r   g      Ð?r   g      @g      @ç      @Tr   r!   g333333Ã?ç      ø?g      @r   gš™™™™™É?ç      @Nç      Àç      Àç      À)rH   rI   rJ   ç      Àç      À)rK   rL   rE   ç      Àç      À)rM   rF   rN   ç      À)rO   rG   rG   )r>   ÚchildrenÚassertEqualr   r8   r9   r4   r5   r7   r   Úallcloser   r    r:   r   r   r;   )r   r   Úsrcr<   r   r   r   Úcheck_   s,    



zTestStreamline.checkc             C   s   | j ƒ  dS )zTest if the test fixture worksN)rT   )r   r   r   r   Útest_streamline}   s    zTestStreamline.test_streamlinec             C   sl   | j }|j}|jƒ |_||_|jjƒ |_|j}|jƒ |_||_|jjƒ |_|j}|jƒ |_||_| jƒ  dS )zQTest if the modules respond correctly when the components
           are changed.N)r<   r:   Ú	__class__r8   r4   ZactorZstream_tracerrT   )r   r<   Útfr4   Útracerr   r   r   Útest_components_changed�   s    


z&TestStreamline.test_components_changedc             C   sX   | j }| j}tƒ }tdƒ|_|j|ƒ |jdƒ |j|ƒ |j|ƒ |j	| _| j
ƒ  dS )z6Test if saving a visualization and restoring it works.ztest.mv2r   N)r2   r>   r   r   ÚnameZsave_visualizationÚseekZclose_sceneZload_visualizationr=   rT   )r   Úenginer>   Úfr   r   r   Útest_save_and_restore”   s    




z$TestStreamline.test_save_and_restorec             C   sJ   | j }|j}g |_|jj|ƒ | jƒ  tj|ƒ}||jdd…< | jƒ  dS )z5Test if the MayaVi2 visualization can be deep-copied.N)r>   rP   ÚextendrT   ÚcopyÚdeepcopy)r   r   ÚsourcesZsources1r   r   r   Útest_deepcopied¨   s    
zTestStreamline.test_deepcopiedN)Ú__name__Ú
__module__Ú__qualname__r   rB   rD   rT   rU   rY   r^   rc   r   r   r   r   r      s   8r   Ú__main__)Úos.pathr   Úior   r`   r   ÚunittestÚmayavi.core.null_enginer   Zmayavi.sources.array_sourcer   Zmayavi.modules.outliner   Zmayavi.modules.streamliner   ÚTestCaser   rd   Úmainr   r   r   r   Ú<module>   s    -