B
    ™i‚\—1  ã               @   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 ddl
mZ ddlZddlmZ G d	d
„ d
e	jeƒZG dd„ de	jeƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ de	jeƒZG dd„ de	jeƒZG dd„ de	jeƒZG dd „ d e	jeƒZG d!d"„ d"e	jeƒZ G d#d$„ d$e	jeƒZ!G d%d&„ d&e	jeƒZ"G d'd(„ d(e	jeƒZ#d)d*„ Z$e%d+krâddl&Z&e	 'e&j(¡ e	 )¡  ej*d*d, dS )-z3Test module for compatibility with plain HDF files.é    )Úabsolute_importN)Úcommon)Úallequal)ÚunittestÚtest_filename)ÚPyTablesTestCase)Úrangec               @   s    e Zd ZdZedƒZdd„ ZdS )ÚEnumTestCasezjTest for enumerated datatype.

    See ftp://ftp.hdfgroup.org/HDF5/current/src/unpacked/test/enum.c.

    zsmpl_enum.h5c                s„   |   d| jk¡ | j d¡}|   t|tjƒ¡ | ¡ ‰ t dddddg¡}|  ˆ |¡ t	| 
¡ ƒ}‡ fdd„d	D ƒ}|  ||¡ d S )
Nz	/EnumTestÚREDÚGREENÚBLUEÚWHITEÚBLACKc                s   g | ]}ˆ | ‘qS © r   )Ú.0Úname)Úenumr   ú;lib/python3.7/site-packages/tables/tests/test_hdf5compat.pyú
<listcomp>4   s    z%EnumTestCase.test.<locals>.<listcomp>)
r
   r   r   r   r   r
   r   r   r   r   )Ú
assertTrueÚh5fileÚget_nodeÚ
isinstanceÚtablesÚArrayZget_enumÚEnumÚassertEqualÚlistÚread)ÚselfÚarrZexpectedEnumÚdataÚexpectedDatar   )r   r   Útest(   s    
zEnumTestCase.testN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úh5fnamer#   r   r   r   r   r	      s   r	   c               @   s   e Zd ZdZdd„ ZdS )ÚNumericTestCasez­Test for several numeric datatypes.

    See
    ftp://ftp.ncsa.uiuc.edu/HDF/files/hdf5/samples/[fiu]l?{8,16,32,64}{be,le}.c
    (they seem to be no longer available).

    c             C   sÔ   |   d| jk¡ | j d¡}|   t|tjƒ¡ |  |jj| j¡ |  |j	| j	¡ |  |j
d¡ | ¡ }tjdddddgdddddgddddd	gdddd	d
gddd	d
dgdd	d
ddgg| jd}|   t ||¡¡ d S )Nz
/TestArray)é   é   r   é   é   é   é   r+   r*   é   é   é	   )Údtype)r   r   r   r   r   r   r   ÚatomÚtypeÚ	byteorderÚshaper   ÚnumpyÚarrayr   ÚareArraysEqual)r   r    r!   r"   r   r   r   r#   C   s    zNumericTestCase.testN)r$   r%   r&   r'   r#   r   r   r   r   r)   :   s   r)   c               @   s   e Zd ZedƒZdZdZdS )ÚF64BETestCasezsmpl_f64be.h5Úfloat64ÚbigN)r$   r%   r&   r   r(   r5   r6   r   r   r   r   r;   X   s   r;   c               @   s   e Zd ZedƒZdZdZdS )ÚF64LETestCasezsmpl_f64le.h5r<   ÚlittleN)r$   r%   r&   r   r(   r5   r6   r   r   r   r   r>   ^   s   r>   c               @   s   e Zd ZedƒZdZdZdS )ÚI64BETestCasezsmpl_i64be.h5Úint64r=   N)r$   r%   r&   r   r(   r5   r6   r   r   r   r   r@   d   s   r@   c               @   s   e Zd ZedƒZdZdZdS )ÚI64LETestCasezsmpl_i64le.h5rA   r?   N)r$   r%   r&   r   r(   r5   r6   r   r   r   r   rB   j   s   rB   c               @   s   e Zd ZedƒZdZdZdS )ÚI32BETestCasezsmpl_i32be.h5Úint32r=   N)r$   r%   r&   r   r(   r5   r6   r   r   r   r   rC   p   s   rC   c               @   s   e Zd ZedƒZdZdZdS )ÚI32LETestCasezsmpl_i32le.h5rD   r?   N)r$   r%   r&   r   r(   r5   r6   r   r   r   r   rE   v   s   rE   c               @   s    e Zd ZdZedƒZdd„ ZdS )ÚChunkedCompoundTestCasez»Test for a more complex and chunked compound structure.

    This is generated by a chunked version of the example in
    ftp://ftp.ncsa.uiuc.edu/HDF/files/hdf5/samples/compound2.c.

    zsmpl_compound_chunked.h5c          	   C   s  |   d| jk¡ | j d¡}|   t|tjƒ¡ |  |jddddddg¡ |  |jd d¡ |  |j	d j
d	¡ |  |jd d
¡ |  |j	d j
d	¡ |  |jd d¡ |  |j	d j
d¡ |  |jd d¡ |  |j	d j
d	¡ |  |jd d¡ |  |j	d j
d¡ |  |jd d¡ |  |j	d j
d	¡ xætt|ƒƒD ]Ö}|| }|  |d |¡ |  |d d¡ |d }xBtdƒD ]6}x.tdƒD ]"}|  || | || | ¡ q†W qxW | j|d |d dd |d }x&tdƒD ]}|  || |d ¡ qÜW |  |d tdƒ¡ q:W d S )Nz/CompoundChunkedZa_nameZc_nameZd_nameZe_nameZf_nameZg_namerD   r   ÚstringZint16)r+   é
   Zfloat32r<   )rH   Zuint8s   Hello!r+   rH   g¸…ëQ¸î?r*   )ZplacesgŸ<,ÔÚ@Úm)r   r   r   r   r   ÚTabler   ÚcolnamesÚcoltypesÚ	coldtypesr7   r   ÚlenZassertAlmostEqualÚord)r   ÚtblrI   ÚrowZdRowÚnÚoZfRowr   r   r   r#   †   s>    (zChunkedCompoundTestCase.testN)r$   r%   r&   r'   r   r(   r#   r   r   r   r   rF   |   s   rF   c               @   s    e Zd ZdZedƒZdd„ ZdS )ÚContiguousCompoundTestCasezpTest for support of native contiguous compound datasets.

    This example has been provided by Dav Clark.

    znon-chunked-table.h5c          	   C   sN  |   d| jk¡ | j d¡}|   t|tjƒ¡ |  |jddddg¡ |  |jd d¡ |  |j	d j
d¡ |  |jd d¡ |  |j	d j
d¡ |  |jd d¡ |  |j	d j
d¡ |  |jd d	¡ |  |j	d j
d¡ xb| ¡ D ]V}|  |d d
¡ |  |d d¡ |   t|d tjdd
gddƒ¡ |  |d d¡ qæW | j ¡  d S )Nz/test_var/structure variableÚaÚbÚcÚdr<   r   )r-   rG   g      @g      @g       @)r3   ó   d)r   r   r   r   r   rJ   r   rK   rL   rM   r7   Ziterrowsr   r8   r9   Úclose)r   rP   rQ   r   r   r   r#   ¼   s*    zContiguousCompoundTestCase.testN)r$   r%   r&   r'   r   r(   r#   r   r   r   r   rT   ³   s   rT   c               @   s    e Zd ZdZedƒZdd„ ZdS )Ú ContiguousCompoundAppendTestCasez?Test for appending data to native contiguous compound datasets.znon-chunked-table.h5c             C   s°   |   d| jk¡ | j ¡  t d¡}t | j|¡ yt 	|d¡| _W n t
k
rX   d S X | j d¡}|  tj|jddddgdfg¡ |  tj|jj¡ | j ¡  t |¡ d S )	Nz/test_var/structure variablez.h5rU   g      @g      @g       @g      @rX   )r   r   rZ   ÚtempfileZmktempÚshutilÚcopyr(   r   Z	open_fileÚIOErrorr   ZassertRaisesZHDF5ExtErrorÚappendrQ   ÚosÚremove)r   Zh5fname_copyrP   r   r   r   r#   á   s    


z%ContiguousCompoundAppendTestCase.testN)r$   r%   r&   r'   r   r(   r#   r   r   r   r   r[   Ü   s   r[   c               @   s    e Zd ZdZedƒZdd„ ZdS )ÚExtendibleTestCasez^Test for extendible datasets.

    See the example programs in the Introduction to HDF5.

    zsmpl_SDSextendible.h5c             C   s   |   d| jk¡ | j d¡}|   t|tjƒ¡ |  |jd¡ |  |jj	d¡ |  |j
d¡ |  |jd¡ |  t|ƒd¡ | ¡ }tjdddddgdddddgdddddgd	ddddgd	ddddgd	ddddgd	ddddgd	ddddgd	ddddgd	ddddgg
|jj	d
}|   t ||¡¡ d S )Nz/ExtendibleArrayr=   rD   )rH   r+   r   rH   r,   r.   r-   )r3   )r   r   r   r   r   ZEArrayr   r6   r4   r5   r7   ZextdimrN   r   r8   r9   r   r:   )r   r    r!   r"   r   r   r   r#     s*    zExtendibleTestCase.testN)r$   r%   r&   r'   r   r(   r#   r   r   r   r   rc   ø   s   rc   c               @   s    e Zd ZdZedƒZdd„ ZdS )ÚSzipTestCasez>Test for native HDF5 files with datasets compressed with szip.ztest_szip.h5c             C   s6   |   d| jk¡ | j d¡}d}|  t|jƒ|¡ d S )Nz
/dset_szipzhFilters(complib='szip', shuffle=False, bitshuffle=False, fletcher32=False, least_significant_digit=None))r   r   r   r   ÚreprÚfilters)r   r    rf   r   r   r   r#   "  s    zSzipTestCase.testN)r$   r%   r&   r'   r   r(   r#   r   r   r   r   rd     s   rd   c               @   s,   e Zd ZedƒZdd„ Zdd„ Zdd„ ZdS )	ÚMatlabFileTestCasezmatlab_file.matc             C   s,   | j  t d¡t d¡¡}|  |jd¡ d S )Nú/rU   )r.   r,   )r   r   ÚsixZ	text_typer   r7   )r   r9   r   r   r   Útest_unicode/  s    zMatlabFileTestCase.test_unicodec             C   s    | j  dd¡}|  |jd¡ d S )Nrh   rU   )r.   r,   )r   r   r   r7   )r   r9   r   r   r   Útest_string4  s    zMatlabFileTestCase.test_stringc             C   s,   | j  t d¡t d¡¡}|  |jd¡ d S )Nrh   rU   )r.   r,   )r   r   r8   Zstr_r   r7   )r   r9   r   r   r   Útest_numpy_str8  s    z!MatlabFileTestCase.test_numpy_strN)r$   r%   r&   r   r(   rj   rk   rl   r   r   r   r   rg   ,  s   rg   c               @   s$   e Zd ZedƒZdd„ Zdd„ ZdS )ÚObjectReferenceTestCaseztest_ref_array1.matc             C   s   | j  d¡}|  |jd¡ d S )Nz/ANN/my_arr)r,   r.   )r   r   r   r7   )r   r9   r   r   r   Útest_node_var@  s    z%ObjectReferenceTestCase.test_node_varc          	   C   s>   | j  d¡}|  t |d d d tjddgtjd¡¡ d S )Nz/ANN/my_arrr   )r3   )r   r   r   r   r:   r8   r9   Zuint64)r   r9   r   r   r   Útest_ref_utf_strD  s
    
z(ObjectReferenceTestCase.test_ref_utf_strN)r$   r%   r&   r   r(   rn   ro   r   r   r   r   rm   =  s   rm   c               @   s,   e Zd ZedƒZdd„ Zdd„ Zdd„ ZdS )	Ú ObjectReferenceRecursiveTestCaseztest_ref_array2.matc             C   s   | j  d¡}|  |jd¡ d S )Nz/var)r.   r,   )r   r   r   r7   )r   r9   r   r   r   Útest_varP  s    z)ObjectReferenceRecursiveTestCase.test_varc          
   C   sJ   | j  d¡}|  t |d d d tjdgdgdgdggtjd¡¡ d S )Nz/varr,   r   ét   ée   és   )r3   )r   r   r   r   r:   r8   r9   Úuint16)r   r9   r   r   r   Útest_ref_strT  s
    z-ObjectReferenceRecursiveTestCase.test_ref_strc             C   sZ   | j  d¡}|  t |d d d d d tjdgdgdgdgdgd	ggtjd
¡¡ d S )Nz/varr-   r   r,   éi   én   rt   éd   rs   )r3   )r   r   r   r   r:   r8   r9   ru   )r   r9   r   r   r   Útest_double_ref\  s
    z0ObjectReferenceRecursiveTestCase.test_double_refN)r$   r%   r&   r   r(   rq   rv   rz   r   r   r   r   rp   M  s   rp   c              C   s  t  ¡ } d}x t|ƒD ]ô}|  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t	¡¡ |  t  t
¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ |  t  t¡¡ qW | S )zCReturn a test suite consisting of all the test cases in the module.r,   )r   Z	TestSuiter   ZaddTestZ	makeSuiter	   r;   r>   r@   rB   rC   rE   rF   rT   r[   rc   rd   rg   rm   rp   )ZtheSuiteZniterÚir   r   r   Úsuited  s&    r|   Ú__main__)ZdefaultTest)+r'   Z
__future__r   ra   r]   r\   r8   r   Ztables.testsr   Ztables.tests.commonr   r   r   r   ZTestCaseri   Z	six.movesr   ZTestFileMixinr	   r)   r;   r>   r@   rB   rC   rE   rF   rT   r[   rc   rd   rg   rm   rp   r|   r$   ÚsysZ
parse_argvÚargvZprint_versionsÚmainr   r   r   r   Ú<module>   sD   7)%
