3
P„-]  ã               @   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 jƒ  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/venv/lib/python3.6/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ƒ  |jƒ  || _|j| _dS )ztInitial setting up of test fixture, automatically called by TestCase
        before any other test method is invokedN)r   ÚstartZ	new_sceneÚeÚcurrent_sceneÚscene)r
   r   r	   r	   r   ÚsetUp#   s    zTestRegistry.setUpc             C   s   | j jƒ  dS )ziFor necessary clean up, automatically called by TestCase
        after the test methods have been invokedN)r   Ústop)r
   r	   r	   r   ÚtearDown/   s    
zTestRegistry.tearDownc             C   s$   | j }|jtdƒƒ}| j|dƒ dS )z;Check if a file with a unique reader in Mayavi2 can be readz	prism.neuN)r   Úopenr   ÚassertNotEqual)r
   r   Úreaderr	   r	   r   Útest_unique_reader5   s    zTestRegistry.test_unique_readerc             C   s   t jdƒ}| j|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 jtdƒƒ}|jƒ }| j|jdƒ t jtdƒƒ}|jƒ }| j|jdƒ dS )z#Test if reader conflict is resolvedz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j|ƒ tjtdƒƒ}|jƒ }| j|j	dƒ g }xLt
tjdd… ƒD ]6\}}d|jkrv|jdkrv|j||fƒ tjj|ƒ qvW tjtdƒƒ}|jƒ }| j|j	dƒ x|D ]\}}tjj||ƒ qÚW tjj|ƒ dS )ziTest if the fixture works fine if there are multiple readers
        capable of reading the file properlyÚ	DummyFilez&mayavi.tests.test_registry.DummyReaderz&PLOT3D filezOpen a PLOT3D data dataÚxyzzPLOT3D files (*.xyz)|*.xyzz1mayavi.tests.test_registry:DummyReader.check_readÚstructured_gridÚany)ÚdatasetsÚattribute_typesÚ
attributes)
ÚidÚ
class_nameÚ	menu_nameÚtooltipÚdescÚhelpÚ
extensionsÚwildcardÚcan_read_testÚoutput_infoztiny.xyzr   Nr   )r   r   r   ÚsourcesÚappendr    r   r#   r!   r   Ú	enumerater3   r-   ÚremoveÚinsert)r
   Ú
open_dummyr   r$   r:   ÚindexÚsrcr	   r	   r   Útest_multiple_valid_readersL   s8    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j|ƒ x:ttjdd… ƒD ]$\}}|jdkrN|}tjj|ƒ P qNW tjt	dƒƒ}|j
ƒ }| j|jdƒ tjj||ƒ tj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&   z&mayavi.tests.test_registry.DummyReaderz&PLOT3D filezOpen a PLOT3D data datar'   zPLOT3D files (*.xyz)|*.xyzz1mayavi.tests.test_registry:DummyReader.check_readr(   r)   )r*   r+   r,   )
r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   NZPolyDataFileztiny.xyzr   )r   r   r   r7   r8   r9   r-   r:   r    r   r#   r!   r   r;   )r
   r<   r=   r>   Úpolyr   r$   r	   r	   r   Útest_no_valid_readert   s0    
z!TestRegistry.test_no_valid_readerN)
r   r   r   r   r   r   r"   r%   r?   rA   r	   r	   r	   r   r   !   s   (r   Ú__main__)ÚunittestÚmayavi.core.null_enginer   Úmayavi.core.registryr   Zmayavi.sources.plot3d_readerr   Úmayavi.core.metadatar   Úmayavi.core.pipeline_infor   Zmayavi.tests.commonr   r   ÚTestCaser   r   Úmainr	   r	   r	   r   Ú<module>   s   w