B
    i\                 @   s,  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d dlZd dlm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm Z  d
ddddddgZ!ej"dkre!dddddddg7 Z!ne!ddddddg7 Z!e!dg7 Z!e#edr(e!$d e#eds@e#edrJe!$d e#edsbe#ed rle!$d! d"d#d$ej% 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/d0 d0e&Z+G d1d2 d2e&Z,G d3d4 d4e&Z-G d5d6 d6ej.eZ/G d7d8 d8ej0Z1G d9d: d:ej.eZ2G d;d< d<ej0Z3G d=d> d>ej0Z4G d?d@ d@ej.eZ5G dAdB dBe5Z6G dCdD dDe5Z7G dEdF dFej.eZ8G dGdH dHe8Z9G dIdJ dJe8Z:G dKdL dLej.eZ;G dMdN dNe;Z<G dOdP dPe;Z=dQdR Z>e?dSkr(e@ejA eB  ejCdRdT dS )U    )print_function)absolute_importN)	StringColBoolColFloatCol
ComplexColEnumColInt8ColUInt8ColInt16Col	UInt16ColInt32Col	UInt32ColInt64Col
Float32Col
Float64Col	Time64Col)common)allequal)unittest)PyTablesTestCase)rangebhilqfdZwin32BHILQFDZb1ZFloat16AtomeZFloat96AtomZFloat128AtomgZComplex192AtomZConplex256AtomG<>)littleZbigc               @   s<   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dS )BasicTestCasezmBasic test for all the supported typecodes present in NumPy.

    All of them are included on PyTables.

    r   c          	   C   s  t jr0tdd td|jj dd td| j td| _zt	j
| jdd	*| _| jj| _|}| j| jd
|d W d Q R X t	j
| jdd	<| _| jj| _| jj }t|dstjj||jjd}t jr2td| td|j td|j td|jj td| td|j td|j td|jj | jjjj}| t|t| | |j|j | |j| jjj | |j|j |jjd dkr| |d n| |jjj| | t||d W d Q R X W d tj| jrt | j X d S )N
z<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=z)Running test for array with typecode '%s' )endzfor class check:z.h5w)mode	somearrayz
Some arrayrshape)dtypezArray written:zArray written shape:zArray written itemsize:zArray written type:zArray read:zArray read shape:zArray read itemsize:zArray read type:r   Sstringnumpy)!r   verboseprintr5   chartitletempfileZmktemph5fnametables	open_fileh5filerootcreate_arrayr2   readhasattrnparraystrr4   itemsizeZatomtypeassertEqualbasename
assertTruer   ospathexistsremove)selfZ	testArrayar   type_ rV   6lib/python3.7/site-packages/tables/tests/test_numpy.py	WriteRead3   sJ    





 zBasicTestCase.WriteReadc             C   s*   t | jdtt| j }| | dS )z2Data integrity during recovery (character objects)r6   N)rF   rG   	tupleCharrH   lenrX   )rS   rT   rV   rV   rW   test00_charo   s    zBasicTestCase.test00_charc             C   sh   t | jdtt| j }|jdkr,|}n.|ddd }|jd dkrZ| |jd d | | dS )zAData integrity during recovery (non-contiguous character objects)r6   rV   N   r   
CONTIGUOUSF)	rF   rG   rY   rH   rZ   r4   rK   flagsrX   )rS   rT   r   rV   rV   rW   test01_char_ncu   s    
zBasicTestCase.test01_char_ncc             C   sB   x<t D ]4}| jjr | j|}ntj| j|d}| | qW dS )z0Data integrity during recovery (numerical types))r5   N)	typecodestupleIntr4   astyperF   rG   rX   )rS   typecoderT   rV   rV   rW   test02_types   s
    
zBasicTestCase.test02_typesc             C   s   x~t D ]v}| jjr | j|}ntj| j|d}t|jdkrDtj|ddd }|jd dkrr| 	|j
d d | | qW dS )z?Data integrity during recovery (non-contiguous numerical types))r5   r   Nr\   r]   F)r`   ra   r4   rb   rF   rG   rZ   r   ZSkipTestrK   r^   rX   )rS   rc   rT   r   rV   rV   rW   test03_types_nc   s    
zBasicTestCase.test03_types_ncN)
__name__
__module____qualname____doc__ZendiancheckrX   r[   r_   rd   re   rV   rV   rV   rW   r,   +   s   <r,   c               @   s   e Zd ZdZedZdZdS )Basic0DOneTestCasezRank-0 case 1   4N)rf   rg   rh   r<   rF   rG   ra   rY   rV   rV   rV   rW   rj      s   
rj   c               @   s   e Zd ZdZedZdZdS )Basic0DTwoTestCasezRank-0 case 2!   Z44N)rf   rg   rh   r<   rF   rG   ra   rY   rV   rV   rV   rW   rm      s   
rm   c               @   s   e Zd ZdZedZdZdS )Basic1DOneTestCasezRank-1 case 1)rk   )rT   N)rf   rg   rh   r<   rF   rG   ra   rY   rV   rV   rV   rW   ro      s   
ro   c               @   s   e Zd ZdZedZdZdS )Basic1DTwoTestCasezRank-1 case 2)r      )aaaN)rf   rg   rh   r<   rF   rG   ra   rY   rV   rV   rV   rW   rp      s   
rp   c               @   s   e Zd ZdZedZdZdS )Basic1DThreeTestCasezRank-1 case 3)rk   rq      )ZaaaaZbbbN)rf   rg   rh   r<   rF   rG   ra   rY   rV   rV   rV   rW   rs      s   
rs   c               @   s0   e Zd ZdZedZddgddgddggZd	S )
Basic2DTestCasezRank-2 case 1)rq   rq   rr   Zdddddr   ZsssZttN)rf   rg   rh   r<   rF   onesra   rY   rV   rV   rV   rW   ru      s   
ru   c               @   s(   e Zd ZdZedZejeddZdS )Basic10DTestCasezRank-10 case 1)
r\   r\   r\   r\   r\   r\   r\   r\   r\   r\   S1)r5   N)	rf   rg   rh   r<   rF   rw   ra   rG   rY   rV   rV   rV   rW   rx      s   
rx   c               @   s    e Zd ZdZdd Zdd ZdS )GroupsArrayTestCasezvThis test class checks combinations of arrays with groups.

    It also uses arrays ranks which ranges until 10.

    c             C   s  t jr tdd td| jj  | jj}d}xjtD ]b}t	d| |}d| }t jrdtd|
| | j|||d | j|d	t| }|d7 }q2W |   | jj}x(tdttD ]}t	d| t|d  }t|dt|d   }| }t||d
slt jrltd|j td| td|j td|jdd td|j  td|jdd td|jj  | |j|j tdjdkr|jjdks|jjdkr| |jjdkp|jjdk nP|jjdks|jjdkr
| |jjdkp|jjdk n| t||d
 ntdjdkr|jjdksL|jjdkrn| |jjdkph|jjdk nP|jjdks|jjdkr| |jjdkp|jjdk n| t||d
 t|d	t| }qW dS )zoChecking combinations of arrays with groups

        It also uses arrays ranks which ranges until 10.

        r-   z<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=z$Running %s.test00_iterativeGroups...   )r\   Zarray_zCreating dataset:zLarge arraygroupr8   zArray a original. Shape: ==>zArray a original. Data: ==>zInfo from dataset:z  shape ==>r.   )r/   z  dtype ==> %sz"Array b read from file. Shape: ==>z. Type ==> %sr   rq   r   r!   r"      r   r#   N)r   r9   r:   	__class__rf   rA   rB   r`   rF   rw   Z_g_joinrC   create_grouprH   _reopenr   rZ   getattrrD   r   r4   _v_pathnamer5   r;   rK   rI   rN   )rS   r|   r   rc   rT   Zdsetnamedsetr   rV   rV   rW   test00_iterativeGroups   sT    


""""z*GroupsArrayTestCase.test00_iterativeGroupsc             C   s$  d}d}t jr2tdd td| jj  td| | jj}t jrLtddd	 xht||d D ]V}t	d
| d}t jrtd| dd	 | j
|d|d|  | j|dt| }q\W | j  |   | jj}t jrt  td x*t||d D ]}t	d
| d}|j }t jr.td| dd	 | | kst jr|j}td|j td|jdd	 td|j  td|jdd	 td|jj  | |j|j |jjdkr| |jjdkp|jjdk n| |jj|jj | || | j|dt| }qW t jr t  dS )zChecking creation of large rank arrays (0 < rank <= 32)

        It also uses arrays ranks which ranges until maxrank.

        r{       r-   z<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=z$Running %s.test01_largeRankArrays...zMaximum rank for tested arrays:zRank array writing progress: r.   )r/   )r{   r   z%3d,rG   zRank: %sr|   zRank array reading progress: zInfo from dataset:z  Shape: ==>z  typecode ==> %cz"Array b read from file. Shape: ==>z. Type ==> %cr   N)r   r9   r:   r~   rf   rA   rB   r   rF   rw   rC   r   rH   flushr   rG   rD   tolistr   r4   rc   r5   r;   rK   rN   Zget_node)rS   ZminrankZmaxrankr|   ZrankrT   r   r   rV   rV   rW   test01_largeRankArrays:  sT    




"z*GroupsArrayTestCase.test01_largeRankArraysN)rf   rg   rh   ri   r   r   rV   rV   rV   rW   rz      s   Rrz   c               @   s  e Zd ZeddddZeddddZeddZeddZ	e
ddZeddZeddZeddZeddZeddZeddZeddZed	d
dZedd
dZeedrejddZ eedrej!ddZ"eedrej#ddZ$eedrejdd
dZ%eedrejdd
dZ&dS )Recordrq   s   abcdr   )rI   dfltposr{      a)r   g      ?r}   y      ?        )rI   r      
Float16Col
Float96ColFloat128ColZComplex196Col   ZComplex256Colr   N)'rf   rg   rh   r   var1var2r   var3r	   var4r
   Zvar5r   Zvar6r   var7r   Zvar8r   Zvar9r   Zvar10r   Zvar11r   Zvar12r   Zvar13Zvar14rE   r?   r   Zvar15r   Zvar16r   Zvar17Zvar18Zvar19rV   rV   rV   rW   r     s0   













r   c                   sP   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
  ZS )TableReadTestCased   c                sP   t t|   | j| jjdt}xt| jD ]}|j	
  q.W | jdd d S )NtablerT   )r1   )superr   setUprA   create_tablerB   r   r   nrowsrowappendr   )rS   r   r   )r~   rV   rW   r     s
    zTableReadTestCase.setUpc             C   s   | j jj}d|_x|jD ]}|j|d}|j| }|jj| j	j
}|jj}|dkr|dkrrtjdg| j dd}ntjdg| j d	d}tjrtd
| tdd td| td|j td|j td|dd  | t||d qW dS )zOChecking column conversion into NumPy in read().

        Char flavor

        r8   )fieldr7   r{   abcdS4)r5   rT   ry   zTypecode of NumPy column read:zShould look like:czItemsize of column:zShape of NumPy column read:zFirst 3 elements of read col:Nrk   )rA   rB   r   flavorcolnamesrD   coltypesdescription	_v_dtypesrL   rI   r5   r;   rF   rG   r   r   r9   r:   r4   rN   r   )rS   r   colnamenumcoltypecolitemsizecol
nctypecode
orignumcolrV   rV   rW   test01_readTableChar  s&    




z&TableReadTestCase.test01_readTableCharc             C   s   | j jj}d|_x~|jD ]t}|j|d}|j| }tj|j	j
d  }|dkrtjrftd| td| tj| j|j	j
d}| t||d qW dS )	zPChecking column conversion into NumPy in read().

        NumPy flavor

        r8   )r   r   r7   zTypecode of NumPy column read:zShould look like:)r4   r5   N)rA   rB   r   r   r   rD   r   rF   Z
sctypeDictr5   r;   r   r9   r:   rw   r   rN   r   )rS   r   r   r   r   r   r   rV   rV   rW   test01_readTableNum  s    



z%TableReadTestCase.test01_readTableNumc       	      C   s  | j jj}d|_dddg}t|| _x|jD ]}|j||d}|j| }|j	j
| jj}|jj}|dkr,|dkrtjdg| j dd	}ntjd
g| j dd	}tjrtd| tdd td| td|j td|j td|dd  | t||d q,W dS )zFColumn conversion into NumPy in readCoords().

        Chars

        r8   r{   r\   rk   )r   r7   r   r   )r5   rT   ry   zTypecode of NumPy column read:zShould look like:r   zItemsize of column:zShape of NumPy column read:zFirst 3 elements of read col:N)rA   rB   r   r   rZ   r   r   read_coordinatesr   r   r   rL   rI   r5   r;   rF   rG   r   r9   r:   r4   rN   r   )	rS   r   coordsr   r   r   r   r   r   rV   rV   rW   test02_readCoordsChar  s*    






z'TableReadTestCase.test02_readCoordsCharc             C   s   | j jj}d|_dddg}t|| _x|jD ]x}|j||d}|j| }|j	j
}|dkr,|dkrddS tjr~td	| td
| tj| j|j	jd}| t||d q,W dS )zMColumn conversion into NumPy in read_coordinates().

        NumPy.

        r8   r{   r\   rk   )r   r7   int64NzType of read NumPy column:zShould look like:)r4   r5   )rA   rB   r   r   rZ   r   r   r   r   r5   rJ   r   r9   r:   rF   rw   r;   rN   r   )rS   r   r   r   r   r   rU   r   rV   rV   rW   test02_readCoordsNum  s     





z&TableReadTestCase.test02_readCoordsNumc                s   | j jjtjdddgdd}xjD ]  fdd|D }j  }|dkr&|d	kr\d
S t||}tjr|j	j
}td| td| tjt||j	jd}| t||d q&W d
S )z7Getting table rows specifyied as NumPy scalar integers.r{   r\   rk   int8)r5   c                s   g | ]}|   qS rV   rV   ).0Zcoord)r   r   rV   rW   
<listcomp>  s    z:TableReadTestCase.test03_getIndexNumPy.<locals>.<listcomp>r7   r   NzType of read NumPy column:zShould look like:)r4   r5   r8   )rA   rB   r   rF   rG   r   r   r   r9   r5   rJ   r:   rw   rZ   r;   rN   r   )rS   r   r   r   rU   r   rV   )r   r   rW   test03_getIndexNumPy  s     




z&TableReadTestCase.test03_getIndexNumPyc             C   s   | j dd | jjj}d|_tjdddgdd}ttj	d }t
d	d
gdg|  ||d < ||d |d d }tjrtd td| | |d d | |d d | |d d | |d d | |d d dS )z0Setting table rows specifyied as NumPy integers.rT   )r1   r8   r{   r\   rk   r   )r5   Zaasax   r   z{Original row:
['aasa', 'x', True, -24, 232, 232, 232, 232, 232L, 232, 232.0, 232.0, (232 + 0j), (232+0j), 232.0, (232+0j)]
z
Read row:
r   s   aasar      xr   Tr   ir   N)r   rA   rB   r   r   rF   rG   rZ   r   columnstuplerD   r   r9   r:   rK   )rS   r   r   nrecordrV   rV   rW   test04_setIndexNumPy+  s    

z&TableReadTestCase.test04_setIndexNumPy)rf   rg   rh   r   r   r   r   r   r   r   r   __classcell__rV   rV   )r~   rW   r     s   
r   c               @   s$   e Zd ZdZeddZeddZdS )Infork   r\   )rI   r   N)rf   rg   rh   _v_posr   Namer   ZValuerV   rV   rV   rW   r   J  s   
r   c               @   sr   e Zd ZdZeddddZedddZeddZ	e
d	ddd
ddddZed	dddZe ZG dd dejZdS )
TestTDescrz.A description that has several nested columns.r   r\   )r   r4   r   r{   )r\   r\   )r   r4   )r   rq   )r3   r'   r   r3   int32)r4   s   ab)rI   r   r   c               @   sH   e Zd ZdZeddZedddZeddZ	e
 ZG dd	 d	ejZd
S )zTestTDescr.Infor{   r\   )rI   r   r   )rI   r   )r   c               @   s,   e Zd ZeddZeddZedddZdS )zTestTDescr.Info.Info2r\   )r4   )rI   r   )rI   r4   N)	rf   rg   rh   r   y3r   rM   r   valuerV   rV   rV   rW   Info2b  s   

r   N)rf   rg   rh   r   r   rM   r   r   r   y2r
   z2r?   IsDescriptionr   rV   rV   rV   rW   r   [  s   

r   N)rf   rg   rh   ri   r   r   r   yr
   zr   Zz3r   colorr   infor?   r   rV   rV   rV   rW   r   P  s   
r   c                   s   e Zd ZdZ fddZdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Z  ZS )*TableNativeFlavorTestCaser   c                sX   t t|   | jj| jjdt| jd}d|_xt	| jD ]}|j
  q:W |  d S )Nr   )Zexpectedrowsr8   )r   r   r   rA   r   rB   r   r   r   r   r   r   r   )rS   r   r   )r~   rV   rW   r   k  s    
zTableNativeFlavorTestCase.setUpc             C   sH  | j r| jdd | jjj}|dd }tjr\tdt| td|j	j
 td|dd  | t|tj |jjdd }| t|tj tjdd	d
}| t||d |jjdd }| t|tj ddddddgfddg}tjd|d
}| |j	j
|j	j
 tjr(td| td| | t| jt|j dS )z)Checking the return of a NumPy in read().rT   )r1   NzType of read:zDescription of the record:zFirst 3 elements of read:rk   )rk   r\   r   )r5   r8   )r   c16)r   f8r   )rM   ZS2)r   r   )r\   )r   r   )r\   )r   u1)rk   zcol-->znpcol-->)closer   rA   rB   r   r   r9   r:   rJ   r5   descrrN   
isinstancerF   ndarraycolsr   zerosr   r   rK   bytescopydata)rS   r   r   colnpcolr5   rV   rV   rW   test01a_basicTableReadv  s:    


z0TableNativeFlavorTestCase.test01a_basicTableReadc             C   sr  | j r| jdd | jjj}|ddd }tjr^tdt| td|j	j
 td|dd  | t|tj |jjddd }| t|tj tjd	d
d}| t||d |jjddd }| t|tj ddt fddt fddddt dfddt dfgfddg}tjd|d}| |j	j
|j	j
 tjrRtd| td| | t| jt|j dS )z;Checking the return of a NumPy in read() (strided version).rT   )r1   Nrk   zType of read:zDescription of the record:zFirst 3 elements of read:	   )rk   r\   r   )r5   r8   r   z%sc16r   z%sf8r   )rM   z|S2)r\   r   )r   z|u1)rk   zcol-->znpcol-->)r   r   rA   rB   r   r   r9   r:   rJ   r5   r   rN   r   rF   r   r   r   r   r   r   	byteorderrK   r   r   r   )rS   r   r   r   r   r5   rV   rV   rW   test01b_basicTableRead  s:    




z0TableNativeFlavorTestCase.test01b_basicTableReadc             C   s   | j r| jdd | jjj}|d}tjrZtdt	| td|j
j td|dd  | t|tj | t|d	 | t|tjd	d
dd dS )z6Checking the return of NumPy in get_where_list method.rT   )r1   zz == 1zType of read:zDescription of the record:zFirst 3 elements of read:Nrk   r   Zi8)r5   r8   )r   r   rA   rB   r   get_where_listr   r9   r:   rJ   r5   r   rN   r   rF   r   rK   rZ   r   Zarange)rS   r   r   rV   rV   rW   test02_getWhereList  s    

z-TableNativeFlavorTestCase.test02_getWhereListc             C   s   | j jj}|jj  | jr2| jdd | j jj}|d}t	j
r^tdt| tdt| | t|tj | t|| j dS )z<Checking the return of NumPy in read_where method (strings).rT   )r1   zcolor == b"ab"zType of read:zLength of the data read:N)rA   rB   r   r   r   create_indexr   r   
read_wherer   r9   r:   rJ   rZ   rN   r   rF   r   rK   r   )rS   r   r   rV   rV   rW   test03a_readWhere  s    


z+TableNativeFlavorTestCase.test03a_readWherec             C   s   | j jj}|jj  | jr2| jdd | j jj}|d}t	j
r^tdt| tdt| | t|tj | t|d dS )z<Checking the return of NumPy in read_where method (numeric).rT   )r1   zz == 0zType of read:zLength of the data read:r   N)rA   rB   r   r   r   r   r   r   r   r   r9   r:   rJ   rZ   rN   r   rF   r   rK   )rS   r   r   rV   rV   rW   test03b_readWhere  s    


z+TableNativeFlavorTestCase.test03b_readWherec             C   s*  ddt  fddt  fddddt  dfddt  dfgfdd	g}tjd
|d}| j| jjd|}| jrz| jdd | jjj}|dd }t	j
rtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t	j
r
td| td| | t| jt|j dS )z2Checking the Table creation from a numpy recarray.r   z%sc16r   z%sf8r   )rM   z|S2)r\   r   )r   z|u1)rk   )r5   table2rT   )r1   NzType of read:zDescription of the record:zFirst 3 elements of read:rk   zLength of the data read:z	npdata-->zdata-->)r   rF   r   rA   r   rB   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   r   r   )rS   r5   npdatar   r   rV   rV   rW   test04a_createTable  s2    




z-TableNativeFlavorTestCase.test04a_createTablec             C   s   | j jj}|dd }|| | jr<| jdd | j jj}|dd }tjrtdt	| td|j
j td	|dd  td
t| | t|tj | |j
j|j
j tjrtd| td| | t| jt|j dS )z$Checking appending a numpy recarray.rk      rT   )r1   NzType of read:zDescription of the record:zLast 3 elements of read:zLength of the data read:z	npdata-->zdata-->)rA   rB   r   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   rF   r   rK   r   r   r   )rS   r   r   r   rV   rV   rW   test04b_appendTable(  s$    




z-TableNativeFlavorTestCase.test04b_appendTablec             C   s   | j jj}tjddd|jjdd< | jr@| jdd | j jj}|jjdd }t	j
rtdt| td|jj td	|dd
  tdt| | t|tj | t|d | t|tjdddd dS )zChecking assigning to a column.)r   r   )r5   NrT   )r1   zType of read:zDescription of the record:zFirst 3 elements of read:rk   zLength of the data read:r   r8   )rA   rB   r   rF   r   r   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   )rS   r   r   rV   rV   rW   test05a_assignColumnD  s    

z.TableNativeFlavorTestCase.test05a_assignColumnc          	   C   s  | j jj}tdd}tdd}tdd}|ddd	|||gd
ddg | jrh| jdd | j jj}|j	j
dd }tjrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj tjrtd| td| | | j|j dS )z+Checking modifying several columns at once.)rk   r\   r   )rk   r\   r\   float64)rk   Zuint8rk   r   r{   r   r   r   rT   )r1   zType of read:zDescription of the record:zFirst 3 elements of read:NzLength of the data read:zycol-->zdata-->)rA   rB   r   rF   rw   r   modify_columnsr   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   r   )rS   r   ZxcolycolZzcolr   rV   rV   rW   test05b_modifyingColumns\  s(    



z2TableNativeFlavorTestCase.test05b_modifyingColumnsc          	   C   s  | j jj}dddg}tjd|d}|ddd|d	d
dg | jrV| jdd | j jj}tdd}|jj	dd }t
jrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t
jrtd| td| | | j|j dS )z?Checking modifying several columns using a single numpy buffer.)r   Zi4)r\   )r   r   )r\   r\   )r   r   )rk   )r5   rk   r   r{   r   r   r   rT   )r1   )rk   r\   r\   r   zType of read:zDescription of the record:zFirst 3 elements of read:NzLength of the data read:zycol-->zdata-->)rA   rB   r   rF   r   r   r   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   r   )rS   r   r5   Znparrayr   r   rV   rV   rW   test05c_modifyingColumnsz  s(    




z2TableNativeFlavorTestCase.test05c_modifyingColumnsc             C   sH  | j jj}ddt fddt fddddt dfddt dfgfdd	g}tjd
|d}|jjdd }|jddd|dd | j	r| j
dd | j jj}|jjdd }tjrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj tjr(td| td| | t| jt|j dS )z9Checking assigning a nested column (using modify_column).r   z%sc16r   z%sf8r   )rM   z|S2)r\   r   )r   z|u1)rk   )r5   rk   r   r{   r   )columnr   rT   )r1   zType of read:zDescription of the record:zFirst 3 elements of read:NzLength of the data read:z	npdata-->zdata-->)rA   rB   r   r   rF   r   r   r   Zmodify_columnr   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   r   r   )rS   r   r5   r   r   rV   rV   rW   test06a_assignNestedColumn  s6    





z4TableNativeFlavorTestCase.test06a_assignNestedColumnc             C   s4  | j jj}ddt fddt fddddt dfddt dfgfdd	g}tjd
|d}||jjdd< | jr| j	dd | j jj}|jjdd }t
jrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t
jrtd| td| | t| jt|j dS )z>Checking assigning a nested column (using the .cols accessor).r   z%sc16r   z%sf8r   )rM   z|S2)r\   r   )r   z|u1)rk   )r5   rk   r   rT   )r1   zType of read:zDescription of the record:zFirst 3 elements of read:NzLength of the data read:z	npdata-->zdata-->)rA   rB   r   r   rF   r   r   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   r   r   )rS   r   r5   r   r   rV   rV   rW   test06b_assignNestedColumn  s4    





z4TableNativeFlavorTestCase.test06b_assignNestedColumnc             C   s  | j jj}|dd }d|d dd< |jddd|d | jrT| jd	d
 | j jj}tddd }|jj	dd }t
jrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t
jrtd| td| | t||d dS )z<Checking modifying several rows at once (using modify_rows).r   rk   r   Nr   r{   )ZrowsrT   )r1   )rk   r\   r\   r   zType of read:zDescription of the record:zFirst 3 elements of read:zLength of the data read:zycol-->zdata-->r8   )rA   rB   r   modify_rowsr   r   rF   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   )rS   r   chunkr   r   rV   rV   rW   test07a_modifyingRows  s(    



z/TableNativeFlavorTestCase.test07a_modifyingRowsc             C   s  | j jj}|dd }d|d dd< ||jdd< | jrP| jdd | j jj}td	d
d }|jjdd }t	j
rtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t	j
rtd| td| | t||d dS )z>Checking modifying several rows at once (using cols accessor).r   rk   r   r   Nr   rT   )r1   )rk   r\   r\   r   r{   zType of read:zDescription of the record:zFirst 3 elements of read:zLength of the data read:zycol-->zdata-->r8   )rA   rB   r   r   r   r   rF   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   )rS   r   r   r   r   rV   rV   rW   test07b_modifyingRows  s(    



z/TableNativeFlavorTestCase.test07b_modifyingRowsc             C   s  | j jj}|dd }d|d dd< |ddd| | jrR| jd	d
 | j jj}tddd }|jj	d }t
jrtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t
jrtd| td| | t||d dS )z<Checking modifying just one row at once (using modify_rows).rk   rq   r   r   Nr      r{   rT   )r1   )r\   r\   r   zType of read:zDescription of the record:zFirst 3 elements of read:zLength of the data read:zycol-->zdata-->r8   )rA   rB   r   r   r   r   rF   r   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   )rS   r   r   r   r   rV   rV   rW   test08a_modifyingRows%  s(    



z/TableNativeFlavorTestCase.test08a_modifyingRowsc             C   s   | j jj}|dd }d|d dd< ||jd< | jrL| jdd | j jj}td	d
d }|jjd }t	j
rtdt| td|jj td|dd  tdt| | t|tj | |jj|jj t	j
rtd| td| | t||d dS )z>Checking modifying just one row at once (using cols accessor).rk   rq   r   r   Nr   rT   )r1   )r\   r\   r   r{   zType of read:zDescription of the record:zFirst 3 elements of read:zLength of the data read:zycol-->zdata-->r8   )rA   rB   r   r   r   r   rF   r   r   r   r9   r:   rJ   r5   r   rZ   rN   r   r   rK   r   )rS   r   r   r   r   rV   rV   rW   test08b_modifyingRowsG  s(    




z/TableNativeFlavorTestCase.test08b_modifyingRowsc             C   s   | j r| jdd | jjj}|d}||}tjrdt	dt
| t	d|jj t	d|dd  | t|tj | t|d	 x&|d
 D ]}| |tjddd qW dS )z2Checking the return of string columns with spaces.rT   )r1   zcolor == b"ab"zType of read:zDescription of the record:zFirst 3 elements of read:Nrk   r   r   abz|S4)r5   )r   r   rA   rB   r   r   r   r   r9   r:   rJ   r5   r   rN   r   rF   r   rK   rZ   rG   )rS   r   Zrdatar   idatarV   rV   rW   test09a_getStringsi  s    


z,TableNativeFlavorTestCase.test09a_getStringsc             C   s   | j r| jdd | jjj}xtdD ]}d|jj|< q&W |  |dd }t	j
rtdt| td|jj td|dd	  | t|tj | t|d
 xRtd
D ]F}|d | }|dkr| |tjddd q| |tjddd qW dS )zNChecking the return of string columns with spaces.

        (modify)

        rT   )r1   2   za  NzType of read:zDescription of the record:zFirst 3 elements of read:rk   r   r   r  z|S4)r5   )r   r   rA   rB   r   r   r   r   r   r   r9   r:   rJ   r5   r   rN   r   rF   r   rK   rZ   rG   )rS   r   r   r   r  rV   rV   rW   test09b_getStrings  s$    
z,TableNativeFlavorTestCase.test09b_getStringsc             C   s.  | j r| jdd | jjj}|j}x tdD ]}d|d< |  q,W |  | j rl| j   t	
| jd| _| jjjdd }tjrtdt| td|jj td	|dd
  | t|tj | t|d xTtdD ]H}|d | }|dk r| |tjddd q| |tjddd qW dS )zNChecking the return of string columns with spaces.

        (append)

        rT   )r1   r  za  r   NzType of read:zDescription of the record:zFirst 3 elements of read:rk      r   r  z|S4)r5   )r   r   rA   rB   r   r   r   r   r   r?   r@   r>   r   r9   r:   rJ   r5   r   rN   r   rF   r   rK   rZ   rG   )rS   r   r   r   r   r  rV   rV   rW   test09c_getStrings  s.    


z,TableNativeFlavorTestCase.test09c_getStrings)rf   rg   rh   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   rV   rV   )r~   rW   r   h  s*   **#%& """!r   c               @   s   e Zd ZdZdS )TableNativeFlavorOpenTestCaseFN)rf   rg   rh   r   rV   rV   rV   rW   r	    s   r	  c               @   s   e Zd ZdZdS )TableNativeFlavorCloseTestCaseTN)rf   rg   rh   r   rV   rV   rV   rW   r
    s   r
  c                   s,   e Zd Z fddZdd Zdd Z  ZS )AttributesTestCasec                s$   t t|   | j| jjd d S )Nr|   )r   r  r   rA   r   rB   )rS   )r~   rV   rW   r     s    zAttributesTestCase.setUpc             C   s   | j jj}|j}tjddd|_| jrB| jdd | j jj}|j}|j}tjddd}| 	t
|tj | |jj|jj tjrtd| td| | 	t||d d	S )
z+Checking the creation of a numpy attribute.)r{   r{   int16)r5   rT   )r1   z	npcomp-->zdata-->r8   N)rA   rB   r|   _v_attrsrF   r   numpy1r   r   rN   r   r   rK   r5   r   r   r9   r:   r   )rS   r|   g_attrsr   npcomprV   rV   rW   test01_writeAttribute  s    



z(AttributesTestCase.test01_writeAttributec             C   s   | j jj}|j}tjddd|_| jrB| jdd | j jj}|j}tj	ddd|_|j}tj	ddd}| 
t|tj | |jj|jj tjrtd| td| | 
t||d d	S )
z/Checking the modification of a numpy attribute.)r{   r\   r  )r5   rT   )r1   z	npcomp-->zdata-->r8   N)rA   rB   r|   r  rF   r   r  r   r   rw   rN   r   r   rK   r5   r   r   r9   r:   r   )rS   r|   r  r   r  rV   rV   rW   test02_updateAttribute  s     



z)AttributesTestCase.test02_updateAttribute)rf   rg   rh   r   r  r  r   rV   rV   )r~   rW   r    s   r  c               @   s   e Zd ZdZdS )AttributesOpenTestCaser   N)rf   rg   rh   r   rV   rV   rV   rW   r    s   r  c               @   s   e Zd ZdZdS )AttributesCloseTestCaser{   N)rf   rg   rh   r   rV   rV   rV   rW   r    s   r  c                   s4   e Zd Z fddZdd Zdd Zdd Z  ZS )	StrlenTestCasec                s~   t t|   | j| jjd}dtddi}| j|d|| _d| j_	| jj
}d|d< |  d|d< |  | j  d S )	Nr|   Texti  )rI   r   r8   zHello Francesc!zHola Francesc!)r   r  r   rA   r   rB   r   r   r   r   r   r   r   )rS   r|   Ztablelayoutr   )r~   rV   rW   r     s    zStrlenTestCase.setUpc             C   s   | j r | jdd | jjjj| _| jdd }| jdd }tjrZt	d| t	d| | 
t|td | 
t|td	 | 
|d | 
|d	 d
S )z-Checking the lengths of strings (read field).rT   )r1   r  r   r{   z
string1-->z
string2-->s   Hello Francesc!s   Hola Francesc!N)r   r   rA   rB   r|   r   r   r   r9   r:   rK   rZ   )rS   str1str2rV   rV   rW   test01%  s    

zStrlenTestCase.test01c             C   s   | j r | jdd | jjjj| _| jdd d d }| jdd d d }| t|td | t|td | |d | |d dS )	z0Checking the lengths of strings (read recarray).rT   )r1   Nr  r   r{   s   Hello Francesc!s   Hola Francesc!)r   r   rA   rB   r|   r   rK   rZ   )rS   r  r  rV   rV   rW   test029  s    zStrlenTestCase.test02c             C   s   | j r | jdd | jjjj| _| jd d }| jd d }| t|td | t|td | |d | |d dS )	z<Checking the lengths of strings (read recarray, row by row).rT   )r1   r   r  r{   s   Hello Francesc!s   Hola Francesc!N)r   r   rA   rB   r|   r   rK   rZ   )rS   r  r  rV   rV   rW   test03J  s    zStrlenTestCase.test03)rf   rg   rh   r   r  r  r  r   rV   rV   )r~   rW   r    s   r  c               @   s   e Zd ZdZdS )StrlenOpenTestCaser   N)rf   rg   rh   r   rV   rV   rV   rW   r  \  s   r  c               @   s   e Zd ZdZdS )StrlenCloseTestCaser{   N)rf   rg   rh   r   rV   rV   rV   rW   r  `  s   r  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jr| t t qW | S )Nr{   )r   Z	TestSuiter   ZaddTestZ	makeSuiterj   rm   ro   rp   rs   ru   rz   r   r	  r
  r  r  r  r  r   Zheavyrx   )ZtheSuiteZniterr   rV   rV   rW   suited  s(    r  __main__)ZdefaultTest)DZ
__future__r   r   rO   sysr=   r8   rF   r?   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   Ztables.testsr   Ztables.tests.commonr   r   r   ZTestCaseZ	six.movesr   r`   platformrE   r   r   r,   rj   rm   ro   rp   rs   ru   rx   ZTempFileMixinrz   r   r   r   r   r   r   r	  r
  r  r  r  r  r  r  r  rf   Z
parse_argvargvZprint_versionsmainrV   rV   rV   rW   <module>   sr   D




w # -    d=G
