a
    =_                      @   s  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
mZmZ d dl
mZ G dd deZee	j d	G d
d deZee	j d	G dd deZee	j d	G dd deZee	j d	G dd deZee	j d	G dd d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	jeZG dd de	jeZG dd deZG d d! d!eZd"d# Z e!d$krd dl"Z"e	#e"j$ e	%  ej&d#d% dS )&    N)FlavorWarning)common)allequal)unittesttest_filename)PyTablesTestCasec                   @   s   e Zd Zdd ZdS )BackCompatTablesTestCasec                 C   s   t jr tdd td| jj  t 0 tjdtd t	
t| jd}W d   n1 s^0    Y  zd|d}d	d
 |D }t jrtd|jd|j tdt tdt| | t|d W |  n
|  0 dS )z9Checking backward compatibility of old formats of tables.
<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=zRunning %s.test01_readTable...ignore)categoryrNz/tuple0c                 S   s   g | ]}|d  qS )Zvar2 ).0recr   r   ;lib/python3.9/site-packages/tables/tests/test_backcompat.py
<listcomp>$       z=BackCompatTablesTestCase.test01_readTable.<locals>.<listcomp>zNrows in:zLast record in table ==>z$Total selected records in table ==> d   )r   verboseprint	__class____name__warningscatch_warningsfilterwarningsUserWarningtables	open_filer   h5fnameget_nodeZ_v_pathnameZnrowsr   lenassertEqualclose)selfh5filetableresultr   r   r   test01_readTable   s    

0

z)BackCompatTablesTestCase.test01_readTableN)r   
__module____qualname__r)   r   r   r   r   r      s   r   zlzo not availablec                   @   s   e Zd ZdZdS )Table2_1LZOzTable2_1_lzo_nrv2e_shuffle.h5Nr   r*   r+   r    r   r   r   r   r,   /   s   r,   c                   @   s   e Zd ZdZdS )Tables_LZO1zTables_lzo1.h5Nr-   r   r   r   r   r.   5   s   r.   c                   @   s   e Zd ZdZdS )Tables_LZO1_shufflezTables_lzo1_shuffle.h5Nr-   r   r   r   r   r/   :   s   r/   c                   @   s   e Zd ZdZdS )Tables_LZO2zTables_lzo2.h5Nr-   r   r   r   r   r0   @   s   r0   c                   @   s   e Zd ZdZdS )Tables_LZO2_shufflezTables_lzo2_shuffle.h5Nr-   r   r   r   r   r1   E   s   r1   c                       s(   e Zd ZdZ fddZdd Z  ZS )BackCompatAttrsTestCasezzerodim-attrs-%s.h5c                    s$   t | j| j | _tt|   d S )N)r   FILENAMEformatr    superr2   setUp)r%   r   r   r   r6   O   s    zBackCompatAttrsTestCase.setUpc                 C   s   t jr tdd td| jj  | jd}tjddd}tjdgdd}| j	dkr| 
t|jj| | 
t|jj| | |jjd nF| j	d	kr| 
t|jj| | 
t|jj| | 
t|jj| d
S )z>Checking backward compatibility of old formats for attributes.r	   r
   zRunning %s.test01_readAttr...z/a   Zint32)Zdtype1.31.4N)r   r   r   r   r   r&   r!   numpyZarrayr4   Z
assertTruer   attrsZarrdim1Z	arrscalarr#   Zpythonscalar)r%   aZscalarZvectorr   r   r   test01_readAttrS   s    


z'BackCompatAttrsTestCase.test01_readAttr)r   r*   r+   r3   r6   r>   __classcell__r   r   r7   r   r2   L   s   r2   c                   @   s   e Zd ZdZdS )	Attrs_1_3r9   Nr   r*   r+   r4   r   r   r   r   r@   h   s   r@   c                   @   s   e Zd ZdZdS )	Attrs_1_4r:   NrA   r   r   r   r   rB   l   s   rB   c                   @   s   e Zd ZedZdd ZdS )VLArrayTestCasezflavored_vlarrays-format1.6.h5c                 C   sH   | j jj}| |jd | j jj}| |jd | |d g d dS )z<Checking backward compatibility with old flavors of VLArray.numericpythonr8   )   5   6s   77N)r&   rootvlarray1r#   flavorvlarray2)r%   rI   rK   r   r   r   test01_backCompats   s
    

z!VLArrayTestCase.test01_backCompatN)r   r*   r+   r   r    rL   r   r   r   r   rC   p   s   rC   c                   @   s$   e Zd ZedZdd Zdd ZdS )TimeTestCaseztime-table-vlarray-1_x.h5c                 C   s   | j jj}| |jd dS )z?Checking backward compatibility with old TimeXX types (tables).littleN)r&   rH   r'   r#   	byteorder)r%   r'   r   r   r   test00_table   s    
zTimeTestCase.test00_tablec                 C   s4   | j jj}| |jd | j jj}| |jd dS )zAChecking backward compatibility with old TimeXX types (vlarrays).rN   N)r&   rH   vlarray4r#   rO   )r%   rQ   Zvlarray8r   r   r   test01_vlarray   s    

zTimeTestCase.test01_vlarrayN)r   r*   r+   r   r    rP   rR   r   r   r   r   rM      s   rM   c                   @   s    e Zd ZdZdd Zdd ZdS )OldFlavorsTestCase01Fc                 C   s   t d}t||}| |jjjd | |jjjd | |jjjd | |jj	jd | |jj
jd | |jjjd W d   n1 s0    Y  dS )z3Checking opening of (X)Array (old 'numeric' flavor)oldflavor_numeric.h5rD   rE   N)r   r   r   r#   rH   array1rJ   array2carray1carray2rI   rK   )r%   r    r&   r   r   r   test01_open   s    z OldFlavorsTestCase01.test01_openc              	   C   sd  t d}td}t|| z2t|d}| t|j	j
jdd |j	jdd |j	jdd |j	jdd |j	jdd	 |j	jdd
 | jr|  t|}n|  | |j	jjd | |j	jjd | |j	jjd | |j	jjd | |j	jjd | |j	jjd W d   n1 s<0    Y  W t| nt| 0 dS )z2Checking (X)Array.copy() method ('numetic' flavor)rT   z.h5zr+/
array1copy
array2copycarray1copycarray2copyvlarray1copyvlarray2copyrD   rE   N)r   tempfileZmktempshutilcopyr   r   ZassertWarnsr   rH   rU   rV   rW   rX   rI   rK   r$   flushr#   r[   rJ   r\   r]   r^   r_   r`   osremove)r%   ZsrcfileZtmpfiler&   r   r   r   test02_copy   s0    
4z OldFlavorsTestCase01.test02_copyN)r   r*   r+   r$   rY   rg   r   r   r   r   rS      s   rS   c                   @   s   e Zd ZdZdS )OldFlavorsTestCase02TN)r   r*   r+   r$   r   r   r   r   rh      s   rh   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 q| S )Nr8   )r   Z	TestSuiterangeZaddTestZ	makeSuiterC   rM   rS   rh   r,   r.   r/   r0   r1   )ZtheSuiteZniternr   r   r   suite   s    rk   __main__)ZdefaultTest)'re   rb   ra   r   r;   r   Ztables.exceptionsr   Ztables.testsr   Ztables.tests.commonr   r   r   r   ZTestCaser   ZskipIfZ	lzo_availr,   r.   r/   r0   r1   ZTestFileMixinr2   r@   rB   rC   rM   rS   rh   rk   r   sysZ
parse_argvargvZprint_versionsmainr   r   r   r   <module>   sD   6
