a
    =_                    @   sB  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 d dl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mZmZmZ d dlmZmZ d d	lmZ  d
Z!dZ"G dd dej#Z$G dd deje Z%e"d Z&G dd de%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/G dd de%Z0G d d! d!e%Z1G d"d# d#e%Z2G d$d% d%e%Z3G d&d' d'e%Z4G d(d) d)e%Z5G d*d+ d+eje Z6G d,d- d-e7Z8e8 Z9e8d.d/Z:e8ej;d0d1d.d.d2d3Z<G d4d5 d5eje Z=G d6d7 d7e=Z>G d8d9 d9e=Z?G d:d; d;e=Z@G d<d= d=e=ZAG d>d? d?e=ZBG d@dA dAe=ZCG dBdC dCe=ZDG dDdE dEe=ZEG dFdG dGe=ZFG dHdI dIe=ZGG dJdK dKe=ZHG dLdM dMeje ZIG dNdO dOee ZJG dPdQ dQee ZKG dRdS dSejLe ZMdTZ"G dUdV dVee ZNG dWdX dXee ZOG dYdZ dZeOZPG d[d\ d\eOZQG d]d^ d^eOZRG d_d` d`eOZSG dadb dbeje ZTG dcdd ddeTZUG dedf dfeTZVG dgdh dheje ZWG didj djeWZXG dkdl dlee ZYdmdn ZZe[dokr>d dl\Z\e]e\j^ e_  ej`dndp dS )q    N)		StringColBoolColIntColFloatColInt8ColInt32ColInt64Col	UInt16Col
Float32Col)Indexdefault_auto_indexdefault_index_filters)calc_chunksize)OldIndexWarning)common)verboseallequalheavyTempFileMixin)unittesttest_filename)PyTablesTestCase
   )`            c                   @   s>   e Zd ZeddddZedddZedddZe	dddZ
d	S )
TDescr          )itemsizedfltposr      )r"   r#   r   N)__name__
__module____qualname__r   var1r   var2r   var3r   var4 r,   r,   8lib/python3.9/site-packages/tables/tests/test_indexes.pyr      s   r   c                       s   e Zd ZdZdZdZdZeZe	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d,d- Zd.d/ Z   Z!S )0BasicTestCaser   zlibr$   c                    s.   t t|   | jj| _|   | j  d S N)superr.   setUph5fileroot	rootgrouppopulateFilecloseself	__class__r,   r-   r2   +   s    
zBasicTestCase.setUpc                 C   s   | j }d}tj| j| j| j| jd| _| j	|dt
|| j| j}t| jD ]R}t|d|jd< |d |jd< ||jd< t| j| d	 |jd
< |j  qJ|  |j D ]}|jtd}qtrtd| j td| d S )NThis is the IndexArray title	complevelcomplibshuffle
fletcher32tableasciir(   r$   r)   r*   r    r+   _blocksizeszNumber of written rows:zNumber of indexed rows:)r5   tablesFilterscompressr?   r@   rA   filtersr3   create_tabler   nrowsrangestrencoderowfloatappendflushcolinstancesvaluescreate_indexsmall_blocksizesr   print)r9   grouptitlerB   icol	indexrowsr,   r,   r-   r6   3   s.    

zBasicTestCase.populateFilec                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}t
dD ]"}t|d|jd< |j  qB|  |jjj}t rtd	|j td
|j td|jj td|jd  dd |dD }| t|d | |dgd  dS )z:Checking flushing an Index incrementing only the last row.
<-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=z!Running %s.test00_flushLastRow...amoder   rC   r(   Max rows in buf:Number of elements per slice:Chunk size:zElements in last row:c                 S   s   g | ]}|d  qS r(   r,   .0pr,   r,   r-   
<listcomp>f   r   z5BasicTestCase.test00_flushLastRow.<locals>.<listcomp>var1 == b"1"r$      1N)r   rW   r;   r%   rF   	open_fileh5fnamer3   r4   rB   rL   rM   rN   rO   rQ   rR   colsr(   index
nrowsinbuf	slicesizesorted	chunksizeZ	indicesLRwhereassertEquallen)r9   rB   rZ   idxcolresultsr,   r,   r-   test00_flushLastRowN   s(    


z!BasicTestCase.test00_flushLastRowc                 C   s2  t rtdd td| jj  tj| jdd| _| jjj	}t
|dD ]$\}}t||d< ||d< |  qH|  |jjj}|jjj}t rtd	|j td
|j | |jd | |jd dd |dD }| t|d | |dgd  dd |dD }| t|d | |dgd  dS )z9Checking automatic re-indexing after an update operation.r]   r^   zRunning %s.test00_update...r_   r`   z(var3>1) & (var3<5)r(   r*   zDirtyness of var1 col:zDirtyness of var3 col:Fc                 S   s   g | ]}|d  qS rf   r,   rg   r,   r,   r-   rj      r   z/BasicTestCase.test00_update.<locals>.<listcomp>rk   r$   rl   c                 S   s   g | ]}|d  qS r*   r,   rg   r,   r,   r-   rj      r   z	var3 == 0r   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   	enumerateru   rM   updaterR   ro   r(   rp   r*   dirtyrv   rw   )r9   rB   rZ   rO   Zidxcol1Zidxcol3ry   r,   r,   r-   test00_updatej   s.    




zBasicTestCase.test00_updatec                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rntd|j td|j td|jj d	d
 |dD }| t|d | |dg dS )z)Checking reading an Index (string flavor)r]   r^   zRunning %s.test01_readIndex...rr`   rb   rc   rd   c                 S   s   g | ]}|d  qS rf   r,   rg   r,   r,   r-   rj      r   z2BasicTestCase.test01_readIndex.<locals>.<listcomp>rk   r    rl   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   rq   rr   rs   rt   ru   rv   rw   r9   rB   rx   ry   r,   r,   r-   test01_readIndex   s    


zBasicTestCase.test01_readIndexc                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rztd|j td|j td|j td	|jj d
d |dD }t rtd| | t|| jd  | |dg| jd   dS )z'Checking reading an Index (bool flavor)r]   r^   zRunning %s.test02_readIndex...r   r`   zRows in table:rb   rc   rd   c                 S   s   g | ]}|d  qS )r)   r,   rg   r,   r,   r-   rj      r   z2BasicTestCase.test02_readIndex.<locals>.<listcomp>zvar2 == TrueSelected values:r$   TN)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r)   rp   rK   rq   rr   rs   rt   ru   rv   rw   r   r,   r,   r-   test02_readIndex   s     



zBasicTestCase.test02_readIndexc              	   C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rntd|j td|j td|jj d	d
 |dD }t rtd| | t|td|jd  | |ttdtd|j dS )z&Checking reading an Index (int flavor)r]   r^   zRunning %s.test03_readIndex...r   r`   rb   rc   rd   c                 S   s   g | ]}|d  qS r{   r,   rg   r,   r,   r-   rj      r   z2BasicTestCase.test03_readIndex.<locals>.<listcomp>z(1<var3)&(var3<10)r   r   r$   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r*   rp   rq   rr   rs   rt   ru   rv   rw   minrK   listrL   r   r,   r,   r-   test03_readIndex   s    



zBasicTestCase.test03_readIndexc              
   C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rztd|j td|j td|j td	|jj d
d |dD }t rtd| | t|td|j | |dd ttttd|jD  dS )z(Checking reading an Index (float flavor)r]   r^   zRunning %s.test04_readIndex...r   r`   rb   zNumber of rows in table:rc   rd   c                 S   s   g | ]}|d  qS )r+   r,   rg   r,   r,   r-   rj      r   z2BasicTestCase.test04_readIndex.<locals>.<listcomp>	var4 < 10r   r   c                 S   s   g | ]}t |qS r,   )rP   )rh   rZ   r,   r,   r-   rj      r   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r+   rp   rq   rK   rr   rs   rt   ru   rv   rw   r   reversedr   rL   r   r,   r,   r-   test04_readIndex   s$    



zBasicTestCase.test04_readIndexc                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rntd|j td|j td|jj d	|_|d
}dd |D }t rtd| td| | t|t| | || dS )z=Checking reading an Index with get_where_list (string flavor)r]   r^   z!Running %s.test05_getWhereList...r_   r`   rb   rc   rd   pythonvar1 < b"10"c                 S   s   g | ]}|d  dk r|j qS r(   s   10nrowrg   r,   r,   r-   rj      r   z5BasicTestCase.test05_getWhereList.<locals>.<listcomp>r   Should look like:Nr   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r+   rp   rq   rr   rs   rt   flavorget_where_listrv   rw   r9   rB   rx   rowList1rowList2r,   r,   r-   test05_getWhereList   s(    





z!BasicTestCase.test05_getWhereListc                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rztd|j td|j td|j td	|jj d
|_|jddd}dd |D }t|tj}t rtd| td| | t|t| | t|| dS )z;Checking reading an Index with get_where_list (bool flavor)r]   r^   z!Running %s.test06_getWhereList...r_   r`   rb   zRows in tables:rc   rd   numpyzvar2 == FalseTsortc                 S   s   g | ]}|d  du r|j qS )r)   Fr   rg   r,   r,   r-   rj     r   z5BasicTestCase.test06_getWhereList.<locals>.<listcomp>r   r   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r)   rp   rq   rK   rr   rs   rt   r   r   r   arrayZint64rv   rw   
assertTruer   r   r,   r,   r-   test06_getWhereList  s,    




z!BasicTestCase.test06_getWhereListc                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rntd|j td|j td|jj d	|_|jd
dd}dd |D }t rtd| td| | t|t| | || dS )z:Checking reading an Index with get_where_list (int flavor)r]   r^   z!Running %s.test07_getWhereList...r_   r`   rb   rc   rd   r   z	var3 < 15Tr   c                 S   s   g | ]}|d  dk r|j qS )r*      r   rg   r,   r,   r-   rj   5  r   z5BasicTestCase.test07_getWhereList.<locals>.<listcomp>r   r   Nr   r   r,   r,   r-   test07_getWhereList!  s(    




z!BasicTestCase.test07_getWhereListc                 C   s   t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rntd|j td|j td|jj d	|_|jd
dd}dd |D }t rtd| td| | t|t| | || dS )z<Checking reading an Index with get_where_list (float flavor)r]   r^   z!Running %s.test08_getWhereList...r_   r`   rb   rc   rd   r   r   Tr   c                 S   s   g | ]}|d  dk r|j qS )r+   r   r   rg   r,   r,   r-   rj   P  r   z5BasicTestCase.test08_getWhereList.<locals>.<listcomp>r   r   Nr   r   r,   r,   r-   test08_getWhereList<  s(    




z!BasicTestCase.test08_getWhereListc                 C   s"  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t r^td td|j
j | |jd d	 | | |j
j  t rtd
 td|j
j | |j
jj | |jd d |j
jjtd}| | |j
jj}t rtd td|j
j | | | |jd d	 dS )zChecking removing an index.r]   r^   z!Running %s.test09a_removeIndex...r_   r`   Before deletionvar1 column:r(   r    After deletionr   rD   After re-creationN)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   rv   
colindexedassertIsNotNoneremove_indexassertIsNonerU   rV   r9   rB   rx   r\   r,   r,   r-   test09a_removeIndexW  s6    






z!BasicTestCase.test09a_removeIndexc                 C   sB  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t r^td td|j
j | | | |jd d	 |j
j  | jdd | jjj	}|j
jj}t rtd
 td|j
j | |j
jj | |jd d |j
jjtd}| | |j
jj}t r"td td|j
j | | | |jd d	 dS )z/Checking removing an index (persistent version)r]   r^   z!Running %s.test09b_removeIndex...r_   r`   r   var1 index column:r(   r    r   r   r   rD   r   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   r   rv   r   r   _reopenr   rU   rV   r   r,   r,   r-   test09b_removeIndex{  s<    








z!BasicTestCase.test09b_removeIndexc                 C   s"  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rZtd td| | |jd d	 | | | jd
d}||d t rtd td| | |j
jj | |jd d	 d|_|d}dd |D }t rtd| td| | t|t| | || dS )z&Checking moving a table with an index.r]   r^   zRunning %s.test10a_moveIndex...r_   r`   Before mover   r(   r    /agrouptable2
After mover   r   c                 S   s   g | ]}|d  dk r|j qS r   r   rg   r,   r,   r-   rj     r   z3BasicTestCase.test10a_moveIndex.<locals>.<listcomp>r   r   Nr   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   rv   r   r   create_groupmover   r   rw   r9   rB   rx   r   r   r   r,   r,   r-   test10a_moveIndex  s4    








zBasicTestCase.test10a_moveIndexc                 C   sR  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t rZtd td| | | | |jd d	 | jd
d}||d | jdd | jjjj}|j
jj}t rtd td| | |j
jj | |jd d	 d|_|d}dd |D }t r.td|t| td|t| | t|t| | || dS )z:Checking moving a table with an index (persistent version)r]   r^   zRunning %s.test10b_moveIndex...r_   r`   r   r   r(   r    r   r   r   r   r   r   r   c                 S   s   g | ]}|d  dk r|j qS r   r   rg   r,   r,   r-   rj     r   z3BasicTestCase.test10b_moveIndex.<locals>.<listcomp>r   r   N)r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   r   rv   r   r   r   r   r   r   r   r   typerw   r   r,   r,   r-   test10b_moveIndex  s:    







zBasicTestCase.test10b_moveIndexc                 C   s&  t rtdd td| jj  tj| jddd| _| jjj	}|j
jj}t r\td td| | |jd	 d
 | | | jdd}||d t rtd td| | |j
jj | |jd	 d
 d|_|d}dd |D }t rtd| td| | t|t| | || dS )z9Checking moving a table with an index (small node cache).r]   r^   zRunning %s.test10c_moveIndex...r_   r   ra   node_cache_slotsr   r   r(   r    r   r   r   r   r   r   c                 S   s   g | ]}|d  dk r|j qS r   r   rg   r,   r,   r-   rj     r   z3BasicTestCase.test10c_moveIndex.<locals>.<listcomp>r   r   Nr   r   r,   r,   r-   test10c_moveIndex  s8    









zBasicTestCase.test10c_moveIndexc                 C   s&  t rtdd td| jj  tj| jddd| _| jjj	}|j
jj}t r\td td| | |jd	 d
 | | | jdd}||d t rtd td| | |j
jj | |jd	 d
 d|_|d}dd |D }t rtd| td| | t|t| | || dS )z6Checking moving a table with an index (no node cache).r]   r^   zRunning %s.test10d_moveIndex...r_   r   r   r   r   r(   r    r   r   r   r   r   r   c                 S   s   g | ]}|d  dk r|j qS r   r   rg   r,   r,   r-   rj   <  r   z3BasicTestCase.test10d_moveIndex.<locals>.<listcomp>r   r   Nr   r   r,   r,   r-   test10d_moveIndex  s8    









zBasicTestCase.test10d_moveIndexc                 C   s  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t r^td td|j
j | |jd d	 | | | jd
 t rtd | d| jj | jddtd| j| j}t| jD ]L}t||jd< |d |jd< ||jd< t| j| d	 |jd< |j  q|  |j D ]}|jtd}| | q&|j
jj}t rjtd td|j
j | | | |jd d	 dS )z'Checking removing a table with indexes.r]   r^   z*Running %s.test11a_removeTableWithIndex...r_   r`   r   r   r(   r    /tabler   rB   r   	New tabler$   r)   r*   r+   rD   r   N) r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   rv   r   r   remove_nodeassertNotInrJ   r   rI   rK   rL   rM   rO   rP   rQ   rR   rS   rT   rU   rV   r9   rB   rx   rZ   r[   r\   r,   r,   r-   test11a_removeTableWithIndexC  sH    






z*BasicTestCase.test11a_removeTableWithIndexc                 C   s  t rtdd td| jj  tj| jdd| _| jjj	}|j
jj}t r^td td|j
j | |jd d	 | | | jd
 t rtd | d| jj | jdd | jddtd| j| j}t| jD ]L}t||jd< |d |jd< ||jd< t| j| d	 |jd< |j  q|  |j D ]}|jt d}| | q2|j
jj}t rvtd td|j
j | | | |jd d	 dS )z=Checking removing a table with indexes (persistent version 2)r]   r^   z*Running %s.test11b_removeTableWithIndex...r_   r`   r   r   r(   r    r   r   rB   r+r   r   r$   r)   r*   r+   rD   r   N)!r   rW   r;   r%   rF   rm   rn   r3   r4   rB   ro   r(   rp   rv   r   r   r   r   r   rJ   r   rI   rK   rL   rM   rO   rP   rQ   rR   rS   rT   rU   rV   r   r,   r,   r-   test11b_removeTableWithIndexp  sJ    






z*BasicTestCase.test11b_removeTableWithIndexc                 C   s   t rtdd td| jj  G dd dtj}t| j t	
d| _tj| jdd| _| j| jjd	|}|jjjtd
 |j}tdD ]$}||d< t|d |d< |  q|  | jdd | j| jjj dS )z=Checking removing a table with indexes (persistent version 3)r]   r^   z*Running %s.test11c_removeTableWithIndex...c                   @   s    e Zd ZeddZeddZdS )z<BasicTestCase.test11c_removeTableWithIndex.<locals>.Distancer   r#   r    N)r%   r&   r'   r   framer   distancer,   r,   r,   r-   Distance  s   
r   z.h5wr`   distance_tablerD   r   r   r$   r   r   N)r   rW   r;   r%   rF   IsDescriptionosremovern   tempfileZmktemprm   r3   rJ   r4   ro   r   rU   rV   rO   rL   rP   rQ   rR   r   r   r   )r9   r   rB   r   rZ   r,   r,   r-   test11c_removeTableWithIndex  s*    


z*BasicTestCase.test11c_removeTableWithIndexc                 C   s0  t j| jdd| _| jjj}dd| jg}| jdkrB|| jd  |D ]}d|dt	|dg}d|dt	|dg}z"t
|d  |d  d7  < qxW nN ty   |d D ]}|d  d7  < q|d D ]}|d  d7  < qY n0 | |d | | |d | | tt|dt	|d| qFd S )	Nr   r`   r    r   i  r   z
(var3 < e))e)rF   rm   rn   r3   r4   rB   rK   rQ   ru   dictnextStopIterationrv   rw   r   )r9   rB   ZtestslimitZhandle_aZhandle_b_r,   r,   r-   test12_doubleIterate  s*    

z"BasicTestCase.test12_doubleIterate)"r%   r&   r'   rH   r?   r@   rA   minRowIndexrK   rV   ssr2   r6   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r,   r,   r:   r-   r.   #   s8    $)&+''-0r.   r$   c                   @   s    e Zd ZdZdZdZdZeZdS )BasicReadTestCaser   r/   N	r%   r&   r'   rH   r?   r@   rA   small_ssrK   r,   r,   r,   r-   r     s
   r   c                   @   s    e Zd ZdZdZdZdZeZdS )ZlibReadTestCaser    r/   r   Nr   r,   r,   r,   r-   r     s
   r   z'BLOSC compression library not availablec                   @   s    e Zd ZdZdZdZdZeZdS )BloscReadTestCaser    Zbloscr   Nr   r,   r,   r,   r-   r     s
   r   z%LZO compression library not availablec                   @   s    e Zd ZdZdZdZdZeZdS )LZOReadTestCaser    Zlzor   Nr   r,   r,   r,   r-   r     s
   r   z'BZIP2 compression library not availablec                   @   s    e Zd ZdZdZdZdZeZdS )Bzip2ReadTestCaser    Zbzip2r   Nr   r,   r,   r,   r-   r     s
   r   c                   @   s    e Zd ZdZdZdZdZeZdS )ShuffleReadTestCaser    r/   r   Nr   r,   r,   r,   r-   r     s
   r   c                   @   s    e Zd ZdZdZdZdZeZdS )Fletcher32ReadTestCaser    r/   r   Nr   r,   r,   r,   r-   r     s
   r   c                   @   s    e Zd ZdZdZdZdZeZdS )ShuffleFletcher32ReadTestCaser    r/   Nr   r,   r,   r,   r-   r     s
   r   c                   @   s   e Zd Zeed  ZdS )OneHalfTestCaser$   Nr%   r&   r'   r   rK   r,   r,   r,   r-   r      s   r   c                   @   s   e Zd Zed ZdS )UpperBoundTestCaser    Nr   r,   r,   r,   r-   r   $  s   r   c                   @   s   e Zd Zed d ZdS )LowerBoundTestCaser$   r    Nr   r,   r,   r,   r-   r   (  s   r   c                   @   s8   e Zd ZeZdd Zdd Zdd Zdd Zd	d
 Z	dS )DeepTableIndexTestCasec                 C   s   | j | j jd}d}| j |dt|d| j}t| jD ]}|j  q8|	  |j
j }| | |j
jj}| |jd d | | | |j| j dS )z9Checking the indexing of a table in a 2nd level hierarchyr   r<   rB   Nr(   r    r3   r   r4   rJ   r   rK   rL   rO   rQ   rR   ro   r(   rU   r   rp   rv   r   	nelementsr9   rX   rY   rB   rZ   r\   rx   r,   r,   r-   test01/  s    


zDeepTableIndexTestCase.test01c                 C   s   | j | j jd}d}| j |dt|d| j}t| jD ]}|j  q8|	  |j
j }| | |j
jj}| jdd | j jjj}|j
jj}| |jd d | | | |j| j dS )	zJChecking the indexing of a table in 2nd level
        (persistent version)r   r<   rB   Nr_   r`   r(   r    r3   r   r4   rJ   r   rK   rL   rO   rQ   rR   ro   r(   rU   r   rp   r   r   rB   rv   r   r   r   r,   r,   r-   test01bE  s"    



zDeepTableIndexTestCase.test01bc                 C   s   | j | j jd}| j |d}| j |d}d}| j |dt|d| j}t| jD ]}|j  qT|	  |j
j }| | |j
jj}| |jd d | | | |j| j dS )z9Checking the indexing of a table in a 4th level hierarchyr   r<   rB   Nr(   r    r   r   r,   r,   r-   test02d  s     


zDeepTableIndexTestCase.test02c                 C   s   | j | j jd}| j |d}| j |d}d}| j |dt|d| j}t| jD ]}|j  qT|	  |j
j }| | |j
jj}| jdd | j jjjjj}|j
jj}| |jd d | | | |j| j dS )	zLChecking the indexing of a table in a 4th level
        (persistent version)r   r<   rB   Nr_   r`   r(   r    r   r   r,   r,   r-   test02b  s&    



zDeepTableIndexTestCase.test02bc                 C   s   | j j}tdD ]}| j |d}qd}| j |dt|d| j}t| jD ]}|j  qJ|	  |j
j }| | |j
jj}| |jd d | | | |j| j dS )z;Checking the indexing of a table in a 100th level hierarchyd   r   r<   rB   Nr(   r    )r3   r4   rL   r   rJ   r   rK   rO   rQ   rR   ro   r(   rU   r   rp   rv   r   r   )r9   rX   rZ   rY   rB   r\   rx   r,   r,   r-   test03  s     


zDeepTableIndexTestCase.test03N)
r%   r&   r'   r   rK   r   r   r   r   r   r,   r,   r,   r-   r   ,  s   "r   c                   @   s   e Zd ZeefddZdS )
IndexPropsc                 C   s   || _ || _d S r0   autorI   )r9   r   rI   r,   r,   r-   __init__  s    zIndexProps.__init__N)r%   r&   r'   r   r   r   r,   r,   r,   r-   r     s   r   F)r   r   r/   r=   )rI   c                       s   e Zd ZdZeZg 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  ZS )"AutomaticIndexingTestCaser    r(   r)   r*   )      r   r$   c              	      s   t t|   d}| jj}d}| jj|dt|d | j|d| _| j	j
| j_| jD ]}| jj| j| jd qNt| jD ]}| jj  qt| j  | jr| jdd | jjj| _d S )Nr<   )r$   rB   )
chunkshaperD   r_   r`   )r1   r   r2   r3   r4   rJ   r   rK   rB   ipropsr   	autoindexcolsToIndexrS   rU   rV   rL   rO   rQ   rR   reopenr   )r9   rY   r4   r   colnamerZ   r:   r,   r-   r2     s&    

zAutomaticIndexingTestCase.setUpc                 C   sl  t rtdd td| jj  | j}| jtu r>| |jd n| |jd | jtu r| |j	d d | 
|jjj | |j	d d | 
|jjj | |j	d d | 
|jjj | |j	d	 d | 
|jjj n| |j	d d | |jjj | |j	d d | |jjj | |j	d d | |jjj | |j	d	 d | 
|jjj d
S )z$Checking indexing attributes (part1)r]   r^   zRunning %s.test01_attrs...r   r    r(   r)   r*   r+   N)r   rW   r;   r%   rB   r   DefaultPropsrv   indexedr   r   ro   r(   rp   r)   r*   r+   r   r9   rB   r,   r,   r-   test01_attrs  s0    


z&AutomaticIndexingTestCase.test01_attrsc                 C   s  t rtdd td| jj  | j}t rD|jr<td|j ntd | jtu r\| 	|j n| jt
u rr| |j | jtu r| |jjjd | |jjjd | |jjjd | |jjjd nH| |jjjt | |jjjt | |jjjt | |jjjd dS )z$Checking indexing attributes (part2)r]   r^   zRunning %s.test02_attrs...zindex props:Table is not indexedN)r   rW   r;   r%   rB   r  r   r   NoAutoPropsassertFalseChangeFiltersPropsr   r  rv   ro   r(   rp   r)   r*   r+   ZassertIsInstancer   r  r,   r,   r-   test02_attrs  s*    



z&AutomaticIndexingTestCase.test02_attrsc                 C   s   t rtdd td| jj  | j}t rx|jrptd|j td|j |jj	j
}td|j td|j|j  ntd | jtur|jj	j
}|j}| |j| |j}| |j| j|  d	S )
zChecking indexing countersr]   r^   zRunning %s.test03_counters...indexedrows:unsavedindexedrows:ztable rows:computed indexed rows:r  N)r   rW   r;   r%   rB   r  _indexedrows_unsaved_indexedrowsro   r(   rp   rK   rr   r   r  r   rv   r9   rB   rp   indexedrowsr,   r,   r-   test03_counters*  s(    



z)AutomaticIndexingTestCase.test03_countersc                 C   s   t rtdd td| jj  | j}|  t rn|jrftd|j td|j |j	j
j}td|j ntd |j	j
j}| jtu r| | n*|j}| |j|j | |j| j|  | jtu r| |j n| jtu r| |j dS )	z/Checking indexing counters (non-automatic mode)r]   r^   zRunning %s.test04_noauto...r  r  r  r  N)r   rW   r;   r%   rB   flush_rows_to_indexr  r  r  ro   r(   rp   r   r   r  r   rv   rK   r  r  r   r	  r   r  r,   r,   r-   test04_noautoD  s0    





z'AutomaticIndexingTestCase.test04_noautoc                 C   s"  t rtdd td| jj  | j}|  | jturB|j}|j	}|
dd | jrj| jdd | jjj}t r|jrtd|j td	| td
|j	 td| td|jjjj ntd | |j| jd  | jtu r| |jjjj | jtu r| |j n| jtu r| |j dS )z(Checking indexing counters (remove_rows)r]   r^   zRunning %s.test05_icounters...r$   r   r_   r`   r  original indexedrows:r  original unsavedindexedrows:zindex dirty:r  N)r   rW   r;   r%   rB   r  r   r  r  r  remove_rowsr   r   r3   r4   r  ro   r(   rp   r~   rv   rK   r  r   r  r   r	  )r9   rB   r  unsavedindexedrowsr,   r,   r-   test05_icountersi  s6    





z*AutomaticIndexingTestCase.test05_icountersc                 C   s   t rtdd td| jj  | j}|  |dd | jrT| jdd | j	j
j}t rtd|j |jD ].}|j|jrjtd	||j|jjf  qj|jD ]J}|j|jr|js| |j|jjd
 q| |j|jjd qdS )z)Checking dirty flags (remove_rows action)r]   r^   zRunning %s.test06_dirty...r      r_   r`   z
auto flag:dirty flag col %s: %sTFN)r   rW   r;   r%   rB   r  r  r   r   r3   r4   r   colnamesro   _f_colrp   r~   rv   )r9   rB   r  r,   r,   r-   test06_dirty  s2    



z&AutomaticIndexingTestCase.test06_dirtyc                 C   s  t rtdd td| jj  | j}|  | jturB|j}|j	}|
ddddg | jrp| jdd	 | jjj}t r|jrtd
|j td| td|j	 td| |jjj}td|j ntd | |j| j | jtu r| |jjjj t r.|jD ].}|j|jrtd||j|jjf  q|jD ]P}|j|jr4|jsj| |j|jjd n| |j|jjd q4dS )z6Checking indexing counters (modify_rows, no-auto mode)r]   r^   zRunning %s.test07_noauto...r   Nr    )asar   r   @r_   r`   r  r  r  r  r  r  r  TF)r   rW   r;   r%   rB   r  r   r  r  r  Zmodify_rowsr   r   r3   r4   r  ro   r(   rp   r   rv   rK   r  r   r~   r  r  r   )r9   rB   r  r  rp   r  r,   r,   r-   test07_noauto  sN    








z'AutomaticIndexingTestCase.test07_noautoc                 C   s   t rtdd td| jj  | j}|  dd |dD }|D ]6}|jdkrDd|d	< d
|d< d|d< d|d< |  qD|	  | j
r| jdd | jjj}dd |dD }|dg }t rtd|j td| td| td| | || dS )z<Checking indexing queries (modify in iterator, no-auto mode)r]   r^   zRunning %s.test07b_noauto...c                 S   s   g | ]
}|j qS r,   r   rh   rO   r,   r,   r-   rj     r   z<AutomaticIndexingTestCase.test07b_noauto.<locals>.<listcomp>(var2 == True) & (var3 > 0)r   r  r(   Tr)   r*   r   r+   r_   r`   c                 S   s   g | ]
}|j qS r,   r   r"  r,   r,   r-   rj   
  r   AutoIndex?:Query results (original):&Query results (after modifying table):r   N)r   rW   r;   r%   rB   r  ru   r   r}   rR   r   r   r3   r4   r   rv   )r9   rB   resrO   resqres_r,   r,   r-   test07b_noauto  s2    







z(AutomaticIndexingTestCase.test07b_noautoc                 C   s   t rtdd td| jj  | j}|  dd |dD }|dg |dg |d	g |  | j	r| j
d
d | jjj}dd |dD }||jd |jd |jd g }t rtd|j td| td| td| | || dS )z0Checking indexing queries (append, no-auto mode)r]   r^   zRunning %s.test07c_noauto...c                 S   s   g | ]
}|j qS r,   r   r"  r,   r,   r-   rj     r   z<AutomaticIndexingTestCase.test07c_noauto.<locals>.<listcomp>r#  )r  Tr    r   )asbTr$   r   )ZascTr   r   r_   r`   c                 S   s   g | ]
}|j qS r,   r   r"  r,   r,   r-   rj   +  r   r   r$   r    r$  r%  r&  r   N)r   rW   r;   r%   rB   r  ru   rQ   rR   r   r   r3   r4   rK   r   rv   )r9   rB   r'  r(  r)  r,   r,   r-   test07c_noauto  s*    

 


z(AutomaticIndexingTestCase.test07c_noautoc                 C   st  t rtdd td| jj  | j}|  | jturV|j}| 	| |j
}| 	| |jdddgddggd	d
gd | jr| jdd | jjj}| |j| j | jtu r| |jjjj t r|jD ].}|j|jrtd||j|jjf  q|jD ]p}|j|jr|jsV|dv r<| |j|jjd n| |j|jjd q| |j|jjd qdS )z%Checking dirty flags (modify_columns)r]   r^   zRunning %s.test08_dirty...r    r  r+        ?       @r(   r+   columnsnamesr_   r`   r  rf   TFN)r   rW   r;   r%   rB   r  r   r  r  r   r  modify_columnsr   r   r3   r4   rv   rK   r  r   ro   r(   rp   r~   r  r  r   )r9   rB   r  r  r  r,   r,   r-   test08_dirty4  sL    








z&AutomaticIndexingTestCase.test08_dirtyc                 C   s  t rtdd td| jj  | j}| jturN|j}| | |j	}| | |j
dddd}| jr| jdd	 | jjj}| jjj}|jjj}|jjj}t rtd
| td| |rtd|j td|j | |j|j |jr| |j | jtu r| | | | n| jtu r&| | t rf|jD ]2}|j|jr2td||j|jjf  q2|jD ].}|j|jrl| |j|jjd qldS )z8Checking propagate Index feature in Table.copy() (attrs)r]   r^   zRunning %s.test09a_propIndex...r   r   Tpropindexesr_   r`   Copied index:Original index:Elements in copied index:Elements in original index:r  FN)r   rW   r;   r%   rB   r   r  r  r   r  copyr   r   r3   r4   r   ro   r(   rp   r   rv   rK   r  r   r   r  r  r  r~   r9   rB   r  r  r   index1index2r  r,   r,   r-   test09a_propIndexe  sR    














z+AutomaticIndexingTestCase.test09a_propIndexc                 C   s  t rtdd td| jj  | j}| jturN|j}| | |j	}| | |j
dddd}| jr| jdd	 | jjj}| jjj}t rtd
| jj td|jjj td|jjj | jtu r| |jjj | |jjj n,| jtu r| |jjj | |jjj dS )z%Checking that propindexes=False worksr]   r^   zRunning %s.test09b_propIndex...r   r   Fr4  r_   r`   zautoindex?:zCopied index indexed?:zOriginal index indexed?:N)r   rW   r;   r%   rB   r   r  r  r   r  r:  r   r   r3   r4   r   r   ro   r(   Z
is_indexedr  r  r   )r9   rB   r  r  r   r,   r,   r-   test09b_propIndex  s0    






z+AutomaticIndexingTestCase.test09b_propIndexc                 C   s   t rtdd td| jj  | j}| jturN|j}| | |j	}| | |j
dddd}| jr| jdd	 | jjj}| jjj}|jjj}|jjj}t rtd
| td| |rtd|j td|j dS )z9Checking propagate Index feature in Table.copy() (values)r]   r^   zRunning %s.test10_propIndex...r   r   Tr4  r_   r`   r6  r7  r8  r9  N)r   rW   r;   r%   rB   r   r  r  r   r  r:  r   r   r3   r4   r   ro   r*   rp   r   )r9   rB   r  r  r   r<  r=  r,   r,   r-   test10_propIndex  s,    









z*AutomaticIndexingTestCase.test10_propIndexc                 C   sv  t rtdd td| jj  | j}|  | jturV|j}| 	| |j
}| 	| |jdddgddggd	d
gd |jdddd}| jr| jdd | jjj}| jjj}|jjj}|jjj}t rtd| td| |rtd|j td|j t r4|jD ]2}|j|jr td||j|jjf  q |jD ]6}|j|jr:|jr:| |j|jjd q:dS )z>Checking propagate Index feature in Table.copy() (dirty flags)r]   r^   zRunning %s.test11_propIndex...r    r  r+  r-  r.  r(   r+   r/  r   r   Tr4  r_   r`   r6  r7  r8  r9  r  FN)r   rW   r;   r%   rB   r  r   r  r  r   r  r2  r:  r   r   r3   r4   r   ro   r(   rp   r   r  r  r~   r   rv   r;  r,   r,   r-   test11_propIndex  sL    












z*AutomaticIndexingTestCase.test11_propIndex)r%   r&   r'   r   r  r   r   rV   r2   r  r
  r  r  r  r  r!  r*  r,  r3  r>  r?  r@  rA  r   r,   r,   r:   r-   r     s&   !"%-"6%!19&#r   c                   @   s    e Zd ZdZdZeZg dZdS )AI1TestCasef   r   r   Nr%   r&   r'   rK   r   r  r   r   r,   r,   r,   r-   rB    s   rB  c                   @   s    e Zd ZdZdZeZg dZdS )AI2TestCaserC  r    r   NrD  r,   r,   r,   r-   rE  '  s   rE  c                   @   s    e Zd ZdZdZeZg dZdS )AI4bTestCasep   r    r   NrD  r,   r,   r,   r-   rF  /  s   rF  c                   @   s<   e Zd Zeedd\ZZZZed d Z	dZ
eZg dZdS )AI5TestCaser    Zmemlevel   r   r   Nr%   r&   r'   r   r   sbsbsr   csrK   r   r  r   r   r,   r,   r,   r-   rH  7  s
   rH  c                   @   s<   e Zd Zeedd\ZZZZed d Z	dZ
eZg dZdS )AI6TestCaser    rI     r   NrK  r,   r,   r,   r-   rO  ?  s
   rO  c                   @   s<   e Zd Zeedd\ZZZZed d Z	dZ
eZg dZdS )AI7TestCaser    rI     r   r   NrK  r,   r,   r,   r-   rQ  G  s
   rQ  c                   @   s<   e Zd Zeedd\ZZZZed d Z	dZ
eZg dZdS )AI8TestCaser    rI  r   r   r   NrK  r,   r,   r,   r-   rS  P  s
   rS  c                   @   s0   e Zd Zeedd\ZZZZeZ	dZ
eZg ZdS )AI9TestCaser    rI  r   N)r%   r&   r'   r   r   rL  rM  r   rN  rK   r   r  r   r   r,   r,   r,   r-   rT  Y  s
   rT  c                   @   s   e Zd ZdZdZeZg ZdS )AI10TestCaserC  r    N)r%   r&   r'   rK   r   r  r   r   r,   r,   r,   r-   rU  a  s   rU  c                   @   s    e Zd ZdZdZeZg dZdS )AI11TestCaserC  r   r   Nr%   r&   r'   rK   r   r	  r   r   r,   r,   r,   r-   rV  i  s   rV  c                   @   s    e Zd ZdZdZeZg dZdS )AI12TestCaserC  r   r   NrW  r,   r,   r,   r-   rX  q  s   rX  c                   @   s   e Zd ZeddZdd ZdS )ManyNodesTestCase@   )r   c                 C   s   t  t  t  d}tdD ]|}tdD ]n}dt| }dt| }d| }| jj|||dd}|jj  |jj  |jj	  |j
  |  q&qdS )z<Indexing many nodes in one single session (based on bug #26))f0f1f2r  chrz	/at/%s/ptr    )createparentsN)r   rL   rM   r3   rJ   ro   r[  rU   r\  r]  rO   rQ   rR   )r9   Z	IdxRecordZqnZsnZqchrnamepathrB   r,   r,   r-   test00|  s"    
zManyNodesTestCase.test00N)r%   r&   r'   r   Zopem_kwargsrb  r,   r,   r,   r-   rY  y  s   
rY  c                       s\   e Zd ZdZG dd dejZe Zedej	dddZ
 fdd	Zd
d Zdd Z  ZS )IndexPropsChangeTestCasez3Test case for changing index properties in a table.c                   @   s   e Zd Ze ZdS )z&IndexPropsChangeTestCase.MyDescriptionN)r%   r&   r'   r   icolr,   r,   r,   r-   MyDescription  s   re  F	   r>   r   c                    sd   t t|   | jdd| j}| jj|_|j	}t
dD ]}|d |d< |  q8|  || _d S )Nr   testr      rd  )r1   rc  r2   r3   rJ   re  oldIndexPropsr   r   rO   rL   rQ   rR   rB   )r9   rB   rO   rZ   r:   r,   r-   r2     s    

zIndexPropsChangeTestCase.setUpc                 C   s4   | j | jfD ]"}| | jj|j | jj| j_qdS )z-Storing index properties as table attributes.N)rj  newIndexPropsrv   rB   r   r   )r9   Zrefpropsr,   r,   r-   test_attributes  s    z(IndexPropsChangeTestCase.test_attributesc                 C   s&   | j }|dd}| |j|j dS )z$Copying index properties attributes.r   Ztest2N)rB   r:  rv   r   )r9   ZoldtableZnewtabler,   r,   r-   test_copyattrs  s    z'IndexPropsChangeTestCase.test_copyattrs)r%   r&   r'   __doc__rF   r   re  r   rj  rG   rk  r2   rl  rm  r   r,   r,   r:   r-   rc    s   rc  c                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )IndexFiltersTestCasez$Test case for setting index filters.c                    s.   t t|   dt i}| jdd|| _d S )Nrd  r   rh  )r1   ro  r2   r   r3   rJ   rB   )r9   Zdescriptionr:   r,   r-   r2     s    
zIndexFiltersTestCase.setUpc                 C   s   t  t}tj |_t  t}tj |_tj |_| jjj}|jddd | |j	j
d | |j	jd | |j	jt |  |jdd|d | |j	j
d | |j	jd | |j	j| |  dS )z)Checking input parameters in new indexes.Z
ultralightr   kindoptlevelmediumr   rq  rr  rI   N)r:  r   r@   rA   rB   ro   rd  rU   rv   rp   rq  rr  rI   r   )r9   Z
argfiltersZ
idxfiltersrd  r,   r,   r-   test_createIndex  s     





z%IndexFiltersTestCase.test_createIndexc                 C   s   | j jj}|jddtjddd |jj}|jj}|jj	}|
  |j}trvtd|||f  td|j|j|j	f  | |j| | |j| | |j	| dS )	z0Checking input parameters in recomputed indexes.fullr  r   rg  rt  zOld parameters: %s, %s, %szNew parameters: %s, %s, %sN)rB   ro   rd  rU   rF   rG   rp   rq  rr  rI   Zreindexr   rW   rv   )r9   rd  rq  rr  rI   Znir,   r,   r-   test_reindex  s"    
z!IndexFiltersTestCase.test_reindex)r%   r&   r'   rn  r2   ru  rw  r   r,   r,   r:   r-   ro    s   ro  c                   @   s   e Zd ZedZdd ZdS )OldIndexTestCasezidx-std-1.x.h5c                 C   s   |  t| jjd dS )z<Check that files with 1.x indexes are recognized and warned.r   N)ZassertWarnsr   r3   get_noder8   r,   r,   r-   test1_x  s    zOldIndexTestCase.test1_xN)r%   r&   r'   r   rn   rz  r,   r,   r,   r-   rx    s   rx  )i          r   c                       s  e Zd ZdZdZdZG dd dej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d.d/ Zd0d1 Zd2d3 Zd4d5 Z d6d7 Z!d8d9 Z"d:d; Z#d<d= Z$d>d? Z%d@dA Z&dBdC Z'dDdE Z(dFdG Z)dHdI Z*dJdK Z+dLdM Z,dNdO Z-dPdQ Z.dRdS Z/dTdU Z0dVdW Z1dXdY Z2dZd[ Z3d\d] Z4d^d_ Z5  Z6S )`CompletelySortedIndexTestCasez1Test case for testing a complete sort in a table.r   rJ  c                   @   s    e Zd ZeddZeddZdS )z+CompletelySortedIndexTestCase.MyDescriptionr    r   r$   Nr%   r&   r'   r   rcolrd  r,   r,   r,   r-   re    s   
re  c                    s   t t|   | jdd| j}|j}| j}t|D ] }||d< || |d< |	  q4|
  || _| jjj| _| jjtd d S )Nr   rB   r  rd  rD   )r1   r}  r2   r3   rJ   re  rO   rK   rL   rQ   rR   rB   ro   rd  create_csindexrV   r9   rB   rO   rK   rZ   r:   r,   r-   r2     s    
z#CompletelySortedIndexTestCase.setUpc                 C   s   | j }| |jjd |  |jddd | |jjd |  |jddd | |jjd | jjdd	d
dd | |jjd dS )z#Testing the Column.is_csi property.Trs  rf  rp  Frv  r   r   r   rd  sortbycheckCSIN)rd  rv   rp   is_csir   rU   rB   r:  )r9   rd  r,   r,   r-   test00_isCompletelySortedIndex  s    z<CompletelySortedIndexTestCase.test00_isCompletelySortedIndexc                 C   sN   | j }t|dd }|j }tr:td| td| | t|| dS )z9Testing the Index.read_sorted() method with no arguments.NOriginal sorted column:The values from the index:	rd  r   r   rp   read_sortedr   rW   r   r   r9   rd  Z	sortedcolZ
sortedcol2r,   r,   r-   test01_readSorted1"  s    


z0CompletelySortedIndexTestCase.test01_readSorted1c                 C   sZ   | j }t|dd dd }|jdd}trFtd| td| | t|| dS )z:Testing the Index.read_sorted() method with arguments (I).N   7   r  r  r  r  r,   r,   r-   test01_readSorted2-  s    

z0CompletelySortedIndexTestCase.test01_readSorted2c                 C   sZ   | j }t|dd dd }|jdd}trFtd| td| | t|| dS )z;Testing the Index.read_sorted() method with arguments (II).N!   a   r  r  r  r  r,   r,   r-   test01_readSorted38  s    

z0CompletelySortedIndexTestCase.test01_readSorted3c                 C   sT   | j }t|dd d}|j }tr@td| td| | t	|| dS )z:Testing the Index.read_indices() method with no arguments.Nuint64Original indices column:r  
rd  r   argsortastyperp   Zread_indicesr   rW   r   r   r9   rd  Z
indicescolZindicescol2r,   r,   r-   test02_readIndices1C  s    


z1CompletelySortedIndexTestCase.test02_readIndices1c                 C   s`   | j }t|dd dd d}|jdd}trLtd| td| | t	|| dS )z;Testing the Index.read_indices() method with arguments (I).Nr  r  r  r  r  r  r  r,   r,   r-   test02_readIndices2N  s     

z1CompletelySortedIndexTestCase.test02_readIndices2c                 C   s`   | j }t|dd dd d}|jdd}trLtd| td| | t	|| dS )z<Testing the Index.read_indices() method with arguments (II).Nr  r  r  r  r  r  r  r,   r,   r-   test02_readIndices3Y  s     

z1CompletelySortedIndexTestCase.test02_readIndices3c                 C   sd   | j }t|dd ddd d}|jddd}trPtd| td| | t	|| dS )z=Testing the Index.read_indices() method with arguments (III).Nr  r  r$   r  r  r  r  r  r,   r,   r-   test02_readIndices4d  s    "

z1CompletelySortedIndexTestCase.test02_readIndices4c                 C   sd   | j }t|dd ddd d}|jddd}trPtd| td| | t	|| dS )z<Testing the Index.read_indices() method with arguments (IV).Nr  r  r  r  r  r  r  r  r,   r,   r-   test02_readIndices5o  s    "

z1CompletelySortedIndexTestCase.test02_readIndices5c                 C   sb   | j }t|dd ddd d}|jjdd}trNtd| td| | t	|| dS )z7Testing the Index.read_indices() method with step only.Nr   r  stepr  r  r  r  r,   r,   r-   test02_readIndices6z  s    "

z1CompletelySortedIndexTestCase.test02_readIndices6c                 C   sX   | j }t|dd d}|jdd }trDtd| td| | t|| dS )z9Testing the Index.__getitem__() method with no arguments.Nr  r  r  	rd  r   r  r  rp   r   rW   r   r   r  r,   r,   r-   test03_getitem1  s    

z-CompletelySortedIndexTestCase.test03_getitem1c                 C   sX   | j }t|dd d d}|jd }trDtd| td| | t|| dS )z2Testing the Index.__getitem__() method with start.N   r  r  r  r  r  r,   r,   r-   test03_getitem2  s    


z-CompletelySortedIndexTestCase.test03_getitem2c                 C   s`   | j }t|dd dd d}|jdd }trLtd| td| | t|| dS )z8Testing the Index.__getitem__() method with start, stop.Nr$   r   r  r  r  r  r  r,   r,   r-   test03_getitem3  s     

z-CompletelySortedIndexTestCase.test03_getitem3c                 C   sh   | j }tj|dd dd}tjdd |dD |jd}trTtd| td| | t	|| dS )	z8Testing the Table.itersorted() method with no arguments.Nrd  orderc                 S   s   g | ]}|  qS r,   Zfetch_all_fieldsr"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted1.<locals>.<listcomp>ZdtypeOriginal sorted table:The values from the iterator:
rB   r   r   r   Z
itersortedZ_v_dtyper   rW   r   r   r9   rB   sortedtablesortedtable2r,   r,   r-   test04_itersorted1  s    


z0CompletelySortedIndexTestCase.test04_itersorted1c                 C   st   | j }tj|dd dddd }tjdd |jdddD |jd}tr`td	| td
| | t	|| dS )z3Testing the Table.itersorted() method with a start.Nrd  r  r   c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted2.<locals>.<listcomp>startr  r  r  r  r  r,   r,   r-   test04_itersorted2  s    


z0CompletelySortedIndexTestCase.test04_itersorted2c                 C   st   | j }tj|dd dddd }tjdd |jdddD |jd}tr`td	| td
| | t	|| dS )z2Testing the Table.itersorted() method with a stop.Nrd  r     c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted3.<locals>.<listcomp>)stopr  r  r  r  r  r,   r,   r-   test04_itersorted3  s    


z0CompletelySortedIndexTestCase.test04_itersorted3c                 C   sv   | j }tj|dd dddd }tjdd |jddddD |jd	}trbtd
| td| | t	|| dS )z<Testing the Table.itersorted() method with a start and stop.Nrd  r  r   r  c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted4.<locals>.<listcomp>r  r  r  r  r  r  r  r,   r,   r-   test04_itersorted4  s    


z0CompletelySortedIndexTestCase.test04_itersorted4c                 C   sz   | j }tj|dd ddddd }tjdd |jddddd	D |jd
}trftd| td| | t	|| dS )JTesting the Table.itersorted() method with a start, stop and
        step.Nrd  r  r   -   r   c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted5.<locals>.<listcomp>r  r  r  r  r  r  r  r  r,   r,   r-   test04_itersorted5  s     


z0CompletelySortedIndexTestCase.test04_itersorted5c                 C   sz   | j }tj|dd ddddd }tjdd |jddddd	D |jd
}trftd| td| | t	|| dS )r  Nrd  r  r  r  r  c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted6.<locals>.<listcomp>r  r  r  r  r  r  r,   r,   r-   test04_itersorted6  s     


z0CompletelySortedIndexTestCase.test04_itersorted6c                 C   sl   | j }tj|dd dd}tjdd |jdddD |jd}trXtd	| td
| | t	|| dS )z9Testing the Table.itersorted() method with checkCSI=True.Nrd  r  c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted7.<locals>.<listcomp>Tr  r  r  r  r  r  r,   r,   r-   test04_itersorted7  s    


z0CompletelySortedIndexTestCase.test04_itersorted7c                 C   sz   | j }tj|dd ddddd }tjdd |jddddd	D |jd
}trftd| td| | t	|| dS )zSTesting the Table.itersorted() method with a start, stop and
        negative step.Nrd  r  r  r  c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted8.<locals>.<listcomp>r  r  r  r  r  r  r,   r,   r-   test04_itersorted8  s     


z0CompletelySortedIndexTestCase.test04_itersorted8c                 C   sv   | j }tj|dd ddddd }tjdd |jdddD |jd}trbtd	| td
| | t	|| dS )z;Testing the Table.itersorted() method with a negative step.Nrd  r  r  c                 S   s   g | ]}|  qS r,   r  r"  r,   r,   r-   rj     r   zDCompletelySortedIndexTestCase.test04_itersorted9.<locals>.<listcomp>r  r  r  r  r  r  r,   r,   r-   test04_itersorted9  s     


z0CompletelySortedIndexTestCase.test04_itersorted9c                 C   sR   | j }tj|dd dd}|d}tr>td| td| | t|| dS )9Testing the Table.read_sorted() method with no arguments.Nrd  r  r  The values from read_sorted:rB   r   r   r  r   rW   r   r   r  r,   r,   r-   test05_readSorted1   s    


z0CompletelySortedIndexTestCase.test05_readSorted1c                 C   s^   | j }tj|dd dddd }|jddd}trJtd| td| | t|| dS )	z4Testing the Table.read_sorted() method with a start.Nrd  r  r      r  r  r  r  r  r,   r,   r-   test05_readSorted2+  s    

z0CompletelySortedIndexTestCase.test05_readSorted2c                 C   s`   | j }tj|dd dddd }|jdddd}trLtd| td| | t|| dS )	z=Testing the Table.read_sorted() method with a start and stop.Nrd  r  r   r  r  r  r  r  r  r,   r,   r-   test05_readSorted36  s    

z0CompletelySortedIndexTestCase.test05_readSorted3c                 C   sd   | j }tj|dd ddddd }|jddddd}trPtd| td	| | t|| dS )
zKTesting the Table.read_sorted() method with a start, stop and
        step.Nrd  r  r  r  r  r  r  r  r  r  r,   r,   r-   test05_readSorted4A  s     

z0CompletelySortedIndexTestCase.test05_readSorted4c                 C   s`   | j }tj|dd ddddd }|jddd}trLtd| td| | t|| dS )z8Testing the Table.read_sorted() method with only a step.Nrd  r  r   r  r  r  r  r  r,   r,   r-   test05_readSorted5M  s     

z0CompletelySortedIndexTestCase.test05_readSorted5c                 C   s`   | j }tj|dd ddddd }|jddd}trLtd| td| | t|| dS )z:Testing the Table.read_sorted() method with negative step.Nrd  r  re   r  r  r  r  r  r,   r,   r-   test05_readSorted6X  s     

z0CompletelySortedIndexTestCase.test05_readSorted6c                 C   s`   | j }tj|dd ddddd }|jddd}trLtd| td| | t|| dS )z?Testing the Table.read_sorted() method with negative step (II).Nrd  r  r  r  r  r  r  r,   r,   r-   test05_readSorted7c  s     

z0CompletelySortedIndexTestCase.test05_readSorted7c                 C   sl   | j }d}d}tj|dd dd||d }|jddddd	}trXtd
| td| | t|| dS )zATesting the Table.read_sorted() method with negative step (III)).K   r  Nrd  r  re   r   6   r  r  r  r  r9   rB   ZsstartZsstopr  r  r,   r,   r-   test05_readSorted8n  s     

z0CompletelySortedIndexTestCase.test05_readSorted8c                 C   sl   | j }d}d}tj|dd dd||d }|jddddd	}trXtd
| td| | t|| dS )z@Testing the Table.read_sorted() method with negative step (IV)).U   r  Nrd  r     r  r  r  r  r  r  r,   r,   r-   test05_readSorted9{  s     

z0CompletelySortedIndexTestCase.test05_readSorted9c                 C   sl   | j }d}d}tj|dd dd||d }|jddddd	}trXtd
| td| | t|| dS )z?Testing the Table.read_sorted() method with negative step (V)).r  J   Nrd  r  r  r   ri  r  r  r  r  r  r,   r,   r-   test05_readSorted10  s     

z1CompletelySortedIndexTestCase.test05_readSorted10c                 C   sl   | j }d}d}tj|dd dd||d }|jddddd	}trXtd
| td| | t|| dS )z9Testing the Table.read_sorted() method with start > stop.ir  Nrd  r  r     ri  r  r  r  r  r  r,   r,   r-   test05_readSorted11  s     

z1CompletelySortedIndexTestCase.test05_readSorted11c                 C   sV   | j }tj|dd dd}|jddd}trBtd| td| | t|| dS )z9Testing the Table.read_sorted() method with checkCSI (I).Nrd  r  Tr  r  r  r  r  r,   r,   r-   test05a_readSorted12  s    

z2CompletelySortedIndexTestCase.test05a_readSorted12c                 C   s   | j }| jt|jddd dS )z:Testing the Table.read_sorted() method with checkCSI (II).r  Fr  N)rB   assertRaises
ValueErrorr  r  r,   r,   r-   test05b_readSorted12  s    z2CompletelySortedIndexTestCase.test05b_readSorted12c                 C   sl   | j }| j|_|jdddd}tj|dd dd}|dd }trXtd| td| | t|| dS )	z8Testing the Table.copy(sortby) method with no arguments.r   r   rd  r  Nr  r  The values from copy:	rB   rq   r:  r   r   r   rW   r   r   r9   rB   r   r  r  r,   r,   r-   test06_copy_sorted1  s    

z1CompletelySortedIndexTestCase.test06_copy_sorted1c                 C   sx   | j }| j|_|jddddd}tj|dd ddddd }|dd }trdtd| td	| | t|| dS )
z3Testing the Table.copy(sortby) method with step=-1.r   r   rd  re   )r  r  Nr  r  r  r  r  r,   r,   r-   test06_copy_sorted2  s     

z1CompletelySortedIndexTestCase.test06_copy_sorted2c                 C   sv   | j }| j|_|jddddd}tj|dd dddd }|dd }trbtd	| td
| | t|| dS )z8Testing the Table.copy(sortby) method with only a start.r   r   rd  r   )r  r  Nr  r   r  r  r  r  r,   r,   r-   test06_copy_sorted3  s    

z1CompletelySortedIndexTestCase.test06_copy_sorted3c                 C   sx   | j }| j|_|jdddddd}tj|dd dddd }|dd }trdtd	| td
| | t|| dS )z7Testing the Table.copy(sortby) method with start, stop.r   r   rd  r   (   )r  r  r  Nr  r  r  r  r  r,   r,   r-   test06_copy_sorted4  s    

z1CompletelySortedIndexTestCase.test06_copy_sorted4c                 C   s|   | j }| j|_|jddddddd}tj|dd dd	ddd }|dd }trhtd
| td| | t|| dS )z=Testing the Table.copy(sortby) method with start, stop, step.r   r   rd  r   r  r  )r  r  r  r  Nr  r  r  r  r  r,   r,   r-   test06_copy_sorted5  s    
 

z1CompletelySortedIndexTestCase.test06_copy_sorted5c                 C   s|   | j dd | jjj}| j|_|jdddd}tj|dd dd}|dd }trht	d	| t	d
| | 
t|| dS )=Testing the Table.copy(sortby) method after table re-opening.r_   r`   r   r   rd  r  Nr  r  r  r   r3   r4   rB   rq   r:  r   r   r   rW   r   r   r  r,   r,   r-   test06_copy_sorted6  s    


z1CompletelySortedIndexTestCase.test06_copy_sorted6c                 C   s:   | j }| j|_|jdddd}| jt|jddddd d	S )
z5Testing the `checkCSI` parameter of Table.copy() (I).r   r   rd  r  table3r  Fr  NrB   rq   r:  r  r  r9   rB   r   r,   r,   r-   test06_copy_sorted7
	  s    z1CompletelySortedIndexTestCase.test06_copy_sorted7c                 C   s:   | j }| j|_|jdddd}| jt|jddddd d	S )
z6Testing the `checkCSI` parameter of Table.copy() (II).r   r   rd  r  r  r  Tr  Nr  r  r,   r,   r-   test06_copy_sorted8	  s    z1CompletelySortedIndexTestCase.test06_copy_sorted8c                 C   sT   | j dd| j}|jj }tr0tdt| | 	|d | 	|j
d jd dS )z8Testing the representation of an index with no elements.r   t2zrepr(t2)-->
r   r  FN)r3   rJ   re  ro   r  r  r   rW   reprrv   
colindexesr  )r9   r  Zirowsr,   r,   r-   test07_isCSI_noelements"	  s    z5CompletelySortedIndexTestCase.test07_isCSI_noelements)7r%   r&   r'   rn  rK   rq   rF   r   re  r2   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  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r,   r,   r:   r-   r}    sb   r}  c                       sZ   e Zd ZdZdZdZG dd dejZ fddZ	dd	 Z
d
d Zdd Zdd Z  ZS )ReadSortedIndexTestCasez?Test case for testing sorted reading in a "full" sorted column.r   rJ  c                   @   s    e Zd ZeddZeddZdS )z%ReadSortedIndexTestCase.MyDescriptionr    r   r$   Nr~  r,   r,   r,   r-   re  3	  s   
re  c                    s   t t|   | jdd| j}|j}| j}t|D ] }||d< || |d< |	  q4|
  || _| jjj| _| jj| jdtd d S )Nr   rB   r  rd  rv  )rr  rq  rE   )r1   r  r2   r3   rJ   re  rO   rK   rL   rQ   rR   rB   ro   rd  rU   rr  rV   r  r:   r,   r-   r2   7	  s    
zReadSortedIndexTestCase.setUpc                 C   s\   | j }tj|dd dd}|d}tr>td| td| | t|tj|dd dS )r  Nrd  r  Sorted table:r  r  r  r,   r,   r-   r  H	  s    


z*ReadSortedIndexTestCase.test01_readSorted1c                 C   sh   |    | jjj}tj|dd dd}|d}trJtd| td| | 	t
|tj|dd dS )zKTesting the Table.read_sorted() method with no arguments
        (re-open).Nrd  r  r  r  )r   r3   r4   rB   r   r   r  r   rW   r   r   r  r,   r,   r-   r  V	  s    



z*ReadSortedIndexTestCase.test01_readSorted2c                 C   s~   | j }| j|_|jdddd}tj|dd dd}tj|dd dd}trjtd|dd  td| | t|| dS )	z&Testing the Table.copy(sortby) method.r   r   rd  r  Nr  Original table:The sorted values from copy:r  r  r,   r,   r-   test02_copy_sorted1f	  s    
z+ReadSortedIndexTestCase.test02_copy_sorted1c                 C   s   | j dd | jjj}| j|_|jdddd}tj|dd dd}tj|dd dd}trzt	d	|dd  t	d
| | 
t|| dS )r  r_   r`   r   r   rd  r  Nr  r  r  r  r  r,   r,   r-   test02_copy_sorted2t	  s    

z+ReadSortedIndexTestCase.test02_copy_sorted2)r%   r&   r'   rn  rK   rq   rF   r   re  r2   r  r  r  r  r   r,   r,   r:   r-   r  -	  s   r  c                   @   s   e Zd ZdZdS )ReadSortedIndex0r   Nr%   r&   r'   rr  r,   r,   r,   r-   r  	  s   r  c                   @   s   e Zd ZdZdS )ReadSortedIndex3r   Nr  r,   r,   r,   r-   r  	  s   r  c                   @   s   e Zd ZdZdS )ReadSortedIndex6r   Nr  r,   r,   r,   r-   r  	  s   r  c                   @   s   e Zd ZdZdS )ReadSortedIndex9rf  Nr  r,   r,   r,   r-   r  	  s   r  c                       s(   e Zd ZdZ fddZdd Z  ZS )Issue156TestBaseNc                    s   t t|   G dd dtj}| jjdd|tdddd}| j  t	d	D ]6}|j
}tjd
d|d< tjd
d|d< |  qP| j  d S )Nc                   @   s$   e Zd Ze ZG dd dejZdS )z#Issue156TestBase.setUp.<locals>.Fooc                   @   s   e Zd Ze ZdS )z'Issue156TestBase.setUp.<locals>.Foo.BarN)r%   r&   r'   r	   coder,   r,   r,   r-   Bar	  s   r  N)r%   r&   r'   r	   r   rF   r   r  r,   r,   r,   r-   Foo	  s   r  r   Zfoor   r/   T)rI   r_  r   r   i  r   Bar/code)r1   r   r2   rF   r   r3   rJ   rG   rR   rL   rO   r   ZrandomZrandintrQ   )r9   r  rB   krO   r:   r,   r-   r2   	  s    


zIssue156TestBase.setUpc              	   C   s   | j d}|j| j   |jdd| jddd}| t|	| jt
|	| jk | | j|j | |j| j j d S )Nz/fooZfoo2T)ZnewnameZ	overwriter  r  r5  )r3   ry  rS   
sort_fieldr  r:  r   r   allr[   rs   ZassertInr  r  )r9   ZoldNodeZnew_noder,   r,   r-   test_copysort	  s    
zIssue156TestBase.test_copysort)r%   r&   r'   r  r2   r  r   r,   r,   r:   r-   r   	  s   r   c                   @   s   e Zd ZdZdS )Issue156TestCase01r   Nr%   r&   r'   r  r,   r,   r,   r-   r	  	  s   r	  c                   @   s   e Zd ZdZdS )Issue156TestCase02r  Nr
  r,   r,   r,   r-   r  	  s   r  c                       s6   e Zd ZdZejZg dZ fddZdd Z	  Z
S )Issue119Time32ColTestCasezTimeCol not properly indexing.)
gmA?gv9Tl?g|^?g?f3?gȍL?g?:v?gTyL?gL\0Z?g}g?gt
?c                    sn   t t   G  fdddtj} jdd| _d _ fddt	 j
D } j|  j  d S )Nc                       s"   e Zd Z jddZeddZdS )z.Issue119Time32ColTestCase.setUp.<locals>.Descrr    r   r$   N)r%   r&   r'   col_typwhenr
   valuer,   r8   r,   r-   Descr	  s   r  r   rh  g  UAc                    s   g | ]\}} j | |fqS r,   )t)rh   rZ   itemr8   r,   r-   rj   	  r   z3Issue119Time32ColTestCase.setUp.<locals>.<listcomp>)r1   r  r2   rF   r   r3   rJ   rB   r  r|   rT   rQ   rR   )r9   r  datar:   r8   r-   r2   	  s    zIssue119Time32ColTestCase.setUpc                 C   sV   | j }| j}d||d f }||}|jjjdd ||}| ||k  d S )Nz(when >= %d) & (when < %d)r  F)Z_verbose)rB   r  
read_wherero   r  rU   r   r  )r9   Ztblr  ZwherestrZno_indexZ
with_indexr,   r,   r-   test_timecol_issue	  s    

z,Issue119Time32ColTestCase.test_timecol_issue)r%   r&   r'   rn  rF   Z	Time32Colr  rT   r2   r  r   r,   r,   r:   r-   r  	  s
   r  c                   @   s   e Zd ZejZdS )Issue119Time64ColTestCaseN)r%   r&   r'   rF   Z	Time64Colr  r,   r,   r,   r-   r  	  s   r  c                   @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
TestIndexingNansc                 C   s   t  t d}| jdd|}|j}tdD ]*}||d< |dkrFtjn||d< |  q,|	  |j
j  |d}| t|d	 d S )
N)rp   rT   r   rB   r  rp   r   rT   z(values >= 0)r   )r   r   r3   rJ   rO   rL   r   nanrQ   rR   ro   rT   rU   r  rv   rw   )r9   ZtrMaprB   r   rZ   resultr,   r,   r-   test_issue_282
  s    

zTestIndexingNans.test_issue_282c              
   C   s   | j ddtt tddtddd}|j}tdD ]:}||d< |dksR|d	krXtjn||d
< ||d< |	  q6|
  |jj  |jj  |d}| t|d |d}| t|d d S )Nr   rB   r,   shaperp   rT   values2r  rp   r$   r   rT   r  (values2 > 0)r   (values > 0))r3   rJ   r   r   r   rO   rL   r   r  rQ   rR   ro   rT   rU   r  r  rv   rw   )r9   rB   r   rZ   results2ry   r,   r,   r-   test_issue_327
  s$    


zTestIndexingNans.test_issue_327c              
   C   s   | j ddtt tddtddd}|j}tdD ]H}tdD ]:}||d< |d	ks^|d
krdtjn||d< ||d< |	  qBq6|
  |jjjtd |jjjtd |d}| t|d |d}| t|d d S Nr   rB   r,   r  r  r   r  rp   r$   r   rT   r  rD   r  i  r      )r3   rJ   r   r   r   rO   rL   r   r  rQ   rR   ro   rT   rU   rV   r  r  rv   rw   )r9   rB   r   r   rZ   r!  ry   r,   r,   r-   test_issue_327_b-
  s&    

z!TestIndexingNans.test_issue_327_bc              
   C   s   | j ddtt tddtddd}|j}tdD ]H}tdD ]:}||d< |d	ks^|d
krdtjn||d< ||d< |	  qBq6|
  |jjjtd |jjjtd |d}| t|d |d}| t|d d S r#  )r3   rJ   r   r   r   rO   rL   r   r  rQ   rR   ro   rT   r  rV   r  r  rv   rw   )r9   rB   r   xrZ   r!  ry   r,   r,   r-   test_csindex_nansF
  s&    

z"TestIndexingNans.test_csindex_nansN)r%   r&   r'   r  r"  r%  r'  r,   r,   r,   r-   r  
  s   r  c                  C   sv  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 | 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t"rr| t t# | t t$ | t t% | t t& | t t' | t t( | t t) | t t* | S )Nr    )+r   Z	TestSuiterL   ZaddTestZ	makeSuiter   r   r   r   r   r   r   r   r   r   r   rB  rE  rT  r   rc  ro  rx  r}  rY  r  r  r  r  r	  r  r  r  r  r   rF  rH  rO  rQ  rS  rU  rV  rX  )ZtheSuiteZniternr,   r,   r-   suite`
  sT    r)  __main__)ZdefaultTest)ar   r:  r   r   rF   r   r   r   r   r   r   r   r	   r
   Ztables.indexr   r   r   Ztables.idxutilsr   Ztables.exceptionsr   Ztables.testsr   Ztables.tests.commonr   r   r   r   r   r   r   ZTestCaser   rV   r   r   r.   r   r   r   ZskipIfZblosc_availr   Z	lzo_availr   Zbzip2_availr   r   r   r   r   r   r   r   objectr   r  r  rG   r	  r   rB  rE  rF  rH  rO  rQ  rS  rT  rU  rV  rX  rY  rc  ro  ZTestFileMixinrx  r}  r  r  r  r  r  r   r	  r  r  r  r  r)  r%   sysZ
parse_argvargvZprint_versionsmainr,   r,   r,   r-   <module>   s   ,     :

 
    Z		!6
    :W4-]2
