
    d.                        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ZddlmZ ddl	m
Z ddlmZ ddlZddlZddlZddlZ eej                  Z e ej        d          d                   Z e ej        d          d                   Zej                            d	d
          dk    a	 da	 dZ	 d Z ej        d          duZ ej        d          duZ  ej        d          duZ! ej        d          duZ" ej        d          duZ#d Z$d Z%d Z&d dZ'd!dZ(d Z) G d dej*                  Z+ G d d          Z, G d d          Z- G d de+          Z.dS )"z$Utilities for PyTables' test suites.    N)Path)perf_counter)Versionblosc   blosc2VERBOSEFALSETRUEFc                     d| v rda |                     d           d| v rda |                     d           d| v rda|                     d           | S )NverboseTsilentFz--heavy)r   removeheavy)argvs    3lib/python3.11/site-packages/tables/tests/common.py
parse_argvr   #   so     DI4HDIK    zliblzobzip2c                 f    | rt          d           nt          d           t          d           d S )Nz#Performing the complete test suite!aQ  Performing only a light (yet comprehensive) subset of the test suite.
If you want a more complete test, try passing the --heavy flag to this script
(or set the 'heavy' parameter in case you are using tables.test() call).
The whole suite will take more than 4 hours to complete on a relatively
modern CPU and around 512 MB of main memory.L-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=)print)r   s    r   print_heavyr   <   sI     178888 0 	1 	1 	1 
)r   c                  \	   t          d           t          dt          j        z             t          dt          j        d          d         z             t          dt          j        z             t          j        d          } t
          j        r4t          j                    }t          j	        d|          d	         }d
|z  }nd}t          dt
          j         d| d           | t          d| d          d           t          j        d          } | /t          d
                    | d         | d                              t          j        d          } | /t          d
                    | d         | d                              t          j        d          } | | d                                         d         }t          d
                    | d         |                     t          j                    }d t          |                                          D             }t          dd                    |          z             ddg}t          dd                    |          z             t          j        d          } | | d                                         d         }t          d 
                    | d         |                     t          j                    }d! t          |                                          D             }t          d"d                    |          z             ddg}t          d#d                    |          z             	 d	d$lm}	 t          d%|	z             n# t$          $ r Y nw xY wt          d&t&          j        z             t          d't+          j                    z             t          d(t&          j        z             t          d)t          j                                        z             t          d*t'          j                    z             t          d+t'          j                    z             t          d,t7          j                    z             t          d           t&          j                                         dS )-z;Print all the versions of software that PyTables relies on.r   zPyTables version:    %szHDF5 version:        %shdf5r   zNumPy version:       %sr   z[0-9.]+r   zusing VML/MKL %sznot using Intel's VML/MKLzNumexpr version:     z ()NzZlib version:        z (in Python interpreter)r   zLZO version:         {} ({})   r   zBZIP2 version:       {} ({})r   zBlosc version:       {} ({})c                 L    g | ]!\  }}d                      ||d                   "S z{} ({})r   format.0kvs      r   
<listcomp>z"print_versions.<locals>.<listcomp>f   s=     
 
 
*.!QIQ!%%
 
 
r   zBlosc compressors:   %sz, shuffle
bitshufflezBlosc filters:       %sr   zBlosc2 version:      {} ({})c                 L    g | ]!\  }}d                      ||d                   "S r!   r"   r$   s      r   r(   z"print_versions.<locals>.<listcomp>q   s=     
 
 
*.!QIQ!%%
 
 
r   zBlosc2 compressors:  %szBlosc2 filters:      %s)__version__zCython version:      %szPython version:      %szPlatform:            %szByte-ordering:       %szDetected cores:      %szDefault encoding:    %szDefault FS encoding: %szDefault locale:      (%s, %s))r   tbr,   which_lib_versionnpneuse_vmlget_vml_versionrefindallr#   splitblosc_get_complib_infosorteditemsjoinblosc2_get_complib_infoCython	Exceptionsysversionplatform	byteorderutilsdetect_number_of_coresgetdefaultencodinggetfilesystemencodinglocalegetdefaultlocalestdoutflush)
tinfovml_version	vml_avail
blosc_dateblosc_cinfoblosc_finfoblosc2_dateblosc2_cinfoblosc2_finfocython_versions
             r   print_versionsrS   I   si    
)	
#bn
4555	
#b&:6&B&B1&E
EFFF	
#bn
4555 ((E	z 0(**jK88;&4		/		
@".
@
@I
@
@
@AAAHeAhHHHIII ''E,33E!HeAhGGHHH ))E,33E!HeAhGGHHH ))E1X^^%%a(
,33E!HjIIJJJ/11
 
289J9J9L9L2M2M
 
 
 	'$))K*@*@@AAA ,/'$))K*@*@@AAA **EAhnn&&q),33E!HkJJKKK133
 
289K9K9M9M2N2N
 
 
 	'$))L*A*AABBB!<0'$))L*A*AABBB888888'.89999   	
#ck
1222	
#h&7&9&9
9::: 

#cm
3444	
#bh&E&E&G&G
GHHH	
#c&<&>&>
>???	
#c&?&A&A
ABBB	
)F,C,E,E
EFFF	) Js   $M= =
N
	N
c                 &    ddl m}  |d|           S )Nr   )resource_filenameztables.tests)pkg_resourcesrU   )filenamerU   s     r   test_filenamerX      s'    //////^X666r   c                 `    t           sdS |rt          | d           dS t          |            dS )z4Print out the `string` if verbose output is enabled.N )end)r   r   )stringnonls     r   verbosePrintr^      s?      f#fr   numpyc                    t          |d          s| |k    S t          | d          r| j        dk    r!t          |d          r|j        dk    r| |k    S | j        |j        k    r%t          rt          d| j        d|j                   dS t          |d          rO| j        j        dd         |j        j        dd         k    r%t          rt          d	| j        d|j                   dS t          | j                  dk    r9| d         |d         k    rdS t          rt          d| j        d|j                   dS | j        dk    ri|j        dk    rdS t          rSt          d
           t          dt          | j                             t          dt          |j                             dS | |k    }t          j
        |          }|st          rt          d           |S )z*Checks if two numerical objects are equal.shape zShape is not equal:z!=r   dtyper   Nzdtype is not equal:zlength is not equalzlen(a.data) ==>zlen(b.data) ==>z,Some of the elements in arrays are not equal)hasattrra   r   r   rc   strlensizedatar/   all)abflavorresults       r   allequalrn      s   
 1g AvQ   AGrMMG$$ %2()2Avw!' 	A'$@@@q q' qw{122!'+abb/AA 	A'$@@@q 17||qR5AbE>>1 E+QWdAGDDD1 	v{{6Q;;1 6+,,,'QV555'QV5551 1fFVF^^F >g ><===Mr   c                     t          |           }t          |          }t          | d          r| j        |j        k    s"t          ||          st          ||          sdS t	          j        | |k              S )zAre both `arr1` and `arr2` equal arrays?

    Arguments can be regular NumPy arrays, chararray arrays or
    structured arrays (including structured record arrays). They are
    checked for type and value equality.

    rc   F)typerd   rc   
issubclassr/   ri   )arr1arr2t1t2s       r   areArraysEqualrv      sy     
dB	dBT7## 
dj(@(@r2 )A",R"4"4 )Au6$$,r   c                   @     e Zd Z fdZd Zd Zd ZddZddZ xZ	S )	PyTablesTestCasec                     t                                                       | j        D ]'}| j        |         j        j        dk    r
d | j        |<   (d S )Ninstancemethod)supertearDown__dict__	__class____name__)selfkeyr~   s     r   r|   zPyTablesTestCase.tearDown   sZ    = 	* 	*C}S!+48HHH%)c"	* 	*r   c                 \    |                                                      d          d         S )zGet the name of this test case..idr5   r   s    r   _getNamezPyTablesTestCase._getName   !    wwyys##B''r   c                 \    |                                                      d          d         S )z>Get the name of the method currently running in the test case.r   r   r   s    r   _getMethodNamezPyTablesTestCase._getMethodName   r   r   c           	          t           re|                                 }|                                 }d| d| }t          d                    |dt          |          z                       dS dS )z;Print a nice header for the current test method if verbose.zRunning r   z{}
{}-N)r   r   r   r   r#   rf   )r   name
methodNametitles       r   _verboseHeaderzPyTablesTestCase._verboseHeader   sv      	<==??D,,..J2t22j22E(//%s5zz)9::;;;;;	< 	<r   Fc                 2   t           r t          d|           t          d|           |r%|                     |j        |j        k    d           n$|                     |j        |j        k    d           |                     |j        |j        k    d           d S )NzGroup 1:zGroup 2:(node1 and node2 have the same pathnames.1node1 and node2 does not have the same pathnames.z0node1 and node2 does not have the same children.)r   r   
assertTrue_v_pathname_v_childrenr   node1node2hardlinks       r   _checkEqualityGroupz$PyTablesTestCase._checkEqualityGroup   s     	%*e$$$*e$$$ 	EOO!U%66:< < < < OO!U%66CE E E 	!22>	@ 	@ 	@ 	@ 	@r   c                 R   t           r t          d|           t          d|           |r%|                     |j        |j        k    d           n$|                     |j        |j        k    d           |                     t	          |d d          |d d                    d           d S )NzLeaf 1:zLeaf 2:r   r   z.node1 and node2 does not have the same values.)r   r   r   r   rv   r   s       r   _checkEqualityLeafz#PyTablesTestCase._checkEqualityLeaf  s     	$)U###)U### 	EOO!U%66:< < < < OO!U%66CE E E 	58U111X..<	> 	> 	> 	> 	>r   F)
r   
__module____qualname__r|   r   r   r   r   r   __classcell__r~   s   @r   rx   rx      s        * * * * *( ( (( ( (< < <@ @ @ @ > > > > > > > >r   rx   c                   0     e Zd ZdZi Z fdZ fdZ xZS )TestFileMixinNc                     t                                                       t          j        | j        fd|                                 i| j        | _        d S )Nr   )r{   setUpr-   	open_fileh5fnamer   open_kwargsh5filer   r~   s    r   r   zTestFileMixin.setUp!  sU    lLE E $E373CE Er   c                 z    | j                                          t                                                       dS )zClose ``h5file``.N)r   closer{   r|   r   s    r   r|   zTestFileMixin.tearDown&  s5     	r   )r   r   r   r   r   r   r|   r   r   s   @r   r   r     s`        GKE E E E E
        r   r   c                   >     e Zd ZdZi Zd Z fdZ fdZddZ xZ	S )TempFileMixinwc                 R    t          j        |                                 d          S )Nz.h5)prefixsuffix)tempfilemktempr   r   s    r   _getTempFileNamezTempFileMixin._getTempFileName1  s    dmmooeDDDDr   c                     t                                                       |                                 | _        t	          j        | j        | j        fd|                                 i| j        | _	        dS )zSet ``h5file`` and ``h5fname`` instance attributes.

        * ``h5fname``: the name of the temporary HDF5 file.
        * ``h5file``: the writable, empty, temporary HDF5 file.

        r   N)
r{   r   r   r   r-   r   	open_moder   r   r   r   s    r   r   zTempFileMixin.setUp4  si     	,,..lL$.   04    r   c                     | j                                          d| _         t          | j                                                   t                                                       dS )z(Close ``h5file`` and remove ``h5fname``.N)r   r   r   r   unlinkr{   r|   r   s    r   r|   zTempFileMixin.tearDownB  sX     	T\!!###r   rc                 r    | j                                          t          j        | j        |fi || _         dS )zReopen ``h5file`` in the specified ``mode``.

        Returns a true or false value depending on whether the file was
        reopenend or not.  If not, nothing is changed.

        T)r   r   r-   r   r   )r   modekwargss      r   _reopenzTempFileMixin._reopenJ  s:     	l4<@@@@tr   )r   )
r   r   r   r   r   r   r   r|   r   r   r   s   @r   r   r   -  s        IKE E E             
 
 
 
 
 
 
 
r   r   c                   *    e Zd Z e            Z	 d ZdS )ShowMemTimec                 r   t          d                                                                          D ]q}|                    d          r(t	          |                                d                   }@|                    d          r(t	          |                                d                   }}|                    d          r(t	          |                                d                   }|                    d          r(t	          |                                d                   }|                    d          r)t	          |                                d                   }5|                    d          r't	          |                                d                   }st          d	t                      | j        z
             t          d
| 	                                z             t          d|dd|dd           t          d|dd|dd           t          d|dd|dd           dS )z$Showing memory and time consumption.z/proc/self/statuszVmSize:r   zVmRSS:zVmData:zVmStk:zVmExe:zVmLib:z
WallClock time:z Memory usage: ******* %s *******zVmSize: z>7z kB	VmRSS: z kBzVmData: z kB	VmStk: zVmExe:  z kB	VmLib: N)
r   	read_text
splitlines
startswithintr5   r   clocktrefr   )r   linevmsizevmrssvmdatavmstkvmexevmlibs           r   test00zShowMemTime.test00[  s    ,--7799DDFF 	- 	-Dy)) -TZZ\\!_--** 	-DJJLLO,,++ -TZZ\\!_--** -DJJLLO,,** -DJJLLO,,** -DJJLLO,,!577TY#677704==??BCCC========>>>========>>><<<<u<<<<=====r   N)r   r   r   r   r   r   rb   r   r   r   r   W  s1        577D7> > > > >r   r   r   )r_   )/__doc__osr3   r=   rE   r?   r   pathlibr   timer   r   packaging.versionr   unittestnumexprr0   r_   r/   tablesr-   hdf5_versionr.   blosc_versionblosc2_versionenvirongetr   r   show_memoryr   
zlib_avail	lzo_availbzip2_availblosc_availblosc2_availr   rS   rX   r^   rn   rv   TestCaserx   r   r   r   rb   r   r   <module>r      s   * * 				 				 



          & & & & & & % % % % % %             wr'',,W55a899--h77:;; *..G
,
,
6 2 9 .  $ "R!&))5
 B ''t3	"b"7++47"b"7++47#r#H--T9
 
 
@ @ @F7 7 7
   2 2 2 2j     &7> 7> 7> 7> 7>x( 7> 7> 7>t        ' ' ' ' ' ' ' 'T> > > > >" > > > > >r   