a
    =Â×_€5  ã                   @   sÚ  d 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 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ƒ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.é    N)Úcommon)Úallequal)ÚunittestÚtest_filename)ÚPyTablesTestCasec                   @   s    e Zd ZdZedƒZdd„ ZdS )ÚPaddedArrayTestCaseai  Test for H5T_COMPOUND (Table) datatype with padding.

    Regression test for issue gh-734

    itemsize.h5 was created with h5py with the array `expectedData` (see below)
    in the table `/Test`:
    'A' and 'B' are 4 + 4 bytes, with 8 bytes padding.

    $ h5ls -v itemsize.h5
    Test                     Dataset {3/3}
    Location:  1:800
    Links:     1
    Storage:   48 logical bytes, 48 allocated bytes, 100.00% utilization
    Type:      struct {
                   "A"                +0    native unsigned int
                   "B"                +4    native unsigned int
               } 16 bytes

    zitemsize.h5c                 C   sR   | j  d¡}| ¡ }tjg d¢ddgddgddgdd	œd
}|  t ||¡¡ d S )Nz/Test))é   é   )é   é   )é   é   ÚAÚBz<u4r   é   é   )ÚnamesZformatsZoffsetsÚitemsize©Zdtype)Úh5fileÚget_nodeÚreadÚnumpyÚarrayÚ
assertTruer   ÚareArraysEqual©ÚselfÚarrÚdataÚexpectedData© r!   ú;lib/python3.9/site-packages/tables/tests/test_hdf5compat.pyÚtest2   s    ÿþzPaddedArrayTestCase.testN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úh5fnamer#   r!   r!   r!   r"   r      s   r   c                   @   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                    sx   |   d| j¡ | j d¡}|  |tj¡ | ¡ ‰ t g d¢¡}|  ˆ |¡ t	| 
¡ ƒ}‡ fdd„dD ƒ}|  ||¡ d S )Nz	/EnumTest)ÚREDÚGREENÚBLUEÚWHITEÚBLACKc                    s   g | ]}ˆ | ‘qS r!   r!   )Ú.0Úname©Úenumr!   r"   Ú
<listcomp>P   s   z%EnumTestCase.test.<locals>.<listcomp>)
r+   r,   r-   r.   r/   r+   r,   r-   r.   r/   )ÚassertInr   r   ÚassertIsInstanceÚtablesÚArrayZget_enumÚEnumÚassertEqualÚlistr   )r   r   ZexpectedEnumr   r    r!   r2   r"   r#   E   s    
þzEnumTestCase.testNr$   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¡ | j d¡}|  |tj¡ |  |jj| j¡ |  |j	| j	¡ |  |j
d¡ | ¡ }tjg d¢g d¢g d¢g d¢g d¢g d¢g| jd	}|  t ||¡¡ d S )
Nz
/TestArray)é   é   )r   r   r
   r   r   )r   r
   r   r   r>   )r
   r   r   r>   r=   )r   r   r>   r=   é   )r   r>   r=   r?   é   )r>   r=   r?   r@   é	   r   )r5   r   r   r6   r7   r8   r:   ÚatomÚtypeÚ	byteorderÚshaper   r   r   r   r   r   r   r!   r!   r"   r#   `   s$    úúzNumericTestCase.testN)r%   r&   r'   r(   r#   r!   r!   r!   r"   r<   W   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)   rC   rD   r!   r!   r!   r"   rF   u   s   rF   c                   @   s   e Zd ZedƒZdZdZdS )ÚF64LETestCasezsmpl_f64le.h5rG   ÚlittleNrI   r!   r!   r!   r"   rJ   {   s   rJ   c                   @   s   e Zd ZedƒZdZdZdS )ÚI64BETestCasezsmpl_i64be.h5Úint64rH   NrI   r!   r!   r!   r"   rL      s   rL   c                   @   s   e Zd ZedƒZdZdZdS )ÚI64LETestCasezsmpl_i64le.h5rM   rK   NrI   r!   r!   r!   r"   rN   ‡   s   rN   c                   @   s   e Zd ZedƒZdZdZdS )ÚI32BETestCasezsmpl_i32be.h5Úint32rH   NrI   r!   r!   r!   r"   rO      s   rO   c                   @   s   e Zd ZedƒZdZdZdS )ÚI32LETestCasezsmpl_i32le.h5rP   rK   NrI   r!   r!   r!   r"   rQ   “   s   rQ   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¡ | j d¡}|  |tj¡ |  |jg 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¡ |  |jd d¡ |  |j	d j
d¡ tt|ƒƒD ]Ê}|| }|  |d |¡ |  |d d¡ |d }tdƒD ]2}tdƒD ]"}|  || | || | ¡ qrqf| j|d |d dd |d }tdƒD ]}|  || |d ¡ qÂ|  |d tdƒ¡ q*d S )Nz/CompoundChunked)Úa_nameÚc_nameÚd_nameÚe_nameÚf_nameÚg_namerS   rP   r!   rT   ÚstringrU   Zint16)r>   é
   rV   Zfloat32rW   rG   )rZ   rX   Zuint8s   Hello!r>   rZ   g¸…ëQ¸î?r=   )ZplacesgŸ<,ÔÚ@Úm)r5   r   r   r6   r7   ÚTabler:   ÚcolnamesÚcoltypesÚ	coldtypesrE   ÚrangeÚlenZassertAlmostEqualÚord)r   Útblr[   ÚrowZdRowÚnÚoZfRowr!   r!   r"   r#   £   s@    þ$zChunkedCompoundTestCase.testNr$   r!   r!   r!   r"   rR   ™   s   rR   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.

    únon-chunked-table.h5c              	   C   s@  |   d| j¡ | j d¡}|  |tj¡ |  |jg 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¡ | ¡ D ]V}|  |d d¡ |  |d d¡ |  t|d tjddgddƒ¡ |  |d	 d¡ qÚ| j ¡  d S )Nú/test_var/structure variable)ÚaÚbÚcÚdrj   rG   r!   rk   rl   )r
   rm   rY   ç      @ç      @ç       @r   ó   d)r5   r   r   r6   r7   r\   r:   r]   r^   r_   rE   Ziterrowsr   r   r   r   Úclose)r   rc   rd   r!   r!   r"   r#   Ù   s.    þÿ
zContiguousCompoundTestCase.testNr$   r!   r!   r!   r"   rg   Ð   s   rg   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.rh   c                 C   s®   |   d| j¡ | j ¡  t d¡}t | j|¡ zt 	|d¡| _W n t
yV   Y d S 0 | j d¡}|  tj|jddddgdfg¡ |  tj|jj¡ | j ¡  t |¡ d S )	Nri   z.h5rj   ro   g      @rp   rn   rm   )r5   r   rr   ÚtempfileZmktempÚshutilÚcopyr)   r7   Z	open_fileÚIOErrorr   ZassertRaisesZHDF5ExtErrorÚappendrd   ÚosÚremove)r   Zh5fname_copyrc   r!   r!   r"   r#   þ   s    

ÿ
z%ContiguousCompoundAppendTestCase.testNr$   r!   r!   r!   r"   rs   ù   s   rs   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¡ | j d¡}|  |tj¡ |  |jd¡ |  |jj	d¡ |  |j
d¡ |  |jd¡ |  t|ƒd¡ | ¡ }tjg d¢g d¢g d¢g d	¢g d	¢g d	¢g d	¢g d	¢g d	¢g d	¢g
|jj	d
}|  t ||¡¡ d S )Nz/ExtendibleArrayrH   rP   )rZ   r>   r   rZ   )r   r   r   r   r   )r   r   r   r   r   )r
   r   r   r   r   r   )r5   r   r   r6   r7   ZEArrayr:   rD   rB   rC   rE   Zextdimra   r   r   r   r   r   r   r   r!   r!   r"   r#     s0    ö
özExtendibleTestCase.testNr$   r!   r!   r!   r"   r{     s   r{   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   s4   |   d| j¡ | j d¡}d}|  t|jƒ|¡ d S )Nz
/dset_szipzhFilters(complib='szip', shuffle=False, bitshuffle=False, fletcher32=False, least_significant_digit=None))r5   r   r   r:   ÚreprÚfilters)r   r   r~   r!   r!   r"   r#   ?  s    zSzipTestCase.testNr$   r!   r!   r!   r"   r|   :  s   r|   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  dd¡}|  |jd¡ d S ©Nú/rj   ©r   r   ©r   r   r:   rE   ©r   r   r!   r!   r"   Útest_unicodeL  s    zMatlabFileTestCase.test_unicodec                 C   s    | j  dd¡}|  |jd¡ d S r€   rƒ   r„   r!   r!   r"   Útest_stringQ  s    zMatlabFileTestCase.test_stringc                 C   s,   | j  t d¡t d¡¡}|  |jd¡ d S r€   )r   r   r   Zstr_r:   rE   r„   r!   r!   r"   Útest_numpy_strU  s    z!MatlabFileTestCase.test_numpy_strN)r%   r&   r'   r   r)   r…   r†   r‡   r!   r!   r!   r"   r   I  s   r   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 )Nú/ANN/my_arr)r   r   rƒ   r„   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 )Nr‰   r   r   )r   r   r   r   r   r   r   Zuint64r„   r!   r!   r"   Útest_ref_utf_stra  s    
ÿþz(ObjectReferenceTestCase.test_ref_utf_strN)r%   r&   r'   r   r)   rŠ   r‹   r!   r!   r!   r"   rˆ   Z  s   rˆ   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 )Nú/varr‚   rƒ   r„   r!   r!   r"   Útest_varm  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 )Nr   r   r   ét   ée   és   r   ©r   r   r   r   r   r   r   Zuint16r„   r!   r!   r"   Útest_ref_strq  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 )Nr   r
   r   r   éi   én   r‘   éd   r   r   r’   r„   r!   r!   r"   Útest_double_refy  s    ÿþz0ObjectReferenceRecursiveTestCase.test_double_refN)r%   r&   r'   r   r)   rŽ   r“   r—   r!   r!   r!   r"   rŒ   j  s   rŒ   c                  C   s   t  ¡ } d}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¡¡ |  t  t¡¡ q| S )zCReturn a test suite consisting of all the test cases in the module.r   )r   Z	TestSuiter`   ZaddTestZ	makeSuiter   r*   rF   rJ   rL   rN   rO   rQ   rR   rg   rs   r{   r|   r   rˆ   rŒ   )ZtheSuiteZniterÚir!   r!   r"   Úsuite  s(    r™   Ú__main__)ZdefaultTest)'r(   ry   ru   rt   r   r7   Ztables.testsr   Ztables.tests.commonr   r   r   r   ZTestCaseZTestFileMixinr   r*   r<   rF   rJ   rL   rN   rO   rQ   rR   rg   rs   r{   r|   r   rˆ   rŒ   r™   r%   ÚsysZ
parse_argvÚargvZprint_versionsÚmainr!   r!   r!   r"   Ú<module>   s@    7)%
