a
    v=ic                    @   s:  d Z ddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddlmZmZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ ddlZddlm  m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Z!G dd d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&e
'dej(j)vd G d!d" d"eZ*e
'dej(j)vd G d#d$ d$eZ+e
'd%ej(j)vd&G d'd( d(eZ,e
'd)ej(j)vd*G d+d, d,eZ-e
'd-ej(j)vd.G d/d0 d0eZ.e
'd1ej(j)vd2G d3d4 d4eZ/e
'd5ej(j)vd6G d7d8 d8eZ0G d9d: d:eZ1G d;d< d<eZ2G d=d> d>eZ3G d?d@ d@eZ4G dAdB dBeZ5G dCdD dDeZ6G dEdF dFeZ7G dGdH dHeZ8G dIdJ dJeZ9G dKdL dLeZ:G dMdN dNeZ;G dOdP dPeZ<G dQdR dReZ=G dSdT dTeZ>G dUdV dVeZ?ej@jAejjBdWkdXdYZCG dZd[ d[eZDG d\d] d]eZEG d^d_ d_eZFG d`da daeZGG dbdc dceZHe
IejjBddkdedfdg ZJdhdi ZKdjdk ZLdldm ZMdndo ZNdpdq ZOdrds ZPej@jQejjBdtk dudYdvdw ZRG dxdy dyeZSG dzd{ d{eZTdS )|z
    Dataset testing operations.

    Tests all dataset operations, including creation, with the exception of:

    1. Slicing operations for read and write, handled by module test_slicing
    2. Type conversion for read and write (currently untested)
    N   )utTestCase)get_data_file_path)FileGroupDataset)is_empty_dataspace)h5fh5t)H5pyDeprecationWarning)versionc                   @   s   e Zd Zdd Zdd ZdS )BaseDatasetc                 C   s   t |  d| _d S )Nw)r   mktempfself r   h/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/h5py/tests/test_dataset.pysetUp'   s    zBaseDataset.setUpc                 C   s   | j r| j   d S N)r   closer   r   r   r   tearDown*   s    zBaseDataset.tearDownN)__name__
__module____qualname__r   r   r   r   r   r   r   &   s   r   c                   @   s   e Zd ZdZdd ZdS )TestReprz5
        Feature: repr(Dataset) behaves sensibly
    c                 C   s<   | j dd}| t|t | j   | t|t dS )z( repr() works on live and dead datasets foo   N)r   create_datasetassertIsInstancereprstrr   r   dsr   r   r   test_repr_open4   s    
zTestRepr.test_repr_openN)r   r   r   __doc__r'   r   r   r   r   r   /   s   r   c                   @   st   e Zd Z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eeed ddd Zdd ZdS )TestCreateShapez@
        Feature: Datasets can be created from a shape only
    c                 C   s    | j dd}| |jd dS )z Create a scalar dataset r   r   Nr   r!   assertEqualshaper   dsetr   r   r   test_create_scalarB   s    z"TestCreateShape.test_create_scalarc                 C   s    | j dd}| |jd dS )z Create a size-1 dataset r   r   Nr*   r-   r   r   r   test_create_simpleG   s    z"TestCreateShape.test_create_simplec                 C   s    | j dd}| |jd dS )z+ Create a size-1 dataset with integer shaper   r   r0   Nr*   r-   r   r   r   test_create_integerL   s    z#TestCreateShape.test_create_integerc                 C   sX   | j dd}| |jd | |jd | j dd}| |jd | |jd dS ) Create an extended dataset r   ?   r5   bar   
   <   Nr   r!   r+   r,   sizer-   r   r   r   test_create_extendedQ   s    z$TestCreateShape.test_create_extendedc                 C   sX   | j dd}| |jd | |jd | j dd}| |jd | |jd dS )r3   r   r5   r4   r6   r7   r:   Nr;   r-   r   r   r   test_create_integer_extendedZ   s    z,TestCreateShape.test_create_integer_extendedc                 C   s&   | j dd}| |jtd dS )) Confirm that the default dtype is float r   r4   z=f4Nr   r!   r+   dtypenpr-   r   r   r   test_default_dtypec   s    z"TestCreateShape.test_default_dtypec                 C   s:   |  t | jd W d   n1 s,0    Y  dS )z  Missing shape raises TypeError r   NassertRaises	TypeErrorr   r!   r   r   r   r   test_missing_shapeh   s    z"TestCreateShape.test_missing_shapec                 C   sF   | j jddtjd}t dv r2tdt   | |j	tj dS )r?   r   r4   rA   )ppc64lez(Storage of long double deactivated on %sN)
r   r!   rB   Z
longdoubleplatformmachinepytestxfailr+   rA   r-   r   r   r   test_long_doublem   s    z TestCreateShape.test_long_double
complex256zNo support for complex256c                 C   s0   | j jddtdd}| |jtd dS )r?   r   r4   rO   rH   N)r   r!   rB   rA   r+   r-   r   r   r   test_complex256t   s    
zTestCreateShape.test_complex256c                 C   s<   | j dd}| |jd | j dd}| |jd d S )Ns   foor0   s   bar/baz)   r*   r   r.   dset2r   r   r   test_name_bytes{   s    zTestCreateShape.test_name_bytesN)r   r   r   r(   r/   r1   r2   r=   r>   rC   rG   rN   r   skipIfhasattrrB   rP   rT   r   r   r   r   r)   <   s   		
r)   c                   @   sx   e Zd Z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S )TestCreateDatazA
        Feature: Datasets can be created from existing data
    c                 C   s0   t dd}| jjd|d}| |j|j dS )z- Create a scalar dataset from existing array r   r   r   dataNrB   onesr   r!   r+   r,   r   rY   r.   r   r   r   r/      s    z!TestCreateData.test_create_scalarc                 C   s0   t dd}| jjd|d}| |j|j dS )z/ Create an extended dataset from existing data r4   r   r   rX   NrZ   r\   r   r   r   r=      s    z#TestCreateData.test_create_extendedc                 C   s4   | j jdddd}| |tj | d| j v  dS )z1 Create dataset with missing intermediate groups z/foo/bar/bazr9   r9   z<i4)r,   rA   N)r   r!   r"   h5pyr   
assertTruer%   r   r   r   test_dataset_intermediate_group   s    z.TestCreateData.test_dataset_intermediate_groupc                 C   sH   t jddd}| jjdd|d}| |jd | |d |d dS )	z8 Create from existing data, and make it fit a new shape    r   rH   r   r9      r,   rY   .N)rB   aranger   r!   r+   r,   assertArrayEqualreshaper\   r   r   r   test_reshape   s    zTestCreateData.test_reshapec                 C   s>   |  t  t| jd j W d   n1 s00    Y  dS )zE Binding Dataset to a non-DatasetID identifier fails with ValueError /N)rE   
ValueErrorr   r   idr   r   r   r   test_appropriate_low_level_id   s    z,TestCreateData.test_appropriate_low_level_idc                 C   s`   |j  }t|tjsJ | |ks*J |d u r@| s\J n| rLJ | |ks\J d S r   )rk   get_type
isinstancer   TypeStringIDget_csetis_variable_strget_size)r   r.   csetlengthtidr   r   r   check_h5_string   s    
zTestCreateData.check_h5_stringc                    sz    fdd}| j jddd | j jdddgd | j jddgdggd | j jd	tjddgtd
d dS )z= Creating dataset with byte string yields vlen ASCII dataset c                    s    j | tjd d d S Nrt   )rv   r   
CSET_ASCIIr.   r   r   r   check_vlen_ascii   s    z?TestCreateData.test_create_bytestring.<locals>.check_vlen_asciia   abcrX   b   defcdrH   Nr   r!   rB   arrayobject)r   r{   r   r   r   test_create_bytestring   s    z%TestCreateData.test_create_bytestringc                 C   s4   | j jdtjddgddd}| j|tjdd d S )	Nr|   r}   r   ZS3rH   rX   rc   rx   )r   r!   rB   r   rv   r   ry   r-   r   r   r   test_create_np_s   s    zTestCreateData.test_create_np_sc                    sz    fdd}| j jddd | j jdddgd | j jddgdggd | j jd	tjddgtd
d d S )Nc                    s    j | tjd d d S rw   )rv   r   	CSET_UTF8rz   r   r   r   check_vlen_utf8   s    z;TestCreateData.test_create_strings.<locals>.check_vlen_utf8r|   abcrX   r~   defr   r   rH   r   )r   r   r   r   r   test_create_strings   s    z"TestCreateData.test_create_stringsc                 C   sL   |  t. | jjdtjddgddd W d    n1 s>0    Y  d S )Nr|   r}   r   ZU3rH   rX   )rE   rF   r   r!   rB   r   r   r   r   r   test_create_np_u   s    zTestCreateData.test_create_np_uc                 C   s*   | j jddd | t| j d j d S )Nr   r   rH   )r   r!   r_   r	   rk   r   r   r   r    test_empty_create_via_None_shape   s    z/TestCreateData.test_empty_create_via_None_shapec                 C   s2   | j jdtjddd | t| j d j d S )Nr   r   rH   rX   )r   r!   r^   Emptyr_   r	   rk   r   r   r   r   !test_empty_create_via_Empty_class   s    z0TestCreateData.test_empty_create_via_Empty_classc                 C   sF   |  t( | jjddtdd W d    n1 s80    Y  d S )Nr6   r    rc   rd   )rE   rj   r   r!   rB   re   r   r   r   r   test_create_incompatible_data   s    z,TestCreateData.test_create_incompatible_dataN)r   r   r   r(   r/   r=   r`   rh   rl   rv   r   r   r   r   r   r   r   r   r   r   r   rW      s   

rW   c                   @   s   e Zd ZdZejdddejdd ejdd fddejdd ejd	d
 fddejd
dd
d
f ejd
d
d
df fddejdd
ddf ejd
d
 fgdd Z	dd Z
dd Zdd Zdd Zd
S )TestReadDirectlyzI
        Feature: Read data directly from Dataset into a Numpy array
    +source_shape,dest_shape,source_sel,dest_seld   r   r9   2   r:   F   Z   Nra   r9      r   r         	   r8   rQ   r8   rc   c           
      C   sn   t jt |dd|}|jd||d}t j|ddd}| }	|| |	|< |||| t j	||	 d S )Nint64rH   r.   rX   )
rB   re   productrg   r!   fullcopyread_directtestingassert_array_equal)
r   writable_filesource_shape
dest_shape
source_seldest_selZsource_valuesr.   arrexpectedr   r   r   test_read_direct   s    	z!TestReadDirectly.test_read_directc                 C   sN   |j ddtjdddd}tjddd}|| tj|tjddd d S )Nr.   r9   r9   r   rH   rX   )r!   rB   re   r[   r   r   r   r   r   r.   r   r   r   r   test_no_sel   s    
zTestReadDirectly.test_no_selc                 C   sj   |j ddd}tdd}tt2 ||tjdd tjdd  W d    n1 s\0    Y  d S 	NZedsetr   rH   r   r   r9   r   r:   )r!   rB   r[   rL   raisesrF   r   s_)r   r   
empty_dsetr   r   r   r   
test_empty   s    zTestReadDirectly.test_emptyc                 C   sR   |j dddd}td}tt || W d    n1 sD0    Y  d S Nr.   r   r   rH      r!   rB   r[   rL   r   rF   r   r   r   r   r   test_wrong_shape   s    
z!TestReadDirectly.test_wrong_shapec                 C   sV   |j dddd}tjddd}tt || W d    n1 sH0    Y  d S Nr.   r]   r   rH   F)orderr   r   r   r   r   test_not_c_contiguous  s    z&TestReadDirectly.test_not_c_contiguous)r   r   r   r(   rL   markparametrizerB   r   r   r   r   r   r   r   r   r   r   r      s   .$

r   c                   @   s   e Zd ZdZejdddejdd ejdd fddejdd ejd	d
 fddejd
dd
d
f ejd
d
d
df fddejdd
ddf ejd
d
 fgdd Z	dd Z
dd Zdd Zd
S )TestWriteDirectlyz>
        Feature: Write Numpy array directly into Dataset
    r   r   r   r9   r   r:   r   r   Nr   r   r   r   r   rQ   r8   rc   c           	      C   sl   |j d|ddd}tt||}tj|ddd}|| ||< |||| tj|d d  | d S )Nr.   int32r   rA   	fillvaluerH   )	r!   rB   re   r   rg   r   write_directr   r   )	r   r   r   r   r   r   r.   r   r   r   r   r   test_write_direct  s    	z#TestWriteDirectly.test_write_directc                 C   sd   |j ddd}tt8 |tdtjdd tjdd  W d    n1 sV0    Y  d S r   )r!   rL   r   rF   r   rB   r[   r   )r   r   r   r   r   r   r   !  s    zTestWriteDirectly.test_emptyc                 C   sR   |j dddd}td}tt || W d    n1 sD0    Y  d S r   r!   rB   r[   rL   r   rF   r   r   r   r   r   r   &  s    
z"TestWriteDirectly.test_wrong_shapec                 C   sV   |j dddd}tjddd}tt || W d    n1 sH0    Y  d S r   r   r   r   r   r   r   ,  s    z'TestWriteDirectly.test_not_c_contiguous)r   r   r   r(   rL   r   r   rB   r   r   r   r   r   r   r   r   r   r     s   .$
r   c                   @   sP   e Zd Z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S )TestCreateRequirezS
        Feature: Datasets can be created only if they don't exist in the file
    c                 C   s.   | j ddd}| |t | |jd dS )z& Create new dataset with no conflicts r   rb   r   N)r   require_datasetr"   r   r+   r,   r-   r   r   r   test_create9  s    zTestCreateRequire.test_createc                 C   s0   | j ddd}| j ddd}| || dS )z) require_dataset yields existing dataset r   rb   r   Nr   r   r+   rR   r   r   r   test_create_existing?  s    z&TestCreateRequire.test_create_existingc                 C   s   | j ddd}| j ddd}| || | j ddd}| j ddd}| || | j ddd}| j ddd}| || dS )	z; require_dataset with integer shape yields existing datasetr   r9   r   r6   r   Zbazs   bazNr   rR   r   r   r   test_create_1DE  s    z TestCreateRequire.test_create_1Dc                 C   sN   | j ddd | t  | j ddd W d   n1 s@0    Y  dS )z6 require_dataset with shape conflict yields TypeError r   rb   r   )r9   r    Nr   r!   rE   rF   r   r   r   r   r   test_shape_conflictS  s    z%TestCreateRequire.test_shape_conflictc                 C   sJ   | j d | t  | j ddd W d   n1 s<0    Y  dS )z< require_dataset with object type conflict yields TypeError r   rb   r   N)r   Zcreate_grouprE   rF   r   r   r   r   r   test_type_conflictY  s    z$TestCreateRequire.test_type_conflictc                 C   sN   | j ddd}| t  | j ddd W d   n1 s@0    Y  dS )zL require_dataset with dtype conflict (strict mode) yields TypeError
        r   rb   r   ZS10Nr   r-   r   r   r   test_dtype_conflict_  s    z%TestCreateRequire.test_dtype_conflictc                 C   s4   | j ddd}| j jddddd}| || dS )z* require_dataset with exactly dtype match r   rb   r   TexactN)r   r!   r   r+   rR   r   r   r   test_dtype_exactf  s    z"TestCreateRequire.test_dtype_exactc                 C   sH   | j ddd}| j jddddd}| || | |jtd dS )zJ require_dataset with convertible type succeeds (non-strict mode)
        r   rb   i4i2Fr   N)r   r!   r   r+   rA   rB   rR   r   r   r   test_dtype_closem  s    z"TestCreateRequire.test_dtype_closeN)r   r   r   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   3  s   r   c                   @   sX   e Zd Z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S )TestCreateChunkedzL
        Feature: Datasets can be created by manually specifying chunks
    c                 C   s$   | j jdddd}| |jd dS )z Create via chunks tuple r   r   r   r,   chunksNr   r!   r+   r   r-   r   r   r   test_create_chunks|  s    z$TestCreateChunked.test_create_chunksc                 C   s$   | j jdddd}| |jd dS )z Create via chunks integer r   r   r9   r   r   Nr   r-   r   r   r   test_create_chunks_integer  s    z,TestCreateChunked.test_create_chunks_integerc                 C   s@   |  t" | jjdddd W d   n1 s20    Y  dS )z& Illegal chunk size raises ValueError r   r   r   r   NrE   rj   r   r!   r   r   r   r   test_chunks_mismatch  s    z&TestCreateChunked.test_chunks_mismatchc                 C   sB   |  t$ | jjddddd W d   n1 s40    Y  dS )z3 Chunked format required for given storage options r   r   r   F)r,   maxshaper   Nr   r   r   r   r   test_chunks_false  s    z#TestCreateChunked.test_chunks_falsec                 C   s@   |  t" | jjdddd W d   n1 s20    Y  dS )z> Attempting to create chunked scalar dataset raises TypeError r   r   )r   r   NrD   r   r   r   r   test_chunks_scalar  s    z$TestCreateChunked.test_chunks_scalarc                 C   s6   | j jdddd}| |jt | t|jd dS )z Auto-chunking of datasets r   )r   r   Tr   rQ   N)r   r!   r"   r   tupler+   lenr-   r   r   r   test_auto_chunks  s    z"TestCreateChunked.test_auto_chunksc                 C   s&   | j jddddd}| |jd dS )z7 Auto-chunking with pathologically large element sizes r   rc   Z
S100000000Tr,   rA   r   r0   Nr   r-   r   r   r   test_auto_chunks_abuse  s    z(TestCreateChunked.test_auto_chunks_abusec                 C   s   | j jddtjdd}d|ddddf< | t|ddddf dk d	|d< | t|d d	k d
|dd< | t|dd d
k dS )z+ Test scalar assignment of chunked dataset r   )rc   r   r   )r   r   r   r   r9   r   N(         r   rQ   )r   r!   rB   r   r_   allr-   r   r   r   test_scalar_assignment  s    
"z(TestCreateChunked.test_scalar_assignmentc                 C   s   t jtdd"}| jjdddd W d   n1 s60    Y  t jtdd"}| jjdddd	 W d   n1 sv0    Y  dS )
z, Auto-chunking of empty datasets not allowedr   )matchr   ZS100T)rA   r   Nr   rA   r   )rL   r   rF   r   r!   )r   errr   r   r   test_auto_chunks_no_shape  s    0z+TestCreateChunked.test_auto_chunks_no_shapeN)r   r   r   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   v  s   r   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )TestCreateFillvaluez>
        Feature: Datasets can be created with fill value
    c                 C   s6   | j jdddd}| |d d | |d d dS )z- Fill value is reflected in dataset contents r   r   g      @r   r   r   N)r   r!   r+   r-   r   r   r   test_create_fillval  s    z'TestCreateFillvalue.test_create_fillvalc                 C   s4   | j jdddd}| |jd | |jtj dS )z( Fill value is recoverable via property r   r   g      @r   N)r   r!   r+   r   ZassertNotIsInstancerB   ndarrayr-   r   r   r   test_property  s    z!TestCreateFillvalue.test_propertyc                 C   s    | j dd}| |jd dS )z0 .fillvalue property works correctly if not set r   r   r   N)r   r!   r+   r   r-   r   r   r   test_property_none  s    z&TestCreateFillvalue.test_property_nonec                 C   sV   t ddg}t jd|dd }| jjdd||d}| |j| | |d	 | d
S )z& Fill value works with compound types )r|   f4)r~   i8r0   rH   r   r   r   r   r    N)rB   rA   r[   r   r!   r+   r   ZassertAlmostEqual)r   dtvr.   r   r   r   test_compound  s
    z!TestCreateFillvalue.test_compoundc                 C   sF   |  t( | jjddddgdd}W d   n1 s80    Y  dS )z$ Bogus fill value raises ValueError r   r   r|   i)r~   r   *   r   Nr   r-   r   r   r   test_exc  s    
zTestCreateFillvalue.test_excN)	r   r   r   r(   r   r   r   r   r  r   r   r   r   r     s   r   c                   @   s   e Zd ZdZdd ZdS )TestCreateNamedTypezC
        Feature: Datasets created from an existing named type
    c                 C   sn   t d| jd< | jjdd| jd d}| |jt d | |j | jd j | |j   dS )z7 Named type object works and links the dataset to type f8typexr   rH   N)	rB   rA   r   r!   r+   rk   rm   r_   Z	committedr-   r   r   r   
test_named  s
    zTestCreateNamedType.test_namedN)r   r   r   r(   r  r   r   r   r   r    s   r  gzipzDEFLATE is not installedc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestCreateGzipz=
        Feature: Datasets created with gzip compression
    c                 C   s4   | j jddddd}| |jd | |jd dS )z# Create with explicit gzip options r   r   ra   r	  r   compressioncompression_optsNr   r!   r+   r  r  r-   r   r   r   	test_gzip  s
    zTestCreateGzip.test_gzipc                 C   s2   | j jdddd}| |jd | |jd dS )z+ Create with implicit gzip level (level 4) r   r  r	  r  r    Nr  r-   r   r   r   test_gzip_implicit  s    z!TestCreateGzip.test_gzip_implicitc                 C   s   | j jdddd}| |jd | |jd tjjj}zVt	 tjj_| 
t" | j jdddd}W d   n1 sx0    Y  W |tjj_n|tjj_0 dS )z. Create with gzip level by specifying integer r   r  r   r  r	  N)r   r!   r+   r  r  r^   _hldataset_LEGACY_GZIP_COMPRESSION_VALSr   rE   rj   )r   r.   original_compression_valsr   r   r   test_gzip_number  s    
2zTestCreateGzip.test_gzip_numberc                 C   s   |  ttf" | jjdddd W d   n1 s60    Y  |  t" | jjdddd W d   n1 sr0    Y  |  t$ | jjddddd W d   n1 s0    Y  dS )	z= Illegal gzip level (explicit or implicit) raises ValueError r   r     r  Nr	  r  )rE   rj   RuntimeErrorr   r!   r   r   r   r   test_gzip_exc  s    00zTestCreateGzip.test_gzip_excN)r   r   r   r(   r  r  r  r  r   r   r   r   r
    s
   r
  c                   @   s    e Zd ZdZdd Zdd ZdS )TestCreateCompressionNumberz?
        Feature: Datasets created with a compression code
    c                 C   sj   t jjj}z2t t jj_| jjddt jjdd}W |t jj_n|t jj_0 | 	|j
d | 	|jd dS )z^ Create with compression number of gzip (h5py.h5z.FILTER_DEFLATE) and a compression level of 7r   r  )r   r  r	  r   N)r^   r  r  r  r   r   r!   h5zFILTER_DEFLATEr+   r  r  )r   r  r.   r   r   r   test_compression_number"  s    
z3TestCreateCompressionNumber.test_compression_numberc                 C   s  |  t"}| jjdddd W d   n1 s20    Y  | dt|j |  t"}| jjdddd W d   n1 s0    Y  | dt|j tjj	j
}zZt tjj	_
|  t& | jjddtjjd W d   n1 s0    Y  W |tjj	_
n|tjj	_
0 dS )	z* Create with invalid compression numbers  r   r  ir  NzInvalid filterr   zUnknown compression)rE   rj   r   r!   ZassertInr$   	exceptionr^   r  r  r  r   
IndexErrorr  r  )r   er  r   r   r   test_compression_number_invalid.  s    00
6z;TestCreateCompressionNumber.test_compression_number_invalidN)r   r   r   r(   r  r#  r   r   r   r   r    s   r  lzfzLZF is not installedc                   @   s    e Zd ZdZdd Zdd ZdS )TestCreateLZF<
        Feature: Datasets created with LZF compression
    c                 C   s   | j jdddd}| |jd | |jd td}| j jd|dd}| |jd | |jd | j   | j d d	 }| || dS )
z Create with explicit lzf r   r  r$  r  Nr   r6   )rY   r  r   )	r   r!   r+   r  r  rB   re   flushrf   )r   r.   testdatareaddatar   r   r   test_lzfJ  s    

zTestCreateLZF.test_lzfc                 C   sB   |  t$ | jjddddd W d   n1 s40    Y  dS )z& Giving lzf options raises ValueError r   r  r$  r    r  Nr   r   r   r   r   test_lzf_excZ  s    zTestCreateLZF.test_lzf_excN)r   r   r   r(   r*  r+  r   r   r   r   r%  C  s   r%  szipzSZIP is not installedc                   @   s   e Zd ZdZdd ZdS )TestCreateSZIPr&  c                 C   s   | j jddddd}dS )z Create with explicit szip r   r  r,  )ec   r  N)r   r!   r-   r   r   r   	test_sziph  s    zTestCreateSZIP.test_szipN)r   r   r   r(   r0  r   r   r   r   r-  a  s   r-  shufflezSHUFFLE is not installedc                   @   s   e Zd ZdZdd ZdS )TestCreateShufflez8
        Feature: Datasets can use shuffling filter
    c                 C   s"   | j jdddd}| |j dS )z Enable shuffle filter r   r  T)r1  N)r   r!   r_   r1  r-   r   r   r   test_shuffleu  s    zTestCreateShuffle.test_shuffleN)r   r   r   r(   r3  r   r   r   r   r2  n  s   r2  
fletcher32zFLETCHER32 is not installedc                   @   s   e Zd ZdZdd ZdS )TestCreateFletcher32z=
        Feature: Datasets can use the fletcher32 filter
    c                 C   s"   | j jdddd}| |j dS )z Enable fletcher32 filter r   r  T)r4  N)r   r!   r_   r4  r-   r   r   r   test_fletcher32  s    z$TestCreateFletcher32.test_fletcher32N)r   r   r   r(   r6  r   r   r   r   r5  {  s   r5  scaleoffsetzSCALEOFFSET is not installedc                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )TestCreateScaleOffsetz?
        Feature: Datasets can use the scale/offset filter
    c                 C   sB   |  t$ | jjddtdd}W d   n1 s40    Y  dS )z[ Ensure that a scale factor is required for scaleoffset compression of floating point data r   r  TrA   r7  NrE   rj   r   r!   floatr-   r   r   r    test_float_fails_without_options  s    z6TestCreateScaleOffset.test_float_fails_without_optionsc                 C   sB   |  t$ | jjddtdd}W d   n1 s40    Y  dS )z# Check when scaleoffset is negetiver   r  gr9  Nr:  r-   r   r   r   test_non_integer  s    z&TestCreateScaleOffset.test_non_integerc                 C   sB   |  t$ | jjddtdd}W d   n1 s40    Y  dS )z% Check when dtype is unsupported typer   r  Tr9  N)rE   rF   r   r!   boolr-   r   r   r   test_unsupport_dtype  s    z*TestCreateScaleOffset.test_unsupport_dtypec                 C   s   d}d}dd|  }t jj| d | }| jjd|t|d}|jdusJJ ||d	< | jj}| j  t	
|d
| _| jd d	 }| j||d|  d ||k rJ dS )z2 Scaleoffset filter works for floating point data r    r   i,  r   r9   g      ?r   r9  N.r)	precision)rB   randomrandr   r!   r;  r7  filenamer   r^   r   rf   r   )r   Zscalefacr,   ranger(  r.   rE  r)  r   r   r   
test_float  s    
z TestCreateScaleOffset.test_floatc                 C   s   d}d}t jjdd| d |d}| jjd|tdd	}|jd
usDJ ||d< | jj}| j  t	
|d| _| jd d }| || d
S )zB Scaleoffset filter works for integer data with default precision r   r@  r   rQ   r   r<   r   Tr9  N.rA  )rB   rC  randintr   r!   intr7  rE  r   r^   r   rf   r   nbitsr,   r(  r.   rE  r)  r   r   r   test_int  s    
zTestCreateScaleOffset.test_intc                 C   s   d}d}t jjdd| |d}| jjd|t|d}| |jdk ||d< | jj}| j	  t
|d	| _| jd d }| || d
S )D Scaleoffset filter works for integer data with specified precision r   r@  r   rQ   rH  r   r9  .rA  N)rB   rC  rI  r   r!   rJ  r_   r7  rE  r   r^   r   rf   rK  r   r   r   test_int_with_minbits  s    
z+TestCreateScaleOffset.test_int_with_minbitsc                 C   s   d}d}t jjdd|d  d |d}| jjd|t|d}| |jdk ||d	< | jj}| j	  t
|d
| _| jd d	 }||k rJ dS )rN  r   r@  r   rQ   r   rH  r   r9  .rA  N)rB   rC  rI  r   r!   rJ  r_   r7  rE  r   r^   r   r   rK  r   r   r   test_int_with_minbits_lossy  s    
z1TestCreateScaleOffset.test_int_with_minbits_lossyN)r   r   r   r(   r<  r=  r?  rG  rM  rO  rP  r   r   r   r   r8    s   r8  c                   @   s@   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dS )TestExternalzB
        Feature: Datasets with the external storage property
    c           
      C   s   d}t j|}|  }|dtjfg}| jjd||j|dd}||d< |jdusTJ t	|d}|
 }W d   n1 s|0    Y  || ksJ tjjd	krt|j    }t| jjj }	||	ksJ dS )
z' Create and access an external dataset r8   r   r   r   z	${ORIGIN}rA   externalefile_prefix.Nrbr   r9   r   )rB   rC  r   r
   	UNLIMITEDr   r!   rA   rT  openreadtobytesr^   r   hdf5_version_tuplepathlibPathrk   get_access_plistget_efile_prefixdecodeas_posixrE  parent)
r   r,   r(  ext_filerT  r.   fidcontentsrU  rc  r   r   r   test_contents  s    &zTestExternal.test_contentsc                 C   s(  d}t j|}|  }tj|dtjfg}| jj	d||j
|tj|d}||d< |jdusdJ t|d}| }W d   n1 s0    Y  || ksJ tjjdkrt|j    }t|j }	||	ksJ | jjd||j
tj|d	}
|
jdusJ |
d
 |k dS )z< Create and access an external dataset using an efile_prefixrR  r   r   rS  .NrV  rW  )rU  r   )rB   rC  r   ospathbasenamer
   rX  r   r!   rA   dirnamerT  rY  rZ  r[  r^   r   r\  r]  r^  rk   r_  r`  ra  rb  rc  r   )r   r,   r(  rd  rT  r.   re  rf  rU  rc  rS   r   r   r   test_contents_efile_prefix  s"     &z'TestExternal.test_contents_efile_prefixc                 C   s   | j jdd|  d dS )z/ External argument may be a file name str only r   rR  rT  N)r   r!   r   r   r   r   r   test_name_str5  s    zTestExternal.test_name_strc                 C   s    | j jddt|  d dS )z0 External argument may be a file name path only r   rR  rm  N)r   r!   r]  r^  r   r   r   r   r   test_name_path:  s    
zTestExternal.test_name_pathc                    sN   |    d}t fddt|D }| jjdd|d}t|j|ksJJ dS )z9 External argument may be an iterable of multiple tuples r   c                 3   s   | ]} |d  d fV  qdS )  Nr   .0r  rd  r   r   	<genexpr>E      z/TestExternal.test_iter_multi.<locals>.<genexpr>ZpoorR  rm  N)r   iterrF  r   r!   r   rT  )r   NrT  r.   r   rs  r   test_iter_multi@  s
    zTestExternal.test_iter_multic              
   C   s   d}|   }t|gft|dgft|dtjgft|fgft|dfgft|dtjdfgft|ddfgffD ]D\}}| |" | jjd||d W d   qf1 s0    Y  qfdS )z" Test with invalid external lists rR  r   zh5f.UNLIMITEDr   rm  N)r   rF   r
   rX  rj   rE   r   r!   )r   r,   rd  exc_typerT  r   r   r   test_invalidI  s    

	zTestExternal.test_invalidN)
r   r   r   r(   rg  rl  rn  ro  rx  rz  r   r   r   r   rQ    s   	rQ  c                   @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )TestAutoCreatezP
        Feature: Datasets auto-created from data produce the correct types
    Tc                 C   sB   |j  }| t|tjj | | | |r>| s>J d S r   )	rk   rm   r+   r  r^   r   ro   rp   rq   )r   r&   rs   variableru   r   r   r   assert_string_typea  s
    
z!TestAutoCreate.assert_string_typec                 C   sx   d| j d< | | j d tjj ddg| j d< | | j d tjj tjddgtjd| j d< | | j d tjj dS )	z<Assigning byte strings produces a vlen string ASCII dataset s   Hello therer     as   bcyrH   zN)r   r}  r^   r   ry   rB   r   object_r   r   r   r   test_vlen_bytesh  s    
zTestAutoCreate.test_vlen_bytesc                 C   s   dt d | jd< | | jd tjj ddg| jd< | | jd tjj tjddggtjd| jd< | | jd tjj d	S )
z?Assigning unicode strings produces a vlen string UTF-8 dataset Hello there4   r  r|   bcr  rH   r  N)	chrr   r}  r^   r   r   rB   r   r  r   r   r   r   test_vlen_unicodes  s    z TestAutoCreate.test_vlen_unicodec                 C   sH   t d| jd< | jd }| j|tjjdd | |j	 
 d dS )zV Assignment of fixed-length byte string produces a fixed-length
        ascii dataset r  r  F)r|  r   N)rB   string_r   r}  r^   r   ry   r+   rk   rm   rr   r%   r   r   r   test_string_fixed  s    
z TestAutoCreate.test_string_fixedN)T)r   r   r   r(   r}  r  r  r  r   r   r   r   r{  \  s
   
r{  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestCreateLikec                 C   sV   t ddd| jd< | jd| jd  | jd }| |jd | |jd  d S )N   r   ZlolZlike_lol)r   r   )	rB   re   rg   r   create_dataset_liker+   r,   ZassertIsr   )r   Zdsliker   r   r   test_no_chunks  s
    
zTestCreateLike.test_no_chunksc                 C   s   | j jdtddd}| dtj|jj	 | j 
d|}| dtj|jj	 | j jdtddd}| dtj|jj	 | j 
d	|}| dtj|jj	 d S )
NZhondar   T)rY   track_timesr   ZhyundaiZibmFZlenovo)r   r!   rB   re   assertNotEqualr^   h5gget_objinfo_idmtimer  r+   )r   origsimilarr   r   r   test_track_times  s    zTestCreateLike.test_track_timesc                 C   s@   | j jdddd}| j d|}| |jd | |jd dS )z) Test when other.maxshape != other.shape otherr   r   r   simr   N)r   r!   r  r+   r,   r   )r   r  r  r   r   r   test_maxshape  s    zTestCreateLike.test_maxshapeN)r   r   r   r  r  r  r   r   r   r   r    s   r  c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestChunkIteratorc                 C   sD   | j dd}| t |  W d    n1 s60    Y  d S )Nr   r   )r   r!   rE   rF   iter_chunksr-   r   r   r   r    s    z TestChunkIterator.test_no_chunksc                 C   s   | j jdddd}tdddftdddftdd	dftd	d
dff}| t| t| tdddftdd	dftd	ddff}| t|tjdd t| d S )Nr   r   )    r   r   r  r   @   `   r   r   a   r   r!   slicer+   listr  rB   r   r   r.   r   r   r   r   test_1d  s    $(zTestChunkIterator.test_1dc                 C   s(  | j jdddd}tdddtdddftdddtdd	dftdddtdddftdddtdd	dftdd
dtdddftdd
dtdd	dftd
d	dtdddftd
d	dtdd	dff}| t| t| tdddtdddff}| t|tjddddf t| d S )Nr   r   r   )r  r  r  r   r  r   r  r   r  0   4   r   r   r  r  r   r   r   test_2d  s      
 
 
zTestChunkIterator.test_2dN)r   r   r   r  r  r  r   r   r   r   r    s   r  c                   @   sX   e Zd Z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S )
TestResizezF
        Feature: Datasets created with "maxshape" may be resized
    c                 C   s2   | j jdddd}| |jd | |jd dS )z  Create dataset with "maxshape" r   r  r   r:   r  Nr   r!   ZassertIsNotr   r+   r   r-   r   r   r   r     s    zTestResize.test_createc                 C   sR   | j jdddd}| |jd | |jd | j jdddd}| |jd dS )z6 Create dataset with "maxshape" using integer maxshaper   r  r   r  Nr6   r  r-   r   r   r   r     s
    zTestResize.test_create_1Dc                 C   sT   | j jdddd}| |jd |d | |jd |d | |jd dS )z( Datasets may be resized up to maxshape r   r  r  r  r   r   Nr   r!   r+   r,   resizer-   r   r   r   test_resize  s    

zTestResize.test_resizec                 C   s<   | j jdddd}| |jd |d | |jd dS )z> Datasets may be resized up to maxshape using integer maxshaper   r   r   r  r  )ra   Nr  r-   r   r   r   test_resize_1D  s    
zTestResize.test_resize_1Dc                 C   sJ   | j jdddd}| t |d W d   n1 s<0    Y  dS )z. Resizing past maxshape triggers an exception r   r  r  r  )r   r   N)r   r!   rE   	Exceptionr  r-   r   r   r   test_resize_over  s    zTestResize.test_resize_overc                 C   sF   | j dd}| t |d W d   n1 s80    Y  dS )z/ Resizing non-chunked dataset raises TypeError r   r  r  N)r   r!   rE   rF   r  r-   r   r   r   test_resize_nonchunked  s    z!TestResize.test_resize_nonchunkedc                 C   s2   | j jdddd}|jddd | |jd d	S )
z Resize specified axis r   r  r  r  r   r   Zaxisr  N)r   r!   r  r+   r,   r-   r   r   r   test_resize_axis  s    zTestResize.test_resize_axisc                 C   sN   | j jdddd}| t |jddd W d   n1 s@0    Y  dS )	z  Illegal axis raises ValueError r   r  r  r  r   rQ   r  N)r   r!   rE   rj   r  r-   r   r   r   test_axis_exc  s    zTestResize.test_axis_excc                 C   s2   | j jdddd}| |jd | |jd dS )z? Allow zero-length initial dims for unlimited axes (issue 111) r   )   r   )r  Nr  N)r   r!   r+   r,   r   r-   r   r   r   test_zero_dim  s    zTestResize.test_zero_dimN)r   r   r   r(   r   r   r  r  r  r  r  r  r  r   r   r   r   r    s   		r  c                   @   s   e Zd ZdZdd ZdS )	TestDtypezD
        Feature: Dataset dtype is available as .dtype property
    c                 C   s(   | j ddd}| |jtd dS )z Retrieve dtype from dataset r   r   |S10Nr@   r-   r   r   r   
test_dtype  s    zTestDtype.test_dtypeN)r   r   r   r(   r  r   r   r   r   r    s   r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestLenzG
        Feature: Size of first axis is available via Python's len
    c                 C   s"   | j dd}| t|d dS )z Python len() (under 32 bits) r   )8  r  r  N)r   r!   r+   r   r-   r   r   r   test_len  s    zTestLen.test_lenc                 C   s~   | j dd}| |jd tjdkrZ| t t| W d   qj1 sN0    Y  n| t|d | | d dS )z Python len() vs Dataset.len() r   )        r  iNr  )	r   r!   r+   r,   sysmaxsizerE   OverflowErrorr   r-   r   r   r   test_len_big  s    
(zTestLen.test_len_bigN)r   r   r   r(   r  r  r   r   r   r   r    s   r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestIterz;
        Feature: Iterating over a dataset yields rows
    c                 C   sX   t jdddd}| jjd|d}t||D ]$\}}| t|d | || q.dS )	z& Iterating over a dataset yields rows ra   r   rH   rb   r   rX   rc   N)	rB   re   rg   r   r!   zipr+   r   rf   )r   rY   r.   r  r  r   r   r   	test_iter.  s
    zTestIter.test_iterc                 C   sL   | j jddd}| t dd |D  W d   n1 s>0    Y  dS )z0 Iterating over scalar dataset raises TypeError r   r   )r,   c                 S   s   g | ]}|qS r   r   rq  r   r   r   
<listcomp>:  ru  z-TestIter.test_iter_scalar.<locals>.<listcomp>N)r   r!   rE   rF   r-   r   r   r   test_iter_scalar6  s    zTestIter.test_iter_scalarN)r   r   r   r(   r  r  r   r   r   r   r  (  s   r  c                   @   s   e Zd Z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 S )!TestStringszr
        Feature: Datasets created with vlen and fixed datatypes correctly
        translate to and from HDF5
    c                 C   sn   t jdd}| jjdd|d}|j }| t|t jj	 | |
 t jj t |j}| |jd dS )z3 Vlen bytes dataset maps to vlen ascii in the file asciiencodingr  r   rH   N)r^   string_dtyper   r!   rk   rm   r+   r  r   ro   rp   ry   check_string_dtyperA   r  r   r   r&   ru   Zstring_infor   r   r   r  D  s    
zTestStrings.test_vlen_bytesc                 C   sp   t jdd}d}| jjdd||d}| | jd d | | | jd  d |  | | jd j| dS )	z& Vlen bytes dataset handles fillvalue r  r  s   barr  r   r   r   N)r^   r  r   r!   r+   asstrra  r   r   r   Z
fill_valuer&   r   r   r   test_vlen_bytes_fillvalueN  s    z%TestStrings.test_vlen_bytes_fillvaluec                 C   sj   t  }| jjdd|d}|j }| t|t jj	 | |
 t jj t |j}| |jd dS )z5 Vlen unicode dataset maps to vlen utf-8 in the file r  r   rH   utf-8N)r^   r  r   r!   rk   rm   r+   r  r   ro   rp   r   r  rA   r  r  r   r   r   r  W  s    
zTestStrings.test_vlen_unicodec                 C   st   t  }d}| jjdd||d}| | jd d |d | | jd  d | | | jd j|d dS )z( Vlen unicode dataset handles fillvalue u   bárr  r   r   r   r  N)r^   r  r   r!   r+   encoder  r   r  r   r   r   test_vlen_unicode_fillvaluea  s    z'TestStrings.test_vlen_unicode_fillvaluec                 C   s   t d}| jjdd|d}|j }| t|tj	j
 | |  | | d | | tj	j t|j}| |jd | |jd dS )zK Fixed-length bytes dataset maps to fixed-length ascii in the file
        r  r  r   rH   r9   r  N)rB   rA   r   r!   rk   rm   r+   r  r^   r   ro   ZassertFalserq   rr   rp   ry   r  r  rt   r  r   r   r   test_fixed_asciij  s    

zTestStrings.test_fixed_asciic                 C   s  t jddd}| jjdd|d}|j }| | t jj	 d}|
d|d< ||d	< ||g|d
d< tj||gtd|dd< tj|
dgd
 |d|dd< | t* tj||gdd|dd< W d    n1 s0    Y  tj|d d tj|
dgd dd d S )Nr  r   )r  rt   r  r   rH      cùr   r   rQ   r    r8      Ur9   S)r^   r  r   r!   rk   rm   r+   rp   r   r   r  rB   r   r   rE   rF   r   r   )r   r   r&   ru   sr   r   r   test_fixed_utf8x  s    
"8zTestStrings.test_fixed_utf8c                 C   sJ   t d}| t" | jjdd|d}W d   n1 s<0    Y  dS )zA Fixed-length unicode datasets are unsupported (raise TypeError) z|U10r  r   rH   N)rB   rA   rE   rF   r   r!   r   r   r&   r   r   r   test_fixed_unicode  s    
zTestStrings.test_fixed_unicodec                 C   sR   t jdd}| jjdd|d}d}||d< |d }| t|t | || dS )	zN writing and reading to vlen bytes dataset preserves type and content
        r  r  r  r   rH      Hellor   N)r^   r  r   r!   r+   r  bytesr   r   r&   rY   outr   r   r   test_roundtrip_vlen_bytes  s    z%TestStrings.test_roundtrip_vlen_bytesc                 C   sR   t d}| jjdd|d}d}||d< |d }| t|t j | || dS )z[ Writing to and reading from fixed-length bytes dataset preserves
        type and content r  r  r   rH   r  r   N)rB   rA   r   r!   r+   r  r  r  r   r   r   test_roundtrip_fixed_bytes  s    
z&TestStrings.test_roundtrip_fixed_bytesc                 C   s^   t  }| jjdd|d}d}||d< | |d t | d }| |t | || d S )Nr  r   rH      fàilter   )	r^   r  r   r!   r"   r  r  r$   r+   r  r   r   r   test_retrieve_vlen_unicode  s    z&TestStrings.test_retrieve_vlen_unicodec                 C   s   | j jddt d}d}||d< |d}| t |d }W d    n1 sT0    Y  | |ddd d | |d	d | | d
t	|  t
j| d d t
j|gtd d S )Nr  r   rH   r  r   r  ignoreZfiltelatin-1r9   r   )r   r!   r^   r  r  rE   UnicodeDecodeErrorr+   r  r   rB   r   r   r   r   )r   r&   rY   Zstrwrap1r  r   r   r   
test_asstr  s    
&zTestStrings.test_asstrc                 C   s   t jdd}| jjdd|d}d}tj|d|d|d< | |d tj |	 d }| |t
 | || | |	d	d
d d | |	dd | tj|	 d d tj|gtd d S )Nr   rx   r  r   rH   r  r  r   r  r  r   r  r   )r^   r  r   r!   rB   r   r  r"   bytes_r  r$   r+   r  r   r   r   r  r   r   r   test_asstr_fixed  s    zTestStrings.test_asstr_fixedc                 C   sV   t d}| jjdd|d}d}| t ||d< W d   n1 sH0    Y  dS )zGEncoding error when writing a non-ASCII string to an ASCII vlen datasetr  r  r   rH   r  r   N)r^   r  r   r!   rE   UnicodeEncodeError)r   r   r&   rY   r   r   r   test_unicode_write_error  s
    
z$TestStrings.test_unicode_write_errorc                 C   s\   t  }| jjdd|d}dtd d}||d< |d }| t|t | || dS )	zJ Writing valid utf-8 byte strings to a unicode vlen dataset is OK
        r  r   rH   r  r  utf8r   N)	r^   r  r   r!   r  r  r+   r  r  r  r   r   r   test_unicode_write_bytes  s    z$TestStrings.test_unicode_write_bytesc                 C   sV   t d}| jjdd|d}d}||d< |d }| t|t | ||d dS )z: Writing an ascii str to ascii vlen dataset is OK
        r  r  r   rH   zASCII stringr   N)r^   r  r   r!   r+   r  r  r  r  r   r   r   test_vlen_bytes_write_ascii_str  s    
z+TestStrings.test_vlen_bytes_write_ascii_strN)r   r   r   r(   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r  =  s    
	
	
r  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestCompoundz:
        Feature: Compound types correctly round-trip
    c              
   C   s   t dt jfdt jfdt jfdt jfdt jfdt jfdt jfg}t jd|d	}|jD ]}t jdd
 ||< qV|| jd< | jd d }| 	t 
||k | |j|j dS )z: Compound types are read back in correct order (issue 236)weightZcputimeZwalltimeZparents_offsetZ	n_parentsstatusendpoint_typer/  rH   r   test.N)rB   rA   float64Zuint32uint8r   fieldsrC  r   r_   r   r+   )r   r   r(  keyoutdatar   r   r   test_rt  s    

zTestCompound.test_rtc                 C   s   t dt jdffdt jfg}t jd|d}|jD ] }t jj|| jdd ||< q2| jj	dd|d}|jD ]}|| ||< ql| jd d	 }| 
t ||k | |j|j d S )
Nr  rc   r  r  rH   rH  r   r  .)rB   rA   r  r  r   r  rC  r,   r   r!   r_   r   r+   )r   r   r(  r  r&   r   r   r   r   test_assign  s    

zTestCompound.test_assignc                 C   s   t dt jfdt jfdt jfg}t jd|d}|jD ]}t jdd ||< q6|| jd< t j| jd ddgd d  |ddg  t j| jd dd d  |d  t	| jd ddksJ d S )	Nr  r  r  r  rH   r   r  r/  )
rB   rA   r  r   r  rC  r   r   r   r   )r   r   r(  r  r   r   r   test_fields&  s     

$zTestCompound.test_fieldsN)r   r   r   r(   r  r  r  r   r   r   r   r    s   r  c                   @   s   e Zd Zdd Zdd ZdS )TestSubarrayc                 C   sl   | j jdddd}g d|d< tj|d d  g dg g dg|d d < tj|d d  g dg d S Nr|   r0   Z3int8rH   r   rQ   rc   r   )r    r   r8   )r   r!   rB   r   r   r%   r   r   r   test_write_listA  s
    zTestSubarray.test_write_listc                 C   sx   | j jdddd}tg d|d< tj|d d  g dg tg dg|d d < tj|d d  g dg d S r  )r   r!   rB   r   r   r   r%   r   r   r   test_write_arrayI  s
    zTestSubarray.test_write_arrayN)r   r   r   r  r  r   r   r   r   r  @  s   r  c                   @   s,   e Zd ZdZddddZdd Zdd	 Zd
S )TestEnumzM
        Feature: Enum datatype info is preserved, read/write as integer
    r   r   r  )REDGREENBLUEc                 C   sD   t j| jdd}| jjdd|d}|j}t |}| || j dS )z= Enum datasets can be created and type correctly round-trips r  Zbasetyper  r  rH   N)r^   
enum_dtypeEDICTr   r!   rA   Zcheck_enum_dtyper+   )r   r   r&   Zdt2Zdict2r   r   r   r   Z  s
    
zTestEnum.test_createc                 C   sp   t j| jdd}| jjdd|d}d|d< d|dd	d	f< | |d d | |dd	d	f tjd
dd d	S )z/ Enum datasets can be read/written as integers r   r  r  r  rH   r  )#   %   r   N)dr   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   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^   r  r  r   r!   r+   rf   rB   r   r  r   r   r   test_readwriteb  s    zTestEnum.test_readwriteN)r   r   r   r(   r  r   r  r   r   r   r   r	  R  s   r	  c                   @   s:   e Zd ZdZdd Zeeedddd Z	dd	 Z
d
S )
TestFloatszA
        Test support for mini and extended-precision floats
    c                 C   sJ   | j jdd|d}| |j| tjd|d}||d< | |d | d S )Nr  r   rH   .)r   r!   r+   rA   rB   r[   rf   )r   r   r.   rY   r   r   r   	_exectestr  s
    zTestFloats._exectestfloat16zNumPy float16 support requiredc                 C   s   |  td dS )z Mini-floats round trip r  N)r  rB   rA   r   r   r   r   	test_miniy  s    zTestFloats.test_minic                 C   s<   t tdr"| tjjtd n| tjjtd dS )z Test mapping for float16 r  z<f2z<f4N)rV   rB   r+   r   Z
IEEE_F16LErA   r   r   r   r   test_mini_mapping  s    
zTestFloats.test_mini_mappingN)r   r   r   r(   r  r   
skipUnlessrV   rB   r  r  r   r   r   r   r  l  s
   
r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestTrackTimesz"
        Feature: track_times
    c                 C   s2   | j jdddd}tj|jj}| d| dS )zC check that when track_times=False, the time stamp=0 (Jan 1, 1970) r   r   Fr  r   N)r   r!   r^   r  r  r  r  r+   )r   r&   Zds_mtimer   r   r   test_disable_track_times  s    z'TestTrackTimes.test_disable_track_timesc                 C   s@   |  t" | jjdddd W d   n1 s20    Y  dS )z3 check that when give track_times an invalid value r   r   nullr  NrD   r   r   r   r   test_invalid_track_times  s    z'TestTrackTimes.test_invalid_track_timesN)r   r   r   r(   r  r  r   r   r   r   r    s   r  c                   @   s    e Zd ZdZdd Zdd ZdS )TestZeroShapez7
        Features of datasets with (0,)-shape axes
    c                 C   s|   | j jdddd}| |jt|j | j jdddd}| |jt|j | j jdd	d
d}| |jt|j dS )z1 Empty datasets can be converted to NumPy arrays r  r   Nr  r  r   r   r  r   r   )NN)r   r!   r+   r,   rB   r   r%   r   r   r   test_array_conversion  s    z#TestZeroShape.test_array_conversionc                 C   s~   ddg}| j jdd|dd}tjd|d}| |d j|j | |d j|j | |d	 j|j | |d	 j|j d
S )z- Slicing into empty datasets works correctly )r|   r   )r~   r  r  r  r   r   rH   .r   N)r   r!   rB   emptyr+   r,   rA   )r   r   r&   r   r   r   r   test_reading  s    zTestZeroShape.test_readingN)r   r   r   r(   r!  r#  r   r   r   r   r    s   r  )r   r9   r8   z+Issue with empty region refs in HDF5 1.10.6reasonc                   @   s@   e Zd ZdZdd Zdd Zedd Zedd	 Zd
d Z	dS )TestRegionRefsz3
        Various features of region references
    c                 C   s@   t |  tdd| _| jjd| jd| _| j| jd< d S )Ni'  r  r  rX   .)	r   r   rB   re   rg   rY   r   r!   r.   r   r   r   r   r     s    
zTestRegionRefs.setUpc                 C   s@   t jdddddf }| jj| }| | j| | j|  dS )z4 Region references can be used as slicing arguments r  r  r9   r   r   N)rB   r   r.   	regionrefrf   rY   r   Zslicrefr   r   r   test_create_ref  s    zTestRegionRefs.test_create_refc                 C   s,   | j jd d }| j | }|jdks(J d S )Nr   )r.   r'  r<   )r   r)  r  r   r   r   test_empty_region  s    
z TestRegionRefs.test_empty_regionc                 C   s   | j jdddd}tjtjj}|  tj|jdtjj	|}|| t
tdks^J |  tj|jdtjj	|}|| |d ksJ d S )NZscalar      ?r   rY   rA      .r   )r   r!   r^   Zh5screateZSCALARZselect_noneZh5rrk   ZDATASET_REGIONr   rB   rA   Z
select_all)r   r&   Zsidr)  r   r   r   test_scalar_dataset  s    z"TestRegionRefs.test_scalar_datasetc                 C   sX   t jdddddf }| jj| }| | jj|| jj | | jj|d dS )z, Region reference shape and selection shape r  r  r9   r   r   )r9      N)rB   r   r.   r'  r+   r,   Z	selectionr(  r   r   r   test_ref_shape  s    zTestRegionRefs.test_ref_shapeN)
r   r   r   r(   r   r*  empty_regionref_xfailr+  r0  r2  r   r   r   r   r&    s   

r&  c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	
TestAstypez(.astype() wrapper & context manager
    c              	   C   s   | j jdddd}td|d< tjdd}td	 |d
* | |d tjdd
d W d    n1 sr0    Y  |d*}| |d tjddd W d    n1 s0    Y  W d    n1 s0    Y  dd |D t	gd ksJ d S )Nr  r   r   rH   r   .T)recordalwaysr  r   c                 S   s   g | ]
}|j qS r   )category)rr  r   r   r   r   r    ru  z.TestAstype.test_astype_ctx.<locals>.<listcomp>rQ   )
r   r!   rB   re   warningscatch_warningssimplefilterastyperf   r   )r   r.   Zwarn_recZf4dsr   r   r   test_astype_ctx  s    
8VzTestAstype.test_astype_ctxc                 C   sL   | j jdddd}td|d< |dd d  }| |tjddd d S Nr  r   r   rH   r   .r   )r   r!   rB   re   r;  rf   )r   r.   r   r   r   r   test_astype_wrapper  s    zTestAstype.test_astype_wrapperc                 C   s:   | j jdddd}td|d< | dt|d d S r=  )r   r!   rB   re   r+   r   r;  r-   r   r   r   test_astype_wrapper_len  s    z"TestAstype.test_astype_wrapper_lenN)r   r   r   r(   r<  r>  r?  r   r   r   r   r4    s   r4  c                   @   s   e Zd ZdZdd ZdS )TestScalarCompoundzl
        Retrieval of a single field from a scalar compound dataset should
        strip the field info
    c                 C   s:   t dg}| jjdd|d}| |d jt d d S )Nr   r  r   rH   r|   r  )rB   rA   r   r!   r+   )r   r   r.   r   r   r   test_scalar_compound  s    z'TestScalarCompound.test_scalar_compoundN)r   r   r   r(   rA  r   r   r   r   r@  
  s   r@  c                   @   sf   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdddZdd Z	dd Z
dd Zdd Zdd ZdS )TestVlenc                 C   sR  t t}| jjdd|d}td|d< td|d< g d|d< td|d< | |d td | |d td | |d tg d | |d td tjtd	td
gt	d|dd< | |d td	 | |d td
 ttdtdg|dd< | |d td | |d td d S )Nvlenr   rH   rc   r   r   r  rQ   r   r    )
r^   
vlen_dtyperJ  r   r!   rB   re   rf   r   r   r  r   r   r   rM    s     
&"zTestVlen.test_intc                 C   s6   t t}| jjdd|d}| jdd|d j d S )NrC  r0   rH   vlen2r   )r^   rD  rJ  r   r!   rA   r  r   r   r   test_reuse_from_other+  s    
zTestVlen.test_reuse_from_otherc                 C   sl   dt fdtt fg}| jjdd|d}| jj}| j  t|d| _| jdd| jd d d j d S )Nr|   r~   rC  r0   rH   rE  r   )	rJ  r^   rD  r   r!   rE  r   r   rA   )r   r   r&   fnamer   r   r   test_reuse_struct_from_other0  s    
z%TestVlen.test_reuse_struct_from_otherc                 C   s@  t t}| jjdd|d}tddg|d< tdg|d< g d|d	< | |d tddg | |d tdg | |d	 tg d
 tjg dtdgt	d|dd	< | |d td | |d td ttg dtg dg|dd	< | |d td | |d td d S )NrC  r   rH   gffffff?333333?r   r   )rI  rQ   rc   rQ   r  )皙?g?g @g@r    r    r   )rJ  rI  皙@)g?rI  rK  rc   )
r^   rD  rJ  r   r!   rB   r   rf   re   r   r  r   r   r   test_convert8  s     
$zTestVlen.test_convertc                 C   s   t t}| jjdd|d}td|d< tjtdtdgtdtdggtd|d d d d f< ttdtdgtdtdgg|d d d d f< d S )NrC  )rQ   rQ   rH   r   r   rc   rQ   )	r^   rD  rJ  r   r!   rB   re   r   r   r  r   r   r   test_multidimI  s    
zTestVlen.test_multidimrC  c                 C   sP  t |}| jj|d|d}tjg d|d}tjg d|d}tjg dtdd}||}g d}	tj|	|d}
g d}tj||d}||d	< ||d
< ||d< |	|d< ||d< | ||d	  | ||d
  | ||d  | |
|d  | ||d  tjddg|d}
|
dd |d	< | |
|d	  | j	  | j
  dS )z
        Helper for testing various vlen numpy data types.
        :param np_dt: Numpy datatype to test
        :param dataset_name: String name of the dataset to create for testing.
        r  rH   )r,         @g      >@)g33333Y@gi@gfffffX@g      %g     r)r   rQ   r  r   )r,  rN  g      @        g      )r   ir   r   i'  r   r   r   rQ   rc   r    g333333?rK  N)r^   rD  r   r!   rB   r   rA   r;  rf   r'  r   )r   np_dtZdataset_namer   r&   Zarray_0Zarray_1Zarray_2Zcasted_array_2Zlist_3Zlist_array_3Zlist_4Zlist_array_4r   r   r   _help_float_testingR  s2    


zTestVlen._help_float_testingc                 C   s   t d}| | d S )Nr  rB   rA   rQ  r   rP  r   r   r   test_numpy_float16  s    
zTestVlen.test_numpy_float16c                 C   s   t d}| | d S )Nfloat32rR  rS  r   r   r   test_numpy_float32  s    
zTestVlen.test_numpy_float32c                 C   s   t d}| | d S )Nr  rR  rS  r   r   r   test_numpy_float64_from_dtype  s    
z&TestVlen.test_numpy_float64_from_dtypec                 C   s   t j}| | d S r   )rB   r  rQ  rS  r   r   r   test_numpy_float64_2  s    zTestVlen.test_numpy_float64_2c                 C   s  | j jddtdd tg d}|ddd | j d d< t| j d d |ddd ksJ | j d d  d	|ddd  | j jd
dtdd tg d}|ddd | j d
 d< t| j d
 d |ddd ks
J | j d
 d  d	|ddd  dS )z4Test that non-contiguous arrays are stored correctlyncr   r>  rH   )TFTTFFFNrQ   r   z != Znc2Zint8)rQ   r    r   r   r   rc   r   )r   r!   r^   rD  rB   r   r   )r   r  r  r   r   r   test_non_contiguous_arrays  s    Fz#TestVlen.test_non_contiguous_arraysN)rC  )r   r   r   rM  rF  rH  rL  rM  rQ  rT  rV  rW  rX  rZ  r   r   r   r   rB    s   	
0rB  c                   @   s   e Zd Zdd Zdd ZdS )TestLowOpenc                 C   s   | j dd}|j }dS )z Test H5Dget_access_plist r   r   N)r   r!   rk   r_  )r   r&   Zp_listr   r   r   test_get_access_list  s    z TestLowOpen.test_get_access_listc                 C   sH   t jt jj}| jdd}~t j| jjd|}| 	|t jj
 dS )z# Test the dapl keyword to h5d.open r  r      xN)r^   Zh5pr/  ZDATASET_ACCESSr   r!   Zh5drY  rk   r"   Z	DatasetID)r   Zdaplr.   Zdsidr   r   r   	test_dapl  s
    zTestLowOpen.test_daplN)r   r   r   r\  r^  r   r   r   r   r[    s   r[  )r   r9   r   z#chunk info requires  HDF5 >= 1.10.5c               	   C   sj  ddl m}  |  }t|d2}|jddddd d	|d d d < W d    n1 sV0    Y  |d t|d
}|d j}| dksJ tdD ]`}t	t
t
|dd }||}|j|ksJ |jdksJ |jd usJ |jdksJ q|d}|jdksJ |jdks&J |jd us6J |jdksFJ W d    n1 s\0    Y  d S )Nr   BytesIOr   r  r  r]   r   )r,   r   rA   r   rA  r   r9   r   )ior`  r^   r   r!   seekrk   Zget_num_chunksrF  r   rB   r   Zunravel_indexZget_chunk_infoZchunk_offsetZfilter_maskZbyte_offsetr<   Zget_chunk_info_by_coord)r`  buffoutfinr&   joffsetsir   r   r   test_get_chunk_details  s*    .



ri  c                 C   s.   | j ddd}|jd u sJ |jd u s*J d S )Nr"  r   rH   )r!   r,   r   )r   r&   r   r   r   test_empty_shape  s    rj  c                  C   s   ddl m}  |  }t|d}|jddd W d    n1 sB0    Y  |d t|dN}|d jd u svJ |d j d u sJ |d j	 dksJ W d    n1 s0    Y  d S )Nr   r_  r   r"  r  rH   rA  )
ra  r`  r^   r   r!   rb  r   rk   Z
get_offsetZget_storage_size)r`  rc  rd  re  r   r   r   test_zero_storage_size  s    ,
rk  c                 C   s   t t jjt t jjd g}| jd|t jd}|jt t jksHJ t j|d d  t j	|t jd ||d d < t j|d d  t j	|t jd d S )Nr   r  r-  rH   )
rB   Ziinfor   maxr!   Zuint64rA   r   r   r   )r   rY   r&   r   r   r   test_python_int_uint64  s     "rm  c                 C   s<   | j ddtjd}tjjddd}||d d g ddf< d S )	NrY   )r   rp  rQ   rH      )r   rc   rQ   rH  )r   rQ   r    .)r!   rB   r  rC  rI  )r   r   blockr   r   r   test_setitem_fancy_indexing  s    rp  c                  C   sD   t td$} | d d dks"J W d    n1 s60    Y  d S )Nzvlen_string_dset.h5ZDS1r   s   Partingr   r   r   r   r   r   test_vlen_spacepad  s    rs  c                  C   sD   t td$} | d d dks"J W d    n1 s60    Y  d S )Nzvlen_string_dset_utc.h5Zds1r   s   2009-12-20T10:16:18.662409Zrq  rr  r   r   r   test_vlen_nullterm  s    rt  )r   r9   rc   z>Appears you cannot pass an unknown filter id for HDF5 < 1.10.3c                 C   s0   d}| j ddtj|dd}t||jv s,J d S )N   rY   r]   T)r,   rA   r  Zallow_unknown_filter)r!   rB   r  r$   _filters)r   Zfake_filter_idr&   r   r   r   test_allow_unknown_filter  s    
rw  c                   @   s    e Zd ZdZdd Zdd ZdS )TestCommutativez|
    Test the symmetry of operators, at least with the numpy types.
    Issue: https://github.com/h5py/h5py/issues/1947
    c                 C   s   d}| j jd|ttjj| d}t|d }t||k||kksHJ t||k||kksbJ d}t|| }t||k||kksJ t||k||kksJ dS )z
        Create a h5py dataset, extract one element convert to numpy
        Check that it returns symmetric response to == and !=
        r   r   r  rA   rY   r   gMbP?N)	r   r!   r;  rB   rC  rD  r  r   Znanmax)r   r,   r.   valdeltanvalr   r   r   test_numpy_commutative  s    
z&TestCommutative.test_numpy_commutativec                 C   sT   d}| j jd|ttjj| d}td}||k||kks<J ||k||kksPJ dS )z
        Create a h5py dataset and check basetype compatibility.
        Check that operation is symmetric, even if it is potentially
        not meaningful.
        ry  r  rz  rO  N)r   r!   r;  rB   rC  rD  )r   r,   r.   r{  r   r   r   test_basetype_commutative-  s    
z)TestCommutative.test_basetype_commutativeN)r   r   r   r(   r~  r  r   r   r   r   rx    s   rx  c                   @   sH   e Zd ZdZejejdk dddd Zejejdk dddd Z	d	S )
TestVirtualPrefixz%
    Test setting virtual prefix
    )r   r9   rQ   z8Virtual prefix does not exist before HDF5 version 1.10.2r$  c                 C   sR   d}d}| j jd|ttjj| |d}t|j	 
   }||ksNJ d S )Nry  /path/to/virtualr  )rA   rY   virtual_prefix)r   r!   r;  rB   rC  rD  r]  r^  rk   r_  get_virtual_prefixra  rb  )r   r,   r  r.   virtual_prefix_readbackr   r   r   test_virtual_prefix_createA  s    
z,TestVirtualPrefix.test_virtual_prefix_createc                 C   s^   d}| j jddd|d}t|j    }| 	|| | 
|t | 	|jd d S )Nr  r   rb   r   )r  )r   r   r]  r^  rk   r_  r  ra  rb  r+   r"   r   r,   )r   r  r.   r  r   r   r   test_virtual_prefix_requireM  s    z-TestVirtualPrefix.test_virtual_prefix_requireN)
r   r   r   r(   r   rU   r   r\  r  r  r   r   r   r   r  =  s   

r  )Ur(   r]  rh  r  numpyrB   rJ   rL   r8  commonr   r   
data_filesr   r^   r   r   r   Zh5py._hl.baser	   r
   r   Zh5py.h5py_warningsr   r   Zh5py._hl.selectionsr  
selectionsselr   r   r)   rW   r   r   r   r   r   r  rU   filtersr  r
  r  r%  r-  r2  r5  r8  rQ  r{  r  r  r  r  r  r  r  r  r  r	  r  r  r  r   rM   r\  r3  r&  r4  r@  rB  r[  r  ri  rj  rk  rm  rp  rs  rt  Zskipifrw  rx  r  r   r   r   r   <module>
   s   		FY0(CC&,'qc,D ?E
0 




-