a
    «ˆcF  ã                   @   s¦   d dl Z d dlZd dlmZm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
„ ZG dd„ dejƒZedkr¢e ¡  dS )é    N)Ú	MagicMockÚMock)Ú
NullEngine)ÚVTKXMLFileReader)ÚOutline)Úget_example_data)Ú
MovieMaker)Ú	TVTKScenec                  C   s*   t td�} d| _d| _ttd�}|| _| S )z=Mocks a scene suitable for testing the movie generation.
    )Úspec)é   r   r   T)r   r	   Z
foregroundZoff_screen_renderingr   r   Úmovie_maker)ÚsÚmm© r   úb/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_file_timestep.pyÚmake_mock_scene   s    

r   c                   @   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 )ÚTestFileDataSourceTimestepc           	      C   sÊ   t  ¡ | _tj | jd¡}tj | jd¡}tj | jd¡}tj | jd¡}tj | jd¡}tdƒ}|| | _| _|| | _	| _
|| _|| _|||||fD ]}t ||¡ q˜tƒ }| ¡  | ¡  || _d S )Nz	abc_1.vtiz	abc_2.vtiz	def_1.vtiz	def_2.vtiz	xyz_1.vtizcube.vti)ÚtempfileÚmkdtempÚrootÚosÚpathÚjoinr   Úabc1Úabc2Údef1Údef2Úxyz1ÚcubeÚshutilÚcopyr   ÚstartZ	new_sceneÚengine)	Úselfr   r   r   r   r   r   ÚiÚer   r   r   ÚsetUp   s"    
z TestFileDataSourceTimestep.setUpc                 C   s   | j  ¡  t | j¡ d S )N)r"   Ústopr   Úrmtreer   )r#   r   r   r   ÚtearDown2   s    
z#TestFileDataSourceTimestep.tearDownc                 C   s°   | j }tƒ }| | j¡ | |¡ tƒ }| |¡ tƒ }| | j¡ | |¡ tƒ }| | j¡ | |¡ d|_	d|_
|  |j
|j
¡ |  |j
|j
¡ d|_
|  |j
|j
¡ d S )NTr   r   )r"   r   Ú
initializer   Ú
add_sourcer   Ú
add_moduler   r   Úsync_timestepÚtimestepÚassertEqualZassertNotEqual)r#   r%   ÚrÚoÚr2Zr3r   r   r   Ú*test_sync_timesteps_steps_relevant_readers6   s$    



zETestFileDataSourceTimestep.test_sync_timesteps_steps_relevant_readersc                 C   sz   | j }tƒ }| | j¡ d|_| |¡ tƒ }| |¡ tƒ }| | j¡ | |¡ d|_	|  
|jd¡ |  
|jd¡ d S ©Nr   Tr   )r"   r   r*   r   r.   r+   r   r,   r   Úplayr/   )r#   r%   r0   r1   r2   r   r   r   Útest_play_updates_timestepT   s    


z5TestFileDataSourceTimestep.test_play_updates_timestepc                    s–   | j }tƒ ‰ ˆ  | j¡ dˆ _| ˆ ¡ tƒ }| |¡ g ‰‡ ‡fdd„}ˆ  |d¡ dˆ _	dˆ _
g d¢}|  ˆ|¡ |  ˆ jd¡ |  ˆ j	d¡ d S )	Nr   c                    s   ˆ  | ¡ | dkrdˆ _d S )Nr   F)ÚappendÚloop)Únew©r0   Úvaluesr   r   Úcallbackz   s    
zFTestFileDataSourceTimestep.test_loop_loops_timesteps.<locals>.callbackr.   T)r   r   r   r   F)r"   r   r*   r   r.   r+   r   r,   Zon_trait_changer8   r5   r/   )r#   r%   r1   r<   Úexpectedr   r:   r   Útest_loop_loops_timestepsl   s     

z4TestFileDataSourceTimestep.test_loop_loops_timestepsc                 C   sx   | j }tƒ }| | j¡ d|_| |¡ tƒ }||_|j}t	ƒ }| 
|¡ d|_|j ¡  |  |jjd¡ |j ¡  d S r4   )r"   r   r*   r   r.   r+   r   Zscener   r   r,   r5   Zanimation_startZassert_called_once_withr/   Zanimation_stepZ
call_countZanimation_stop)r#   r%   r0   r   r   r1   r   r   r   Ú%test_play_calls_movie_maker_correctly‹   s    


z@TestFileDataSourceTimestep.test_play_calls_movie_maker_correctlyc                 C   sŒ   | j }tƒ }| | j¡ d|_| |¡ |  |jd¡ |  t|j	ƒd¡ t
 | jtj | jd¡¡ d|_|  |jd¡ |  t|j	ƒd¡ d S )Nr   r   é   ú	abc_3.vtiTé   )r"   r   r*   r   r.   r+   r/   Ú_max_timestepÚlenÚ	file_listr   r    r   r   r   r   Úupdate_files)r#   r%   r0   r   r   r   Ú#test_update_files_updates_file_list¤   s    
z>TestFileDataSourceTimestep.test_update_files_updates_file_listc                 C   sè   | j }tƒ }| | j¡ | |¡ tƒ }| | j¡ | |¡ d|_d|_|  |j	d¡ |  t
|jƒd¡ t | jtj | jd¡¡ t | jtj | jd¡¡ d|_|  |j	d¡ |  t
|jƒd¡ |  |j	d¡ |  t
|jƒd¡ d S )NTr   r   r@   rA   z	def_3.vtirB   )r"   r   r*   r   r+   r   r-   r.   r/   rC   rD   rE   r   r    r   r   r   r   rF   )r#   r%   r0   r2   r   r   r   Ú(test_update_files_updates_all_file_lists¸   s$    

zCTestFileDataSourceTimestep.test_update_files_updates_all_file_listsN)Ú__name__Ú
__module__Ú__qualname__r&   r)   r3   r6   r>   r?   rG   rH   r   r   r   r   r      s   r   Ú__main__)r   ZunittestZunittest.mockr   r   r   r   Zmayavi.core.null_enginer   Z"mayavi.sources.vtk_xml_file_readerr   Zmayavi.modules.outliner   Zmayavi.tests.commonr   Ztvtk.pyface.movie_makerr   Ztvtk.pyface.tvtk_scener	   r   ZTestCaser   rI   Úmainr   r   r   r   Ú<module>   s    <