a
    «ˆc£/  ã                   @   s˜   d Z ddlmZ ddlZddl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mZ G dd„ dejƒZG d	d
„ d
ejƒZedkr”e ¡  dS )z”Tests for tvtk_base.py.  These only test the basic functionality of
the code in tvtk_base.  More tests for TVTK objects should be in
test_tvtk.py.

é    )ÚreloadN)Úapi)Ú	tvtk_base)Úget_tvtk_nameÚcamel2enthoughtc                   @   sœ   e Zd Zddd„ZejZdd„ Zejdddd	œd
ddd�Z	dd„ Z
e de dd¡¡Zdd„ Ze d¡Zdd„ Ze d¡Zdd„ Ze d¡Zdd„ ZdZdS )ÚPropNé   c                 K   s    t jj| tj||fi |¤Ž d S ©N)r   ÚTVTKBaseÚ__init__ÚvtkÚvtkProperty)ÚselfÚobjÚupdateÚtraits© r   ú\/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/tvtk/tests/test_tvtk_base.pyr      s
    
ÿÿzProp.__init__c                 C   s   |   | jj| j¡ d S r	   )Ú
_do_changeÚ_vtk_objÚSetEdgeVisibilityZedge_visibility_©r   Zold_valÚnew_valr   r   r   Ú_edge_visibility_changed   s    zProp._edge_visibility_changedr   é   )ÚpointsÚ	wireframeÚsurfaceé   é   r   )Údefault_valuec                 C   s   |   | jj| j¡ d S r	   )r   r   ZSetRepresentationÚrepresentation_r   r   r   r   Ú_representation_changed&   s    zProp._representation_changedç      ð?ç        c                 C   s   |   | jj| j¡ d S r	   )r   r   Ú
SetOpacityÚopacityr   r   r   r   Ú_opacity_changed+   s    
ÿzProp._opacity_changed)r#   r#   r#   c                 C   s   |   | jj| jd¡ d S ©Nr   )r   r   ÚSetSpecularColorÚspecular_colorr   r   r   r   Ú_specular_color_changed1   s    
ÿzProp._specular_color_changedc                 C   s   |   | jj| jd¡ d S r(   )r   r   ÚSetDiffuseColorÚdiffuse_colorr   r   r   r   Ú_diffuse_color_changed7   s    
ÿzProp._diffuse_color_changedc                 C   s   |   | jj| j¡ d S r	   )r   r   ÚSetColorÚcolorr   r   r   r   Ú_color_changed=   s    
ÿzProp._color_changed))Úedge_visibilityZGetEdgeVisibility)r&   Z
GetOpacity)r*   ZGetSpecularColor)r0   ZGetColor)r-   ZGetDiffuseColor)ÚrepresentationZGetRepresentation)Nr   )Ú__name__Ú
__module__Ú__qualname__r   r   Zfalse_bool_traitr2   r   ZRevPrefixMapr3   r"   r   ZTraitZRanger&   r'   Zvtk_color_traitr*   r+   r-   r.   r0   r1   Ú_updateable_traits_r   r   r   r   r      s"   

þ


r   c                   @   s‚   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d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zde_dS )ÚTestTVTKBasec                 C   sx   g d¢}g d¢}t |ƒD ] \}}t|ƒ}|  ||| ¡ qg d¢}tdƒD ](}d| }t|ƒ}|  |d||  ¡ qJdS )z'Test VTK to TVTK class name conversion.)Z	vtkFooBarZvtkXMLDataReaderZvtk3DSReaderZ
vtk2000Bug)ZFooBarÚXMLDataReaderZThreeDSReaderZ	Two000Bug)
ZZeroZOneZTwoZThreeZFourZFiveZSixZSevenZEightZNineé
   zvtk%dAz%sAN)Ú	enumerater   ÚassertEqualÚrange)r   Úv_nameÚt_nameÚiÚvnÚtnÚnumr   r   r   Útest_tvtk_nameJ   s    zTestTVTKBase.test_tvtk_namec                 C   s>   g d¢}g d¢}t |ƒD ] \}}t|ƒ}|  ||| ¡ qdS )z2Test CamelCase to Enthought style name conversion.)Z	GetFooBarZ
GetOBBTreer9   Z	GetFooXMLZ
HTMLIsSGMLZ_SetMeZ_XYZTestZActor2DZActor3DZActor6DZPLOT3DReaderZActor61DimensionZGL2PSExporterZVolume16Reader)Zget_foo_barZget_obb_treeZxml_data_readerZget_foo_xmlZhtml_is_sgmlZ_set_meZ	_xyz_testZactor2dZactor3dZactor6_dZplot3d_readerZactor61_dimensionZgl2ps_exporterZvolume16_readerN)r;   r   r<   )r   r>   r?   r@   rA   rB   r   r   r   Útest_camel2enthought[   s
    z!TestTVTKBase.test_camel2enthoughtc                 C   s‚   t ƒ }|j |_d|_d|_d|_d|_d|_|jD ]H\}}t|j	|ƒƒ }|dkrj|  
|t||d ƒ¡ q4|  
|t||ƒ¡ q4dS )	z1Test if VTK object changes when trait is changed.Úpç      à?©r   r   r   )r   r   r   ©r   r   r   r3   Ú_N)r   r2   r3   r&   r0   r-   r*   r7   Úgetattrr   r<   )r   rF   ÚtÚgÚvalr   r   r   Útest_do_changek   s    
zTestTVTKBase.test_do_changec                 C   s@   t ƒ }z| |jjd¡ W n ty,   Y n0 |  |jd¡ d S )NÚar   )r   Z
_wrap_callr   ZSetLineWidthÚ	TypeErrorr<   Z_in_set©r   rF   r   r   r   Ú%test_wrap_call_is_graceful_on_failure{   s    z2TestTVTKBase.test_wrap_call_is_graceful_on_failurec                 C   sª   t ƒ }|j}| d¡ |  |jd¡ | d¡ |  |jd¡ | ¡  |  |jd¡ d}| 	|¡ |  |j
|¡ d}| |¡ |  |j|¡ d}| |¡ |  |j|¡ dS )z0Test trait updation when the VTK object changes.r   rG   r   ©r#   r#   r$   ©r#   r$   r$   )r$   r#   r$   N)r   r   r   r<   r2   r%   r&   ÚSetRepresentationToPointsr3   r/   r0   r,   r-   r)   r*   )r   rF   r   rN   r   r   r   Útest_auto_updateŠ   s"    




zTestTVTKBase.test_auto_updatec                 C   sÞ   t ƒ }| ¡  |j}| d¡ |  |jd¡ | d¡ |  |jd¡ | ¡  |  |j	d¡ | 
¡  | ¡  |  |jd¡ |  |jd¡ |  |j	d¡ | d¡ |  |jd¡ | d¡ |  |jd¡ | ¡  |  |j	d¡ dS )z9If setup_observers and teardown_observers work correctly.r   r   rG   r#   r   r   N)r   Zteardown_observersr   r   r<   r2   r%   r&   rV   r3   Zupdate_traitsZsetup_observersZSetRepresentationToSurface)r   rF   r   r   r   r   Útest_setup_teardown_observers£   s(    



z*TestTVTKBase.test_setup_teardown_observersc                 C   s  t ƒ }d|_d|_d|_d|_d|_d|_t |¡}~t 	|¡}|  
|jd¡ |  
|jd¡ |  
|jd¡ d}|  
|j|¡ d}|  
|j|¡ d	}|  
|j|¡ | ¡ }~t ƒ }|jj}| |¡ |  
||jj¡ |  
|jd¡ |  
|jd¡ |  
|jd¡ d}|  
|j|¡ d
S )zTest if pickling works.r   rF   rG   rH   )r   r   r   rI   r   )r$   r#   r#   rT   N)r   r2   r3   r&   r0   r-   r*   ÚpickleÚdumpsÚloadsr<   Ú__getstate__r   Ú__this__Ú__setstate__)r   rF   ÚsrN   ÚdÚaddrr   r   r   Útest_pickleÃ   s<    


zTestTVTKBase.test_picklec                 C   sX  t ƒ }|  |jd¡ |  |jd¡ d|_|  |jd¡ |  |jd¡ d|_|  |jd¡ |  |jd¡ d|_|  |jd¡ |  |jd¡ d|_|  |jd¡ |  |jd¡ |  tjt|d	d
¡ |  tjt|d	d¡ |  tjt|d	d¡ |  tj¡�}d|_W d  ƒ n1 �s0    Y  d}|  |t	|j
ƒ¡ ~d|_|  |jd¡ |  |jd¡ dS )z)Test the reverse prefix map trait we use.r   r   rF   r   r   Zwirer   r   r3   Zpoints1ZPOINTSé   ÚqNzJ'points' or 'surface' or 'wireframe' (or any unique prefix) or 0 or 1 or 2r   )r   r<   r3   r!   ÚassertRaisesr   Ú
TraitErrorÚsetattrZassertInÚstrÚ	exception)r   rF   Zexception_contextZexpected_info_textr   r   r   Útest_rev_prefix_mapë   sH    ÿÿÿ&ÿþz TestTVTKBase.test_rev_prefix_mapc                 C   s\   t ƒ }t |¡}|  | d¡d¡ t |¡}|  | d¡d¡ t | ¡}|  |jjd¡ dS )zTest the `deref_vtk` function.r   Tr8   N)r   r   Ú	deref_vtkr<   ZIsAÚ	__class__r4   )r   rF   ÚoZo1r   r   r   Útest_deref_vtk  s    


zTestTVTKBase.test_deref_vtkc                 C   s*   t ƒ }d|_t |¡}~|  |ƒ d¡ dS )z*Test object deletion and reference cycles.r   N)r   r3   ÚweakrefÚrefr<   )r   rF   rp   r   r   r   Útest_obj_del&  s
    
zTestTVTKBase.test_obj_delc                 C   st   t ƒ }t |¡}t ¡ �" | d¡ | ¡  W d   ƒ n1 s@0    Y  |  |jd¡ | d¡ |  |jd¡ d S )NrG   r#   gš™™™™™Ù?)r   r   rk   Zglobal_disable_updater%   ZModifiedr<   r&   )r   rF   Zvpr   r   r   Útest_global_disable_update.  s    


&
z'TestTVTKBase.test_global_disable_updatec                 C   sF   t ƒ }|  tjt|dd¡ |  tjt|dd¡ |  tjt|dd¡ dS )z'Test if TVTK objects use strict traits.Úfoor   Z_fooZ__fooN)r   re   r   rf   rg   rR   r   r   r   Útest_strict_traitsA  s    zTestTVTKBase.test_strict_traitsc                 C   sN   t dddd�}|  |jd¡ |  |jd¡ |  |jd¡ | jtjt dd� d	S )
z2Test if the objects traits can be set in __init__.gš™™™™™¹?)r   r   r   rF   )r&   r0   r3   rU   r   Úbar)rs   N)r   r<   r&   r0   r3   re   r   rf   rR   r   r   r   Útest_init_traitsH  s
    zTestTVTKBase.test_init_traitsc                 C   sž   t tjƒ}tƒ }|jj}|  |d t tjƒ¡ |  |tj |¡¡ ~t 	¡  |  |t tjƒ¡ |  |tjv d¡ tƒ }t tjƒ}t
tƒ |  |t tjƒ¡ dS )z%Test if object cache works correctly.r   FN)Úlenr   Z_object_cacher   r   r]   r<   ÚgetÚgcZcollectr   )r   Úl1rF   ra   r   r   r   Útest_zz_object_cacheR  s    

z!TestTVTKBase.test_zz_object_cacheFN)r4   r5   r6   rD   rE   rO   rS   rW   rX   rb   rj   rn   rq   rr   rt   rv   r{   Z__test__r   r   r   r   r8   I   s    (0
r8   Ú__main__)Ú__doc__Ú	importlibr   ZunittestrY   ro   r   ry   r   r   Ztvtkr   Ztvtk.commonr   r   r
   r   ZTestCaser8   r4   Úmainr   r   r   r   Ú<module>   s   2  '