a
    «ˆc  ã                   @   s†   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 G dd	„ d	eƒZG d
d„ de jƒZedkr‚e  ¡  dS )é    N)Ú
NullEngine)Úregistry)ÚPLOT3DReader)ÚSourceMetadata)ÚPipelineInfo)Úget_example_datac                   @   s    e Zd Zdd„ Zedd„ ƒZdS )ÚDummyReaderc                 C   s   dS )zSThis is a Dummy Reader for Testing Purposes
        Its extended from PLOT3D ReaderN© ©Úselfr	   r	   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mayavi/tests/test_registry.pyÚ
print_info   s    zDummyReader.print_infoc                 C   s   dS )z- Callable which alwasy returns False
        Fr	   )ÚclsÚfilenamer	   r	   r   Ú
check_read   s    zDummyReader.check_readN)Ú__name__Ú
__module__Ú__qualname__r   Úclassmethodr   r	   r	   r	   r   r      s   r   c                   @   sD   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S )ÚTestRegistryc                 C   s(   t ƒ }| ¡  | ¡  || _|j| _dS )ztInitial setting up of test fixture, automatically called by TestCase
        before any other test method is invokedN)r   ÚstartZ	new_sceneÚeZcurrent_sceneZscene)r   r   r	   r	   r   ÚsetUp#   s    zTestRegistry.setUpc                 C   s   | j  ¡  dS )ziFor necessary clean up, automatically called by TestCase
        after the test methods have been invokedN)r   Ústopr
   r	   r	   r   ÚtearDown/   s    
zTestRegistry.tearDownc                 C   s$   | j }| tdƒ¡}|  |d¡ dS )z;Check if a file with a unique reader in Mayavi2 can be readz	prism.neuN)r   Úopenr   ZassertNotEqual)r   r   Úreaderr	   r	   r   Útest_unique_reader5   s    zTestRegistry.test_unique_readerc                 C   s   t  d¡}|  |d¡ dS )z<Test if the mechanism to handle unsupported files works finezjunk.abcN)r   Úget_file_readerÚassertEqual)r   r   r	   r	   r   Útest_unsupported_file;   s    
z"TestRegistry.test_unsupported_filec                 C   sL   t  tdƒ¡}| ¡ }|  |jd¡ t  tdƒ¡}| ¡ }|  |jd¡ dS )z#Test if reader conflict is resolvedútiny.xyzr   zthio3xx.xyzZPolyDataReaderN)r   r   r   Úget_callabler   r   )r   r   Úcallabler	   r	   r   Útest_multipe_readers@   s    z!TestRegistry.test_multipe_readersc                 C   sü   t dddddddgddtdgd	gd	gd
�d�
}tj |¡ t tdƒ¡}| ¡ }|  |j	d¡ g }t
tjdd… ƒD ]6\}}d|jv rt|jdkrt| ||f¡ tj |¡ qtt tdƒ¡}| ¡ }|  |j	d¡ |D ]\}}tj ||¡ qÔtj |¡ dS )ziTest if the fixture works fine if there are multiple readers
        capable of reading the file properlyÚ	DummyFileú&mayavi.tests.test_registry.DummyReaderú&PLOT3D fileúOpen a PLOT3D data dataÚxyzúPLOT3D files (*.xyz)|*.xyzú1mayavi.tests.test_registry:DummyReader.check_readÚstructured_gridÚany©ZdatasetsZattribute_typesÚ
attributes©
ÚidÚ
class_nameZ	menu_nameZtooltipÚdescÚhelpÚ
extensionsZwildcardZcan_read_testZoutput_infor!   r   Nr   )r   r   r   ÚsourcesÚappendr   r   r"   r   r   Ú	enumerater5   r1   ÚremoveÚinsert)r   Ú
open_dummyr   r#   r9   ÚindexÚsrcr	   r	   r   Útest_multiple_valid_readersL   s<    þöz(TestRegistry.test_multiple_valid_readersc                 C   s¶   t dddddddgddtdgd	gd	gd
�d�
}tj |¡ ttjdd… ƒD ]&\}}|jdkrL|}tj |¡  qtqLt t	dƒ¡}| 
¡ }|  |jd¡ tj ||¡ tj |¡ dS )zãTest that if there is no reader which can read the file with
        assurity, the registry returns the last one of the readers
        which dont have a can_read_test and claim to read the file with
        the given extensionr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r0   NZPolyDataFiler!   r   )r   r   r   r6   r7   r8   r1   r9   r   r   r"   r   r   r:   )r   r;   r<   r=   Zpolyr   r#   r	   r	   r   Útest_no_valid_readert   s4    þö
z!TestRegistry.test_no_valid_readerN)
r   r   r   r   r   r   r    r$   r>   r?   r	   r	   r	   r   r   !   s   (r   Ú__main__)ZunittestZmayavi.core.null_enginer   Zmayavi.core.registryr   Zmayavi.sources.plot3d_readerr   Zmayavi.core.metadatar   Zmayavi.core.pipeline_infor   Zmayavi.tests.commonr   r   ZTestCaser   r   Úmainr	   r	   r	   r   Ú<module>   s   w