
    d4                        d Z ddlZddlZddlmZ ddlZddlZddl	m
Z
  G d de
j        e
j                  Z G d de
j        e
j                  Z G d	 d
e
j        e
j                  Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de
j        e
j                  Z G d de
j        e
j                  Z G d de
j        e
j                  Z G d de
j        e
j                  Z G d d e
j        e
j                  Z G d! d"e
j        e
j                  Z G d# d$e
j        e
j                  Z G d% d&e
j        e
j                  Zd' Zed(k    rEddl Z  e
j!        e j"                    e
j#                     e
j$        %                    d)*           dS dS )+z3Test module for compatibility with plain HDF files.    N)Path)commonc                   8    e Zd ZdZ ej        d          Z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                     | j                             d          }|                                }t          j        g dddgddgddgdd	
          }|                     t          j        ||                     d S )Nz/Test))      )      )      ABz<u4r         )namesformatsoffsetsitemsizedtype)h5fileget_nodereadnparray
assertTruer   areArraysEqualselfarrdataexpectedDatas       <lib/python3.11/site-packages/tables/tests/test_hdf5compat.pytestzPaddedArrayTestCase.test#   s    k""7++xxzzx''' #JE5> !f"6 67 7 7 	-dLAABBBBB    N__name__
__module____qualname____doc__r   test_filenameh5fnamer%    r&   r$   r   r      sF         & #f"=11GC C C C Cr&   r   c                   8    e Zd ZdZ ej        d          Zd ZdS )EnumTestCasezjTest for enumerated datatype.

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

    zsmpl_enum.h5c                    |                      d| j                   | j                            d          }|                     |t          j                   |                                t	          j        g d          }|                     |           t          |
                                          }fddD             }|                     ||           d S )Nz	/EnumTest)REDGREENBLUEWHITEBLACKc                      g | ]
}|         S r.   r.   ).0nameenums     r$   
<listcomp>z%EnumTestCase.test.<locals>.<listcomp>A   s*     8 8 8DJ8 8 8r&   )
r2   r3   r4   r5   r6   r2   r3   r4   r5   r6   )assertInr   r   assertIsInstancetbArrayget_enumEnumassertEquallistr   )r    r!   expectedEnumr"   r#   r:   s        @r$   r%   zEnumTestCase.test6   s    k4;///k"";//c28,,,||~~wIIIJJ|,,,CHHJJ8 8 8 878 8 8 	|,,,,,r&   Nr'   r.   r&   r$   r0   r0   -   sA          #f">22G- - - - -r&   r0   c                       e Zd ZdZd ZdS )NumericTestCasezTest 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           	      B   |                      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        	          }|                     t          j        ||                     d S )
Nz
/TestArray)      )r   r   r
   r   r   )r   r
   r   r   rI   )r
   r   r   rI   rH   )r   r   rI   rH      )r   rI   rH   rJ      )rI   rH   rJ   rK   	   r   )r<   r   r   r=   r>   r?   rB   atomtype	byteordershaper   r   r   r   r   r   r   s       r$   r%   zNumericTestCase.testQ   s   lDK000k""<00c28,,,	222777F+++xxzzxOOOOOOOOOOOO! %)I/ / / 	-dLAABBBBBr&   N)r(   r)   r*   r+   r%   r.   r&   r$   rF   rF   H   s2         C C C C Cr&   rF   c                   6    e Zd Z ej        d          ZdZdZdS )F64BETestCasezsmpl_f64be.h5float64bigNr(   r)   r*   r   r,   r-   rN   rO   r.   r&   r$   rR   rR   f   s*        "f"?33GDIIIr&   rR   c                   6    e Zd Z ej        d          ZdZdZdS )F64LETestCasezsmpl_f64le.h5rS   littleNrU   r.   r&   r$   rW   rW   l   s*        "f"?33GDIIIr&   rW   c                   6    e Zd Z ej        d          ZdZdZdS )I64BETestCasezsmpl_i64be.h5int64rT   NrU   r.   r&   r$   rZ   rZ   r   *        "f"?33GDIIIr&   rZ   c                   6    e Zd Z ej        d          ZdZdZdS )I64LETestCasezsmpl_i64le.h5r[   rX   NrU   r.   r&   r$   r^   r^   x   *        "f"?33GDIIIr&   r^   c                   6    e Zd Z ej        d          ZdZdZdS )I32BETestCasezsmpl_i32be.h5int32rT   NrU   r.   r&   r$   ra   ra   ~   r\   r&   ra   c                   6    e Zd Z ej        d          ZdZdZdS )I32LETestCasezsmpl_i32le.h5rb   rX   NrU   r.   r&   r$   rd   rd      r_   r&   rd   c                   8    e Zd ZdZ ej        d          Zd ZdS )ChunkedCompoundTestCasezTest 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                    |                      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 ]<}t          d          D ]*}|                     ||         |         ||z   |z              +=|                     |d         |dz  d           |d         }t          d          D ]!}|                     ||         |dz             "|                     |d         t          d                     d S )Nz/CompoundChunked)a_namec_named_namee_namef_nameg_namerh   rb   r.   ri   stringrj   int16)rI   
   rk   float32rl   rS   )rp   rm   uint8s   Hello!rI   rp   gQ?rH   )placesg<,@m)r<   r   r   r=   r>   TablerB   colnamescoltypes	coldtypesrP   rangelenassertAlmostEqualord)r    tblrt   rowdRownofRows           r$   r%   zChunkedCompoundTestCase.test   s*   ($+666k""#566c28,,,LHHH	J 	J 	J 	h/999x06;;;h/:::x06;;;h/999x06@@@h/;;;x06;;;h/;;;x06>>>h/999x06;;;s3xx 	6 	6Aa&C S]A...S]I666x=D1XX < <r < <A$$T!WQZQ;;;;<""3x=!d(1"EEEx=D2YY ? ?&&tAwI>>>>S]CHH5555	6 	6r&   Nr'   r.   r&   r$   rf   rf      sB          #f"#=>>G*6 *6 *6 *6 *6r&   rf   c                   8    e Zd ZdZ ej        d          Zd ZdS )ContiguousCompoundTestCasezpTest for support of native contiguous compound datasets.

    This example has been provided by Dav Clark.

    non-chunked-table.h5c           
         |                      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 ]}|                     |d         d           |                     |d         d           |                     t          j        |d         t          j        ddgd                               |                     |d	         d           | j                                         d S )N/test_var/structure variable)abcdr   rS   r.   r   r   )r
   r   rn         @      @       @r      d)r<   r   r   r=   r>   ru   rB   rv   rw   rx   rP   iterrowsr   r   allequalr   r   close)r    r}   r~   s      r$   r%   zContiguousCompoundTestCase.test   s*   4dkBBBk""#ABBc28,,,L   	" 	" 	" 	c*I666s+12666c*I666s+12666c*I666s+14888c*H555s+12666<<>> 	- 	-CSXs+++SXs+++OOFOC"(C:Y???A A B B BSXt,,,,r&   Nr'   r.   r&   r$   r   r      sB          #f"#9::G    r&   r   c                   8    e Zd ZdZ ej        d          Zd ZdS ) ContiguousCompoundAppendTestCasez?Test for appending data to native contiguous compound datasets.r   c                 z   |                      d| j                   | j                                         t          j        d          }t          j        | j        |           	 t          j	        |d          | _        n# t          $ r Y d S w xY w| j                            d          }|                     t          j        |j        ddddgdfg           |                     t          j        |j        j                   | j                                         t!          |                                           d S )	Nr   z.h5r   r   g      @r   r   r   )r<   r   r   tempfilemktempshutilcopyr-   r>   	open_fileOSErrorr   assertRaisesHDF5ExtErrorappendr~   r   unlink)r    h5fname_copyr}   s      r$   r%   z%ContiguousCompoundAppendTestCase.test   s)   4dkBBBu--DL,///	,|S99DKK 	 	 	FF	 k""#ABB"/3:sCj#67	9 	9 	9 	"/37>:::\!!#####s   $A? ?
BBNr'   r.   r&   r$   r   r      s<        II"f"#9::G$ $ $ $ $r&   r   c                   8    e Zd ZdZ ej        d          Zd ZdS )ExtendibleTestCasez^Test for extendible datasets.

    See the example programs in the Introduction to HDF5.

    zsmpl_SDSextendible.h5c                    |                      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	        
          }|                     t#          j        ||                     d S )Nz/ExtendibleArrayrT   rb   )rp   rI   r   rp   )r   r   r   r   r   )r   r   r   r   r   )r
   r   r   r   r   r   )r<   r   r   r=   r>   EArrayrB   rO   rM   rN   rP   extdimrz   r   r   r   r   r   r   r   s       r$   r%   zExtendibleTestCase.test  sc   ($+666k""#566c29---...000G,,,Q'''S2&&&xxzzxOOOOOOOOOOOOOOOOOOOO
! %(HM
3 
3 
3 	-dLAABBBBBr&   Nr'   r.   r&   r$   r   r     sG          #f"#:;;GC C C C Cr&   r   c                   8    e Zd ZdZ ej        d          Zd ZdS )SzipTestCasez>Test for native HDF5 files with datasets compressed with szip.ztest_szip.h5c                     |                      d| j                   | 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   rB   reprfilters)r    r!   r   s      r$   r%   zSzipTestCase.test2  s[    lDK000k""<00Eck**G44444r&   Nr'   r.   r&   r$   r   r   -  s;        HH"f">22G5 5 5 5 5r&   r   c                   @    e Zd Z ej        d          Zd Zd Zd ZdS )MatlabFileTestCasezmatlab_file.matc                 r    | j                             dd          }|                     |j        d           d S N/r   r   r   r   r   rB   rP   r    r   s     r$   test_unicodezMatlabFileTestCase.test_unicode?  7    $$S#..f-----r&   c                 r    | j                             dd          }|                     |j        d           d S r   r   r   s     r$   test_stringzMatlabFileTestCase.test_stringD  r   r&   c                     | j                             t          j        d          t          j        d                    }|                     |j        d           d S r   )r   r   r   str_rB   rP   r   s     r$   test_numpy_strz!MatlabFileTestCase.test_numpy_strH  sG    $$RWS\\273<<@@f-----r&   N)	r(   r)   r*   r   r,   r-   r   r   r   r.   r&   r$   r   r   <  sT        "f"#455G. . .
. . .. . . . .r&   r   c                   :    e Zd Z ej        d          Zd Zd ZdS )ObjectReferenceTestCaseztest_ref_array1.matc                 p    | j                             d          }|                     |j        d           d S )N/ANN/my_arr)r   r   r   r   s     r$   test_node_varz%ObjectReferenceTestCase.test_node_varP  s5    $$]33f-----r&   c           	          | j                             d          }|                     t          j        |d         d         d         t          j        ddgt
          j                                       d S )Nr   r   r   )r   r   r   r   r   r   r   uint64r   s     r$   test_ref_utf_strz(ObjectReferenceTestCase.test_ref_utf_strT  sq    $$]33-!HQKNBHaV29===? ? 	@ 	@ 	@ 	@ 	@r&   N)r(   r)   r*   r   r,   r-   r   r   r.   r&   r$   r   r   M  sJ        "f"#899G. . .@ @ @ @ @r&   r   c                   @    e Zd Z ej        d          Zd Zd Zd ZdS ) ObjectReferenceRecursiveTestCaseztest_ref_array2.matc                 p    | j                             d          }|                     |j        d           d S )N/varr   r   r   s     r$   test_varz)ObjectReferenceRecursiveTestCase.test_var_  s5    $$V,,f-----r&   c                     | j                             d          }|                     t          j        |d         d         d         t          j        dgdgdgdggt
          j                                       d S )Nr   r   r   t   e   s   r   r   r   r   r   r   r   r   uint16r   s     r$   test_ref_strz-ObjectReferenceRecursiveTestCase.test_ref_strc  s    $$V,,-!HQKNHsecUSEC51CCCE E 	F 	F 	F 	F 	Fr&   c                    | j                             d          }|                     t          j        |d         d         d         d         d         t          j        dgdgdgdgdgd	ggt
          j        
                               d S )Nr   r
   r   r   i   n   r   d   r   r   r   r   s     r$   test_double_refz0ObjectReferenceRecursiveTestCase.test_double_refj  s    $$V,,-!HQKN1a HsecUSEC53%#?9& & &' ' 	( 	( 	( 	( 	(r&   N)	r(   r)   r*   r   r,   r-   r   r   r   r.   r&   r$   r   r   [  sW        "f"#899G. . .F F F( ( ( ( (r&   r   c                  N   t           j                                        } d}t          |          D ]s}|                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                               |                     t           j                            t                                |                     t           j                            t"                               |                     t           j                            t$                               |                     t           j                            t&                               |                     t           j                            t(                               |                     t           j                            t*                               u| S )zCReturn a test suite consisting of all the test cases in the module.r   )r   unittest	TestSuitery   addTest	makeSuiter   r0   rR   rW   rZ   r^   ra   rd   rf   r   r   r   r   r   r   r   )theSuiteniteris      r$   suiter   r  s    ((**HE5\\ I I223FGGHHH22<@@AAA22=AABBB22=AABBB22=AABBB22=AABBB22=AABBB22=AABBB223JKKLLL223MNNOOOO%%&FGG	I 	I 	I223EFFGGG22<@@AAA223EFFGGG223JKKLLLO%%&FGG	I 	I 	I 	I Or&   __main__r   )defaultTest)&r+   r   r   pathlibr   numpyr   tablesr>   tables.testsr   TestFileMixinPyTablesTestCaser   r0   rF   rR   rW   rZ   r^   ra   rd   rf   r   r   r   r   r   r   r   r   r(   sys
parse_argvargvprint_versionsr   mainr.   r&   r$   <module>r      s   9 9                      C C C C C&.0G C C C@- - - - -6')@ - - -6C C C C Cf*F,C C C C<    O       O       O       O       O       O   46 46 46 46 46f2F4K 46 46 46n' ' ' ' '!5!'!8' ' 'T$ $ $ $ $v';'-'>$ $ $:"C "C "C "C "C-v/F "C "C "CJ5 5 5 5 56')@ 5 5 5. . . . .-v/F . . ."@ @ @ @ @f2F4K @ @ @( ( ( ( (v';'-'>( ( (.  : zJJJFchF
OW-----	 r&   