o
    giZ                    @   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
 ddlmZmZ ddlmZmZ ddlmZmZ ddlZddlmZmZmZmZmZ dd	lmZ d
dl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j'(d e)dfej*dfej+dfe,d!fej-d!fej.d!fej/d"d#d$d%fej/d&d#d$d%fej/d"d'd%fej/d&d'd%fe/ d%fgd(d) Z0G d*d+ d+eZ1e2d,ej3j4vd-G d.d/ d/eZ5e2d,ej3j4vd-G d0d1 d1eZ6e2d2ej3j4vd3G d4d5 d5eZ7e2d6ej3j4vd7G d8d9 d9eZ8e2d:ej3j4vd;G d<d= d=eZ9e2d>ej3j4vd?G d@dA dAeZ:e2dBej3j4vdCG dDdE dEeZ;G dFdG dGeZ<G dHdI dIeZ=G dJdK dKeZ>G dLdM dMeZ?G dNdO dOeZ@G dPdQ dQeZAG dRdS dSeZBG dTdU dUeZCG dVdW dWeZDG dXdY dYeZEG dZd[ d[eZFG d\d] d]eZGG d^d_ d_eZHG d`da daeZIG dbdc dceZJG ddde deeZKG dfdg dgeZLG dhdi dieZMG djdk dkeZNG dldm dmeZOdndo ZPeQejRjSdpkp+ejRjSdqko+ejRjSdrk dsdtdu ZTdvdw ZUdxdy ZVdzd{ ZWd|d} ZXd~d ZYdd ZZdd Z[dd Z\G dd deZ]G dd deZ^dddZ_dddZ`ej'j(ddd e_fdd e_fdd e_fdd e`fgg ddZaedk rdndZbej'(ddebgeadd Zcej'jdedk ddeadd Zeeadd Zfeadd Zgeadd Zheadd Ziej'jjdddd Zkdd Zldd Zmdd Znd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)ThreadPoolExecutor)FileDataset)is_empty_dataspaceproduct)h5fh5t   )utTestCaseNUMPY_RELEASE_VERSIONis_main_thread	make_name)get_data_file_path   )H5pyDeprecationWarningc                   @      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   U/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/h5py/tests/test_dataset.pysetUp'   s   zBaseDataset.setUpc                 C   s   | j r
| j   d S 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                   @   sB   e Zd ZdZejdkrdndZdd Zej	j
dd Zd	d
 ZdS )TestReprz5
        Feature: repr(Dataset) behaves sensibly
    big><c                 C   s<   t  }| jj|ddd}t|d| d| j dksJ d S )N   int32dtypez<HDF5 dataset "z": shape (4,), type "i4">)r   r   create_datasetreprendian_markr   namedsr   r   r   test_repr_basic5   s   $zTestRepr.test_repr_basicc                 C   s2   | j jt ddd}| j   t|dksJ dS )z( repr() works on live and dead datasets r&   f4r)   z<Closed HDF5 dataset>N)r   r,   r   r   r-   r   r1   r   r   r   test_repr_closed:   s   
zTestRepr.test_repr_closedc                 C   s0   | j jd ddd}t|d| j dksJ d S )Nr&   r(   r)   z-<HDF5 dataset (anonymous): shape (4,), type "r+   )r   r,   r-   r.   r4   r   r   r   test_repr_anonymousA   s   zTestRepr.test_repr_anonymousN)r   r    r!   __doc__sys	byteorderr.   r2   pytestmarkthread_unsafer5   r6   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eeed ddd Zdd Zdd ZdS )TestCreateShapez@
        Feature: Datasets can be created from a shape only
    c                 C   &   | j jt ddd}| |jd dS )z Create a scalar dataset r   r3   r)   Nr   r,   r   assertEqualshaper   dsetr   r   r   test_create_scalarL      z"TestCreateShape.test_create_scalarc                 C   r>   )z Create a size-1 dataset r	   r3   r)   Nr?   rB   r   r   r   test_create_simpleQ   rE   z"TestCreateShape.test_create_simplec                 C   &   | j jt ddd}| |jd dS )z+ Create a size-1 dataset with integer shaper	   r3   r)   rF   Nr?   rB   r   r   r   test_create_integerV   rE   z#TestCreateShape.test_create_integerc                 C   4   | j jt ddd}| |jd | |jd dS )z- Create an extended dataset with tuple shape ?   r3   r)   rL   Nr   r,   r   r@   rA   sizerB   r   r   r   test_create_extended_1d[      z'TestCreateShape.test_create_extended_1dc                 C   rJ   )z. Create an extended dataset with 2 dimensions )   
   r3   r)   <   NrM   rB   r   r   r   test_create_extended_2da   rP   z'TestCreateShape.test_create_extended_2dc                 C   s4   | j jt ddd}| |jd | |jd dS )z/ Create an extended dataset with integer shape rL   r3   r)   rK   NrM   rB   r   r   r   test_create_integer_extendedg   rP   z,TestCreateShape.test_create_integer_extendedc                 C   s,   | j jt ddd}| |jtd dS )) Confirm that the default dtype is float rK   r3   r)   z=f4Nr   r,   r   r@   r*   nprB   r   r   r   test_default_dtypem   s   z"TestCreateShape.test_default_dtypec                 C   s>   |  t | jt  W d   dS 1 sw   Y  dS )z  Missing shape raises TypeError NassertRaises	TypeErrorr   r,   r   r   r   r   r   test_missing_shaper   s   "z"TestCreateShape.test_missing_shapec                 C   sH   | j jt dtjd}t dv rtdt   | 	|j
tj dS )rV   rK   r)   )ppc64lez(Storage of long double deactivated on %sN)r   r,   r   rX   
longdoubleplatformmachiner:   xfailr@   r*   rB   r   r   r   test_long_doublew   s   z TestCreateShape.test_long_double
complex256zNo support for complex256c                 C   s2   | j jt dtdd}| |jtd dS )rV   rK   rd   r)   N)r   r,   r   rX   r*   r@   rB   r   r   r   test_complex256~   s   zTestCreateShape.test_complex256c                 C   sX   | j jtddddd}| |jd | j jtddddd}| |jd d S )Nfooutf-8rF   r3   r)   z	bar{}/bazr   )r   r,   r   encoder@   rA   )r   rC   dset2r   r   r   test_name_bytes   s   zTestCreateShape.test_name_bytesc                 C   sR   t t | jt d}W d    n1 sw   Y  |jtdks'J d S )N   r3   )r:   warnsr   r   r,   r   r*   rX   rB   r   r   r   test_no_dtype   s   zTestCreateShape.test_no_dtypeN)r   r    r!   r7   rD   rG   rI   rO   rT   rU   rY   r]   rc   r
   skipIfhasattrrX   re   rk   ro   r   r   r   r   r=   F   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   2   t dd}| jjt |d}| |j|j dS )z- Create a scalar dataset from existing array r   r   dataNrX   onesr   r,   r   r@   rA   r   ru   rC   r   r   r   rD         z!TestCreateData.test_create_scalarc                 C   rs   )z/ Create an extended dataset from existing data rK   r   rt   Nrv   rx   r   r   r   test_create_extended   ry   z#TestCreateData.test_create_extendedc                 C   s<   t d}| jj|ddd}| |tj | || jv  dS )z1 Create dataset with missing intermediate groups z/foo{}/bar/bazrR   rR   z<i4rA   r*   N)r   r   r,   assertIsInstanceh5pyr   
assertTruer/   r   r   r   test_dataset_intermediate_group   s   z.TestCreateData.test_dataset_intermediate_groupc                 C   sJ   t jddd}| jjt d|d}| |jd | |d |d dS )z8 Create from existing data, and make it fit a new shape    r   r)   rR      rA   ru   .N)	rX   aranger   r,   r   r@   rA   assertArrayEqualreshaperx   r   r   r   test_reshape   s   zTestCreateData.test_reshapec                 C   s@   |  t t| jd j W d   dS 1 sw   Y  dS )zE Binding Dataset to a non-DatasetID identifier fails with ValueError /N)r[   
ValueErrorr   r   idr   r   r   r   test_appropriate_low_level_id   s   "z,TestCreateData.test_appropriate_low_level_idc                 C   sb   |j  }t|tjsJ | |ksJ |d u r!| sJ d S | r'J | |ks/J d S r   )r   get_type
isinstancer   TypeStringIDget_csetis_variable_strget_size)r   rC   csetlengthtidr   r   r   check_h5_string   s   
zTestCreateData.check_h5_stringc                    s    fdd}| j jtddd | j jtdddgd | j jtddgdggd | j jtd	tjddgtd
d dS )z= Creating dataset with byte string yields vlen ASCII dataset c                        j | tjd d d S Nr   )r   r   
CSET_ASCIIrC   r   r   r   check_vlen_ascii      z?TestCreateData.test_create_bytestring.<locals>.check_vlen_asciia   abcrt   b   defcdr)   Nr   r,   r   rX   arrayobject)r   r   r   r   r   test_create_bytestring   s    z%TestCreateData.test_create_bytestringc                 C   s6   | j jt tjddgddd}| j|tjdd d S )Nr   r   S3r)   rt   r   r   )r   r,   r   rX   r   r   r   r   rB   r   r   r   test_create_np_s   s    zTestCreateData.test_create_np_sc                    s    fdd}| j jtddd | j jtdddgd | j jtddgdggd | j jtd	tjddgtd
d d S )Nc                    r   r   )r   r   	CSET_UTF8r   r   r   r   check_vlen_utf8   r   z;TestCreateData.test_create_strings.<locals>.check_vlen_utf8r   abcrt   r   defr   r   r)   r   )r   r   r   r   r   test_create_strings   s    z"TestCreateData.test_create_stringsc                 C   sP   |  t | jjt tjddgddd W d    d S 1 s!w   Y  d S )Nr   r   U3r)   rt   )r[   r\   r   r,   r   rX   r   r   r   r   r   test_create_np_u   s   ""zTestCreateData.test_create_np_uc                 C   s0   t  }| jj|dd | t| j| j d S )Nr   r)   )r   r   r,   r   r   r   r   r0   r   r   r    test_empty_create_via_None_shape   s   z/TestCreateData.test_empty_create_via_None_shapec                 C   s8   t  }| jj|tjddd | t| j| j d S )Nr   r)   rt   )r   r   r,   r~   Emptyr   r   r   r   r   r   r   !test_empty_create_via_Empty_class   s   z0TestCreateData.test_empty_create_via_Empty_classc                 C   sJ   |  t | jjt dtdd W d    d S 1 sw   Y  d S )Nr'   r   r   )r[   r   r   r,   r   rX   r   r   r   r   r   test_create_incompatible_data   s   "z,TestCreateData.test_create_incompatible_dataN)r   r    r!   r7   rD   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rr      s    

rr   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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   rR   2   rS   F   Z   Nr   rR      r   r   rm      	   rQ   r   rQ   r   c           
      C   sn   t jt|dd|}|jt ||d}t j|ddd}| }	|| |	|< |||| t j	
||	 d S )Nint64r)   rt   )rX   r   r   r   r,   r   fullcopyread_directtestingassert_array_equal)
r   writable_filesource_shape
dest_shape
source_seldest_selsource_valuesrC   arrexpectedr   r   r   test_read_direct   s   	z!TestReadDirectly.test_read_directc                 C   sP   |j t dtjdddd}tjddd}|| tj|tjddd d S )NrR   rR   r   r)   rt   )r,   r   rX   r   rw   r   r   r   r   r   rC   r   r   r   r   test_no_sel  s   
zTestReadDirectly.test_no_selc                 C   sn   |j t dd}tdd}tt ||tjdd tjdd  W d    d S 1 s0w   Y  d S Nr   r)   r   r   rR   r   rS   )	r,   r   rX   rw   r:   raisesr\   r   s_)r   r   
empty_dsetr   r   r   r   
test_empty  s
   $"zTestReadDirectly.test_emptyc                 C   V   |j t ddd}td}tt || W d    d S 1 s$w   Y  d S Nr   r   r)      r,   r   rX   rw   r:   r   r\   r   r   r   r   r   test_wrong_shape  
   
"z!TestReadDirectly.test_wrong_shapec                 C   Z   |j t ddd}tjddd}tt || W d    d S 1 s&w   Y  d S Nr{   r   r)   F)orderr   r   r   r   r   test_not_c_contiguous  
   "z&TestReadDirectly.test_not_c_contiguousc                 C   s|   d}|j t |tjd}tj|tjd}|| tjdtjd}tt || W d    d S 1 s7w   Y  d S )N)r   r   r)   )r      )	r,   r   rX   r   zerosr   r:   r   r\   )r   r   rA   rC   r   arr2r   r   r   test_zero_length  s   
"z!TestReadDirectly.test_zero_length)r   r    r!   r7   r:   r;   parametrizerX   r   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   rR   r   rS   r   r   Nr   r   r   r   r   r   rQ   r   c           	      C   sl   |j t |ddd}tt||}tj|ddd}|| ||< |||| tj	|d d  | d S )Nr(   r   r*   	fillvaluer)   )
r,   r   rX   r   r   r   r   write_directr   r   )	r   r   r   r   r   r   rC   r   r   r   r   r   test_write_direct1  s   	z#TestWriteDirectly.test_write_directc                 C   sh   |j t dd}tt |tdtjdd tjdd  W d    d S 1 s-w   Y  d S r   )	r,   r   r:   r   r\   r   rX   rw   r   )r   r   r   r   r   r   r   A  s   *"zTestWriteDirectly.test_emptyc                 C   r   r   r,   r   rX   rw   r:   r   r\   r   r   r   r   r   r   F  r   z"TestWriteDirectly.test_wrong_shapec                 C   r   r   r   r   r   r   r   r   L  r   z'TestWriteDirectly.test_not_c_contiguous)r   r    r!   r7   r:   r;   r   rX   r   r   r   r   r   r   r   r   r   r   +  s    .$
r   c                   @   `   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S )TestCreateRequirezS
        Feature: Datasets can be created only if they don't exist in the file
    c                 C   s0   | j t dd}| |t | |jd dS )z& Create new dataset with no conflicts r   r   N)r   require_datasetr   r}   r   r@   rA   rB   r   r   r   test_createY  s   zTestCreateRequire.test_createc                 C   >   t  }| j|dd}d|d< | j|dd}| || dS )z) require_dataset yields existing dataset r   r   {   r   r   Nr   r   r   r@   r   r0   rC   rj   r   r   r   test_create_existing_  
   z&TestCreateRequire.test_create_existingc                 C   r   )z; require_dataset with integer shape yields existing datasetrR   r   r   r   Nr   r   r   r   r   test_create_1D_integerg  r   z(TestCreateRequire.test_create_1D_integerc                 C   s>   t  }| j|dd}d|d< | j|dd}| || d S )Nr   r   r   r   rR   r   r   r   r   r   test_create_1D_tupleo  s
   z&TestCreateRequire.test_create_1D_tuplec                 C   sD   t  }| j|dd}d|d< | j|ddd}| || d S )NrR   r   r   r   rg   r   )r   r   r   ri   r@   r   r   r   r   test_create_1D_binaryv  s
   z'TestCreateRequire.test_create_1D_binaryc                 C   sV   t  }| j|dd | t | j|dd W d   dS 1 s$w   Y  dS )z6 require_dataset with shape conflict yields TypeError r   r   )rR   r'   Nr   r   r,   r[   r\   r   r   r   r   r   test_shape_conflict}  s
   "z%TestCreateRequire.test_shape_conflictc                 C   sR   t  }| j| | t | j|dd W d   dS 1 s"w   Y  dS )z< require_dataset with object type conflict yields TypeError r   r   N)r   r   create_groupr[   r\   r   r   r   r   r   test_type_conflict  s
   "z$TestCreateRequire.test_type_conflictc                 C   sV   t  }| j|dd}| t | j|dd W d   dS 1 s$w   Y  dS )zL require_dataset with dtype conflict (strict mode) yields TypeError
        r   r   S10Nr  )r   r0   rC   r   r   r   test_dtype_conflict  s
   "z%TestCreateRequire.test_dtype_conflictc                 C   sB   t  }| j|dd}d|d< | jj|dddd}| || dS )z* require_dataset with exactly dtype match r   r   r   r   TexactN)r   r   r,   r   r@   r   r   r   r   test_dtype_exact  s
   z"TestCreateRequire.test_dtype_exactc                 C   sV   t  }| j|dd}d|d< | jj|dddd}| || | |jtd dS )	zJ require_dataset with convertible type succeeds (non-strict mode)
        r   i4í r   i2Fr	  N)r   r   r,   r   r@   r*   rX   r   r   r   r   test_dtype_close  s   z"TestCreateRequire.test_dtype_closeN)r   r    r!   r7   r   r   r   r  r  r  r  r  r  r  r   r   r   r   r   S  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t dddd}| |jd dS )z Create via chunks tuple r   r   r3   rA   chunksr*   Nr   r,   r   r@   r  rB   r   r   r   test_create_chunks     z$TestCreateChunked.test_create_chunksc                 C   (   | j jt dddd}| |jd dS )z Create via chunks integer r   rR   r3   r  r   Nr  rB   r   r   r   test_create_chunks_integer  r  z,TestCreateChunked.test_create_chunks_integerc                 C   F   |  t | jjt dddd W d   dS 1 sw   Y  dS )z& Illegal chunk size raises ValueError r   r   r3   r  Nr[   r   r   r,   r   r   r   r   r   test_chunks_mismatch     "z&TestCreateChunked.test_chunks_mismatchc                 C   H   |  t | jjt ddddd W d   dS 1 sw   Y  dS )z3 Chunked format required for given storage options r   r   Fr3   )rA   maxshaper  r*   Nr  r   r   r   r   test_chunks_false  s   "z#TestCreateChunked.test_chunks_falsec                 C   r  )z> Attempting to create chunked scalar dataset raises TypeError r   r   r3   r  NrZ   r   r   r   r   test_chunks_scalar  r  z$TestCreateChunked.test_chunks_scalarc                 C   s:   | j jt dddd}| |jt | t|jd dS )z Auto-chunking of datasets )r   r   Tr3   r  r   N)r   r,   r   r}   r  tupler@   lenrB   r   r   r   test_auto_chunks  s   z"TestCreateChunked.test_auto_chunksc                 C   r  )z7 Auto-chunking with pathologically large element sizes r   
S100000000TrA   r*   r  rF   Nr  rB   r   r   r   test_auto_chunks_abuse  r  z(TestCreateChunked.test_auto_chunks_abusec                 C   s   | j jt 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   r   r   )r	   r   r   r%  rR   r	   N(         r   r   )r   r,   r   rX   r(   r   allrB   r   r   r   test_scalar_assignment  s   " z(TestCreateChunked.test_scalar_assignmentc                 C   s   t  }tjtdd}| jj|ddd W d   n1 sw   Y  tjtdd}| jj|ddd W d   dS 1 s?w   Y  dS )	z, Auto-chunking of empty datasets not allowedr   matchS100T)r*   r  Nr   r*   r  )r   r:   r   r\   r   r,   )r   r0   errr   r   r   test_auto_chunks_no_shape  s   "z+TestCreateChunked.test_auto_chunks_no_shapeN)r   r    r!   r7   r  r  r  r  r  r"  r&  r+  r1  r   r   r   r   r    s    r  c                   @   8   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   s:   | j jt dddd}| |d d | |d d dS )z- Fill value is reflected in dataset contents r         @r3   r   r*   r   r   N)r   r,   r   r@   rB   r   r   r   test_create_fillval  s   z'TestCreateFillvalue.test_create_fillvalc                 C   s8   | j jt dddd}| |jd | |jtj dS )z( Fill value is recoverable via property r   g      @r3   r5  N)r   r,   r   r@   r   assertNotIsInstancerX   ndarrayrB   r   r   r   test_property  s   z!TestCreateFillvalue.test_propertyc                 C   rH   )z0 .fillvalue property works correctly if not set r   r3   r)   r   N)r   r,   r   r@   r   rB   r   r   r   test_property_none  rE   z&TestCreateFillvalue.test_property_nonec                 C   sX   t ddg}t jd|dd }| jjt d||d}| |j| | |d | d	S )
z& Fill value works with compound types )r   r3   )r   i8rF   r)   r   r   r   r'   N)	rX   r*   rw   r   r,   r   r@   r   assertAlmostEqual)r   dtvrC   r   r   r   test_compound  s
   z!TestCreateFillvalue.test_compoundc                 C   sJ   |  t | jjt dddgdd}W d   dS 1 sw   Y  dS )z$ Bogus fill value raises ValueError r   r   i)r   r   *   r   Nr  rB   r   r   r   test_exc
  s
   "zTestCreateFillvalue.test_excN)	r   r    r!   r7   r6  r9  r:  r?  rC  r   r   r   r   r3    s    r3  c                   @   sl   e Zd ZdZdd Zedejj	vd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 )TestFillTimezI
        Feature: Datasets created with specified fill time property
    c                 C   sX   | j jt dddd}|j }| | tjj	 | |d d | |d d dS )z Fill time default to IFSET r   r3   r4  )r   r   r   N
r   r,   r   r   get_create_plistr@   get_fill_timer~   h5dFILL_TIME_IFSETr   rC   plistr   r   r   test_fill_time_default  s
   
z#TestFillTime.test_fill_time_defaultgzipDEFLATE is not installedc                 C   sZ   | j jt ddddd}|j }| | tjj	 | |d d | |d d dS )	z5 Fill time is IFSET for compressed dataset (chunked) r   r3   rM  r4  )compressionr   r   r   NrE  rJ  r   r   r   test_compressed_default  s   
z$TestFillTime.test_compressed_defaultc                 C   sZ   | j jt ddddd}|j }| | tjj	 | 
|d d | 
|d d dS )	z Fill time set to NEVER r   r3   r4  neverr   	fill_timer   r   N)r   r,   r   r   rF  r@   rG  r~   rH  FILL_TIME_NEVERassertNotEqualrJ  r   r   r   test_fill_time_never)  s   
z!TestFillTime.test_fill_time_neverc                 C   s:   | j jt ddddd}|j }| | tjj	 dS )z# Fill time explicitly set to ALLOC r   r3   r4  allocrR  N)
r   r,   r   r   rF  r@   rG  r~   rH  FILL_TIME_ALLOCrJ  r   r   r   test_fill_time_alloc3  s
   
z!TestFillTime.test_fill_time_allocc                 C   s<   | j jt dddddd}|j }| | tjj	 dS )z# Fill time explicitly set to IFSET r   r3   rh   r4  ifset)r  r   rS  NrE  rJ  r   r   r   test_fill_time_ifset:  s
   
z!TestFillTime.test_fill_time_ifsetc                 C   F   |  t | jjt dddd}W d   dS 1 sw   Y  dS )z2 Choice of fill_time is 'alloc', 'never', 'ifset' r   r3   fill_badrS  Nr  rB   r   r   r   test_invalid_fill_timeA  r  z#TestFillTime.test_invalid_fill_timec                 C   r\  )z fill_time must be a string r   r3   r   r^  Nr  rB   r   r   r   test_non_str_fill_timeF  r  z#TestFillTime.test_non_str_fill_timec                 C   s|   | j jt ddddd}|j }| | tjj	 t
|dd d s)J |d t
|dd d s<J dS )z= The resize dataset will be filled (by default fill value 0) r  r3   r   rl   )r  r  N        )r   r,   r   r   rF  r@   rG  r~   rH  rI  rX   iscloser*  resizerJ  r   r   r   #test_resize_chunk_fill_time_defaultK  s   

 z0TestFillTime.test_resize_chunk_fill_time_defaultc              	   C   s   | j jt ddddddd}|j }| | tjj	 t
|dd d r+J |d t
|dd d r>J dS )	z$ The resize dataset won't be filled r  r3   r   r4  rQ  rl   )r  r   rS  r  N)r   r,   r   r   rF  r@   rG  r~   rH  rT  rX   rb  anyrc  rJ  r   r   r   !test_resize_chunk_fill_time_neverW  s   

 z.TestFillTime.test_resize_chunk_fill_time_neverN)r   r    r!   r7   rL  r
   rp   r~   filtersri   rP  rV  rY  r[  r_  r`  rd  rf  r   r   r   r   rD    s    
	
rD  zdt,expectedra  rg   rm   encodingr       asciiri  c                 C   s$   |j t d| d}|j|ksJ d S )Nr   r)   )r,   r   r   )r=  r   r   rC   r   r   r   test_get_unset_fill_valuee  s   rm  c                   @      e Zd ZdZdd ZdS )TestCreateNamedTypezC
        Feature: Datasets created from an existing named type
    c                 C   sx   t d}td| j|< | j| }| jjt dd|d}| |jtd | |j |j | |j 	  dS )z7 Named type object works and links the dataset to type typef8xr   r)   N)
r   rX   r*   r   r,   r@   r   r   r   	committed)r   r0   r=  rC   r   r   r   
test_named~  s   
zTestCreateNamedType.test_namedN)r   r    r!   r7   rt  r   r   r   r   ro  x      ro  rM  rN  c                   @   s>   e Zd ZdZdd Zdd Zejjdddd	 Z	d
d Z
dS )TestCreateGzipz=
        Feature: Datasets created with gzip compression
    c                 C   s8   | j jt ddddd}| |jd | |jd dS )z# Create with explicit gzip options r   r   r3   rM  r   rO  compression_optsNr   r,   r   r@   rO  ry  rB   r   r   r   	test_gzip  s
   zTestCreateGzip.test_gzipc                 C   s6   | j jt dddd}| |jd | |jd dS )z+ Create with implicit gzip level (level 4) rw  r3   rM  rO  r'   Nrz  rB   r   r   r   test_gzip_implicit     z!TestCreateGzip.test_gzip_implicitmonkey-patchreasonc                 C   s   t  }| jj|dddd}| |jd | |jd tjjj	}z5t
 tjj_	| t | jj|dddd}W d   n1 sAw   Y  W |tjj_	dS W |tjj_	dS |tjj_	w )z. Create with gzip level by specifying integer rw  r3   r   r|  rM  N)r   r   r,   r@   rO  ry  r~   _hldataset_LEGACY_GZIP_COMPRESSION_VALSr   r[   r   )r   r0   rC   original_compression_valsr   r   r   test_gzip_number  s   
zTestCreateGzip.test_gzip_numberc                 C   s   t  }| ttf | jj|dddd W d   n1 sw   Y  | t | jj|dddd W d   n1 s>w   Y  | t | jj|ddddd W d   dS 1 s_w   Y  dS )	z= Illegal gzip level (explicit or implicit) raises ValueError rw  r3      r|  NrM  rx  )r   r[   r   RuntimeErrorr   r,   r   r   r   r   test_gzip_exc  s   "zTestCreateGzip.test_gzip_excN)r   r    r!   r7   r{  r}  r:   r;   r<   r  r  r   r   r   r   rv    s    
rv  c                   @   s<   e Zd ZdZejjdddd Zejjdddd ZdS )	TestCreateCompressionNumberz?
        Feature: Datasets created with a compression code
    r  r  c                 C   sl   t jjj}zt t jj_| jjddt jjddd}W |t jj_n|t jj_w | 	|j
d | 	|jd dS )	z^ Create with compression number of gzip (h5py.h5z.FILTER_DEFLATE) and a compression level of 7rf   rw  )r   r3   )rO  ry  r*   rM  r   N)r~   r  r  r  r   r   r,   h5zFILTER_DEFLATEr@   rO  ry  )r   r  rC   r   r   r   test_compression_number  s   
z3TestCreateCompressionNumber.test_compression_numberc                 C   s&  |  t}| jjddddd W d   n1 sw   Y  | dt|j |  t}| jjddddd W d   n1 sBw   Y  | d	t|j tjj	j
}z7t tjj	_
|  t | jjddtjjdd W d   n1 sxw   Y  W |tjj	_
dS W |tjj	_
dS |tjj	_
w )
z* Create with invalid compression numbers  rf   rw  ir3   rO  r*   NzInvalid filterr   zUnknown compression)r[   r   r   r,   assertInstr	exceptionr~   r  r  r  r   
IndexErrorr  r  )r   er  r   r   r   test_compression_number_invalid  s"   
z;TestCreateCompressionNumber.test_compression_number_invalidN)	r   r    r!   r7   r:   r;   r<   r  r  r   r   r   r   r    s    
r  lzfzLZF is not installedc                   @   (   e Zd ZdZdd Zdd Zdd ZdS )	TestCreateLZF<
        Feature: Datasets created with LZF compression
    c                 C   s6   | j jt dddd}| |jd | |jd dS )z( Create with explicit lzf (empty chunks)rw  r  r3   r  Nrz  rB   r   r   r   test_lzf_sparse  r~  zTestCreateLZF.test_lzf_sparsec                 C   sf   t  }td}| jj||dd}| |jd | |jd | j  | j| d }| 	|| dS )z% Create with explicit lzf (populated)r   r  )ru   rO  Nr   )
r   rX   r   r   r,   r@   rO  ry  flushr   )r   r0   testdatarC   readdatar   r   r   test_lzf_dense  s   

zTestCreateLZF.test_lzf_densec                 C   r  )z& Giving lzf options raises ValueError rw  r3   r  r'   rx  Nr  r   r   r   r   test_lzf_exc  s
   "zTestCreateLZF.test_lzf_excN)r   r    r!   r7   r  r  r  r   r   r   r   r    s
    r  szipzSZIP is not installedc                   @   rn  )TestCreateSZIPr  c                 C   s   | j jt ddddd}dS )z Create with explicit szip rw  r3   r  )ec   rx  N)r   r,   r   rB   r   r   r   	test_szip
  s   
zTestCreateSZIP.test_szipN)r   r    r!   r7   r  r   r   r   r   r        r  shufflezSHUFFLE is not installedc                   @   rn  )TestCreateShufflez8
        Feature: Datasets can use shuffling filter
    c                 C   &   | j jt dddd}| |j dS )z Enable shuffle filter rw  Tr3   )r  r*   N)r   r,   r   r   r  rB   r   r   r   test_shuffle     zTestCreateShuffle.test_shuffleN)r   r    r!   r7   r  r   r   r   r   r    r  r  
fletcher32zFLETCHER32 is not installedc                   @   rn  )TestCreateFletcher32z=
        Feature: Datasets can use the fletcher32 filter
    c                 C   r  )z Enable fletcher32 filter rw  Tr3   )r  r*   N)r   r,   r   r   r  rB   r   r   r   test_fletcher32#  r  z$TestCreateFletcher32.test_fletcher32N)r   r    r!   r7   r  r   r   r   r   r    ru  r  scaleoffsetzSCALEOFFSET is not installedc                   @   H   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

    Note: loss of precision caused by scaleoffset only becomes visible
    when closing and reopening the File.
    Can't close/reopen the shared self.f in pytest-run-parallel.
    c                 C   F   |  t | jjt dtdd}W d   dS 1 sw   Y  dS )z[ Ensure that a scale factor is required for scaleoffset compression of floating point data rw  Tr*   r  Nr[   r   r   r,   r   floatrB   r   r   r    test_float_fails_without_options2     "z6TestCreateScaleOffset.test_float_fails_without_optionsc                 C   r  )z# Check when scaleoffset is negetiverw  gr  Nr  rB   r   r   r   test_non_integer8  r  z&TestCreateScaleOffset.test_non_integerc                 C   r  )z% Check when dtype is unsupported typerw  Tr  N)r[   r\   r   r,   r   boolrB   r   r   r   test_unsupport_dtype>  r  z*TestCreateScaleOffset.test_unsupport_dtypec           	      C   s   d}d}dd|  }t jj| d | }|  }t|d}|jd|t j|d}|jd	us0J ||d
< W d	   n1 s>w   Y  t|d}|d d
 }W d	   n1 sZw   Y  | j	||d|  d ||k
 rrJ d	S )z2 Scaleoffset filter works for floating point data r'   r   i,  r   rR   g      ?r   rf   r  N.r)	precision)rX   randomrandr   r~   r   r,   float64r  r   r*  )	r   scalefacrA   ranger  fnamer   rC   r  r   r   r   
test_floatD  s"   

	z TestCreateScaleOffset.test_floatc                 C   s   d}d}t jjdd| d |t jd}|  }t|d}|jd|t jd	d
}|jdus/J ||d< W d   n1 s=w   Y  t|d}|d d }W d   n1 sYw   Y  | 	|| dS )zB Scaleoffset filter works for integer data with default precision r)  r  r   r   r	   rN   r*   r   rf   Tr  N.r  )
rX   r  randintr   r   r~   r   r,   r  r   r   nbitsrA   r  r  r   rC   r  r   r   r   test_int^  s   
zTestCreateScaleOffset.test_intc                 C   s   d}d}t jjdd| |t jd}|  }t|d}|jd|t j|d}| |j	dk ||d	< W d
   n1 s<w   Y  t|d}|d d	 }W d
   n1 sXw   Y  | 
|| d
S )D Scaleoffset filter works for integer data with specified precision r)  r  r   r   r  r   rf   r  .Nr  )rX   r  r  r   r   r~   r   r,   r   r  r   r  r   r   r   test_int_with_minbitss  s   
z+TestCreateScaleOffset.test_int_with_minbitsc                 C   s   d}d}t jjdd|d  d |t jd}|  }t|d}|jd|t j|d	}| |j	dk ||d
< W d   n1 s@w   Y  t|d}|d d
 }W d   n1 s\w   Y  ||k
 riJ dS )r  r)  r  r   r   r	   r  r   rf   r  .Nr  )rX   r  r  r   r   r~   r   r,   r   r  r*  r  r   r   r   test_int_with_minbits_lossy  s   "
z1TestCreateScaleOffset.test_int_with_minbits_lossyN)r   r    r!   r7   r  r  r  r  r  r  r  r   r   r   r   r  )  s    r  c                   @   r  )TestExternalzB
        Feature: Datasets with the external storage property
    c           
      C   s   d}t j|}|  }|dtjfg}| jjt ||j|dd}||d< |j	dus+J t
|d}| }W d   n1 s?w   Y  || ksLJ t|j    }t| jjj }	||	ksjJ dS )z' Create and access an external dataset rQ   r   r   z	${ORIGIN}r*   externalefile_prefix.Nrb)rX   r  r   r   	UNLIMITEDr   r,   r   r*   r  openreadtobytespathlibPathr   get_access_plistget_efile_prefixdecodeas_posixfilenameparent)
r   rA   r  ext_filer  rC   fidcontentsr  r  r   r   r   test_contents  s   
zTestExternal.test_contentsc                 C   s   t  }d}tj|}|  }tj|dtjfg}| j	j
|||j|tj|d}||d< |jdus5J t|d}| }W d   n1 sIw   Y  || ksVJ t|j    }	t|j }
|	|
ksrJ | j	j|||jtj|d}|jdusJ |d |k dS )	z< Create and access an external dataset using an efile_prefixr  r   r  .Nr  )r  r   )r   rX   r  r   ospathbasenamer   r  r   r,   r*   dirnamer  r  r  r  r  r  r   r  r  r  r  r  r   )r   r0   rA   r  r  r  rC   r  r  r  r  rj   r   r   r   test_contents_efile_prefix  s$    
z'TestExternal.test_contents_efile_prefixc                 C   s   | j jt d|  dd dS )z/ External argument may be a file name str only r  r3   r  r*   N)r   r,   r   r   r   r   r   r   test_name_str  s   zTestExternal.test_name_strc                 C   s$   | j jt ddt|  d dS )z0 External argument may be a file name path only r  r3   )r  N)r   r,   r   r  r  r   r   r   r   r   test_name_path  s   
zTestExternal.test_name_pathc                    sR   |    d}t fddt|D }| jjt d|dd}t|j|ks'J dS )z9 External argument may be an iterable of multiple tuples r   c                 3   s    | ]
} |d  d fV  qdS )  Nr   .0rr  r  r   r   	<genexpr>  s    z/TestExternal.test_iter_multi.<locals>.<genexpr>r  r3   r  N)r   iterr  r   r,   r   r!  r  )r   Nr  rC   r   r  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 ]$\}}| | | jjt ||dd W d   n1 sRw   Y  q3dS )z" Test with invalid external lists r  r   zh5f.UNLIMITEDr3   r  N)	r   r\   r   r  r   r[   r   r,   r   )r   rA   r  exc_typer  r   r   r   test_invalid  s   

	zTestExternal.test_invalidc                 C   sV   |   }d}d}| jjt |d||d}|jdu sJ |j|ks"J |j|ks)J dS )z$ Create expandable external dataset )   @   )Nr  r3   )r  r  N)r   r   r,   r   r  rA   r  )r   r  rA   r  exp_dsetr   r   r   test_create_expandable  s   z#TestExternal.test_create_expandableN)r   r    r!   r7   r  r  r  r  r  r  r  r   r   r   r   r    s    	r  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   sF   |j  }| t|tjj | | | |r| s!J d S d S r   )	r   r   r@   rp  r~   r   r   r   r   )r   r1   r   variabler   r   r   r   assert_string_type  s   
z!TestAutoCreate.assert_string_typec                 C   s   t d}t d}t d}d| j|< | | j| tjj ddg| j|< | | j| tjj tjddgtjd| j|< | | j| tjj dS )	z<Assigning byte strings produces a vlen string ASCII dataset rr  yzs   Hello there   as   bcr)   N)	r   r   r  r~   r   r   rX   r   object_r   rr  r  r  r   r   r   test_vlen_bytes  s   
zTestAutoCreate.test_vlen_bytesc                 C   s   t d}t d}t d}dtd | j|< | | j| tjj ddg| j|< | | j| tjj tjddggtj	d| j|< | | j| tjj d	S )
z?Assigning unicode strings produces a vlen string UTF-8 dataset rr  r  r  Hello there4   r   bcr)   N)
r   chrr   r  r~   r   r   rX   r   r  r  r   r   r   test_vlen_unicode%  s   z TestAutoCreate.test_vlen_unicodec                 C   sN   t  }td| j|< | j| }| j|tjjdd | |j	
  d dS )zV Assignment of fixed-length byte string produces a fixed-length
        ascii dataset r  F)r  r(  N)r   rX   bytes_r   r  r~   r   r   r@   r   r   r   r/   r   r   r   test_string_fixed5  s
   
z TestAutoCreate.test_string_fixedN)T)r   r    r!   r7   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   sf   t d}t d}tddd| j|< | j|| j|  | j| }| |jd | |j	d  d S )Nrr  r  r   rm   rm   rm   )
r   rX   r   r   r   create_dataset_liker@   rA   assertIsr  )r   rr  r  dsliker   r   r   test_no_chunks@  s   
zTestCreateLike.test_no_chunksc                 C   s   t d}t d}t d}t d}| jj|tddd}| dtj|j	j
 | j||}| dtj|j	j
 | jj|tdd	d}| dtj|j	j
 | j||}| dtj|j	j
 d S )
Nrr  r  r  r   r)  T)ru   track_timesr   F)r   r   r,   rX   r   rU  r~   h5gget_objinfo_idmtimer
  r@   )r   rr  r  r  r   origsimilarr   r   r   test_track_timesJ  s    zTestCreateLike.test_track_timesc                 C   sJ   | j jtddddd}| j td|}| |jd | |jd dS )	z) Test when other.maxshape != other.shape rr  r   r   r3   r  r*   r  r   N)r   r,   r   r
  r@   rA   r  )r   otherr  r   r   r   test_maxshape\  s   zTestCreateLike.test_maxshapeN)r   r    r!   r  r  r  r   r   r   r   r  ?  s    
r  c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestChunkIteratorc                 C   sL   | j jt ddd}| t |  W d    d S 1 sw   Y  d S )Nr   r3   r)   )r   r,   r   r[   r\   iter_chunksrB   r   r   r   r  e  s   
"z TestChunkIterator.test_no_chunksc                 C   sZ   | j jt dddd}| t |tdddf W d    d S 1 s&w   Y  d S )Nr       r3   r     C   r   )r   r,   r   r[   r   r  slicerB   r   r   r   test_rank_mismatchj  s   "z$TestChunkIterator.test_rank_mismatchc                 C   s"  | j jt 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| tdddftdddff}| t|tjd d t| td	ddff}| t|tjd	 t| d S )Nr   r  r3   r  r*   r   r  r	   r  `   r   r   a   	r   r,   r   r   r@   listr  rX   r   r   rC   r   r   r   r   test_1do  s   $($$$zTestChunkIterator.test_1dc                 C   s  | j jt 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| 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jd ddd f t| td
ddtdddftd
ddtdddff}| t|tjd
ddf t| d S )Nr   r   )r  r  r3   r"  r   r  r	   r  r   r#  0   4   r'  r   r$  r  r  r%  r'  r   r   r   test_2d{  s.   
,,,zTestChunkIterator.test_2dc                 C   s   | j jt 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f}tdd}| t|||ft| d S )	Nr	  r   r   r3   r"  r   r'   r	   rm   )r   r,   r   r   r@   r&  r  )r   rC   r   selr   r   r   test_2d_partial_slice  s   
"z'TestChunkIterator.test_2d_partial_sliceN)r   r    r!   r  r!  r(  r,  r/  r   r   r   r   r  d  s    r  c                   @   r   )
TestResizezF
        Feature: Datasets created with "maxshape" may be resized
    c                 C   s6   | j jt dddd}| |jd | |jd dS )z  Create dataset with "maxshape" rw  r   rS   r3   r  Nr   r,   r   assertIsNotr  r@   r  rB   r   r   r   r     r~  zTestResize.test_createc                 C   s6   | j jt dddd}| |jd | |jd dS )zF Create dataset with "maxshape" using tuple shape and integer maxshaper  r   r3   r  Nr2  rB   r   r   r   %test_create_1D_integer_maxshape_tuple  r~  z0TestResize.test_create_1D_integer_maxshape_tuplec                 C   s(   | j jt dddd}| |jd dS )zH Create dataset with "maxshape" using integer shape and integer maxshaper   r3   r  r  N)r   r,   r   r@   r  rB   r   r   r   'test_create_1D_integer_maxshape_integer  r  z2TestResize.test_create_1D_integer_maxshape_integerc                 C   sX   | j jt dddd}| |jd |d | |jd |d | |jd dS )z( Datasets may be resized up to maxshape rw  r1  r3   r  r   r   Nr   r,   r   r@   rA   rc  rB   r   r   r   test_resize  s   

zTestResize.test_resizec                 C   s@   | j jt dddd}| |jd |d | |jd dS )z> Datasets may be resized up to maxshape using integer maxshaper   r'  r3   r  r  )r   Nr7  rB   r   r   r   test_resize_1D  s   
zTestResize.test_resize_1Dc                 C   sP   | j jt dddd}| t |d W d   dS 1 s!w   Y  dS )z. Resizing past maxshape triggers an exception rw  r1  r3   r  )r   r   N)r   r,   r   r[   	Exceptionrc  rB   r   r   r   test_resize_over  s   "zTestResize.test_resize_overc                 C   sN   | j jt ddd}| t |d W d   dS 1 s w   Y  dS )z/ Resizing non-chunked dataset raises TypeError rw  r3   r)   r1  N)r   r,   r   r[   r\   rc  rB   r   r   r   test_resize_nonchunked  s   "z!TestResize.test_resize_nonchunkedc                 C   s6   | j jt dddd}|jddd | |jd d	S )
z Resize specified axis rw  r1  r3   r  r   r	   axisr6  N)r   r,   r   rc  r@   rA   rB   r   r   r   test_resize_axis  r~  zTestResize.test_resize_axisc                 C   sT   | j jt dddd}| t |jddd W d   dS 1 s#w   Y  dS )	z  Illegal axis raises ValueError rw  r1  r3   r  r   r   r=  N)r   r,   r   r[   r   rc  rB   r   r   r   test_axis_exc  s   "zTestResize.test_axis_excc                 C   s6   | j jt dddd}| |jd | |jd dS )z? Allow zero-length initial dims for unlimited axes (issue 111) )   r   )rA  Nr3   r  N)r   r,   r   r@   rA   r  rB   r   r   r   test_zero_dim  r~  zTestResize.test_zero_dimN)r   r    r!   r7   r   r4  r5  r8  r9  r;  r<  r?  r@  rB  r   r   r   r   r0    s    	r0  c                   @       e Zd ZdZdd Zdd ZdS )	TestDtypezD
        Feature: Dataset dtype is available as .dtype property
    c                 C   s*   | j t dd}| |jtd dS )z Retrieve dtype from dataset rl   |S10NrW   rB   r   r   r   
test_dtype  s   zTestDtype.test_dtypec                 C   s>   t dt jfdt jfg}| jt d|}| |j| dS )z7 Retrieve dtype from complex float16 dataset (gh-2156) r  rA  rl   N)rX   r*   float16r   r,   r   r@   )r   	complex32rC   r   r   r   test_dtype_complex32  s   zTestDtype.test_dtype_complex32N)r   r    r!   r7   rF  rI  r   r   r   r   rD        rD  c                   @   rC  )TestLenzG
        Feature: Size of first axis is available via Python's len
    c                 C   s(   | j jt ddd}| t|d dS )z Python len() (under 32 bits) )8  rA  r3   r)   rL  N)r   r,   r   r@   r!  rB   r   r   r   test_len  s   zTestLen.test_lenc                 C   s   | j jt ddd}| |jd tjdkr0| t t	| W d   n1 s*w   Y  n| t	|d | |	 d dS )z Python len() vs Dataset.len() )        rA  r3   r)   iNrN  )
r   r,   r   r@   rA   r8   maxsizer[   OverflowErrorr!  rB   r   r   r   test_len_big  s   

zTestLen.test_len_bigN)r   r    r!   r7   rM  rQ  r   r   r   r   rK    rJ  rK  c                   @   rC  )TestIterz;
        Feature: Iterating over a dataset yields rows
    c                 C   s^   t jdddd}| jjt |d}t||ddD ]\}}| t|d | 	|| qd	S )
z& Iterating over a dataset yields rows r   r   r)   r   rt   T)strictr   N)
rX   r   r   r   r,   r   zipr@   r!  r   )r   ru   rC   rr  r  r   r   r   	test_iter  s   zTestIter.test_iterc                 C   sR   | j jt ddd}| t dd |D  W d   dS 1 s"w   Y  dS )z0 Iterating over scalar dataset raises TypeError r   r3   r|   c                 S   s   g | ]}|qS r   r   r  r   r   r   
<listcomp>$  s    z-TestIter.test_iter_scalar.<locals>.<listcomp>N)r   r,   r   r[   r\   rB   r   r   r   test_iter_scalar   s   "zTestIter.test_iter_scalarN)r   r    r!   r7   rU  rW  r   r   r   r   rR    s    rR  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 d! Zd"d# Zd$S )%TestStringszr
        Feature: Datasets created with vlen and fixed datatypes correctly
        translate to and from HDF5
    c                 C   sp   t jdd}| jjt 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 rk  rl  r   r)   N)r~   string_dtyper   r,   r   r   r   r@   rp  r   r   r   r   check_string_dtyper*   ri  r   r=  r1   r   string_infor   r   r   r   .  s   
zTestStrings.test_vlen_bytesc                 C   s`   t jdd}d}| jjt d||d}| |d | | | d |  | |j| dS )& Vlen bytes dataset handles fillvalue rk  rl     barr   r   r   N	r~   rY  r   r,   r   r@   asstrr  r   r   r=  
fill_valuer1   r   r   r   test_vlen_bytes_fillvalue8  s   z%TestStrings.test_vlen_bytes_fillvaluec                 C   sl   t  }| jjt 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)   rg   N)r~   rY  r   r,   r   r   r   r@   rp  r   r   r   r   rZ  r*   ri  r[  r   r   r   r  A  s   
zTestStrings.test_vlen_unicodec                 C   sd   t  }d}| jjt d||d}| |d |d | | d | | |j|d dS )( Vlen unicode dataset handles fillvalue    bárr   r   r   rg   N)	r~   rY  r   r,   r   r@   ri   r`  r   ra  r   r   r   test_vlen_unicode_fillvalueK  s   z'TestStrings.test_vlen_unicode_fillvaluec                 C   s   t d}| jjt 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
        rE  r   r)   rR   rk  N)rX   r*   r   r,   r   r   r   r@   rp  r~   r   r   assertFalser   r   r   r   rZ  ri  r   r[  r   r   r   test_fixed_asciiT  s   

zTestStrings.test_fixed_asciic                 C   sb   t jddd}d}| jjt d||d}| |d | | | d |  | |j| dS )	r]  rk  rR   rh  r^  r   r   r   Nr_  ra  r   r   r   test_fixed_bytes_fillvalueb  s   z&TestStrings.test_fixed_bytes_fillvaluec                 C   s  t jddd}| jjt 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 spw   Y  tj|d d tj|dgd dd d S )Nrg   rm   rh  r   r)      cùr   r	   r   r'   rQ      UrR   S)r~   rY  r   r,   r   r   r   r@   r   r   r   ri   rX   r   r   r[   r\   r   r   )r   r=  r1   r   sr   r   r   test_fixed_utf8k  s   
"0zTestStrings.test_fixed_utf8c                 C   sj   t jddd}dd}| jjt d||d}| |d | | | d |d | |j	| dS )	rd  rg   rR   rh  re  r   r   r   N)
r~   rY  ri   r   r,   r   r@   r`  r  r   ra  r   r   r   test_fixed_utf_8_fillvalue{  s   
z&TestStrings.test_fixed_utf_8_fillvaluec                 C   sN   t d}| t | jjt d|d}W d   dS 1 s w   Y  dS )zA Fixed-length unicode datasets are unsupported (raise TypeError) z|U10r   r)   N)rX   r*   r[   r\   r   r,   r   r   r=  r1   r   r   r   test_fixed_unicode  s   
"zTestStrings.test_fixed_unicodec                 C   sT   t jdd}| jjt d|d}d}||d< |d }| t|t | || dS )zN writing and reading to vlen bytes dataset preserves type and content
        rk  rl  r   r)      Hellor   N)r~   rY  r   r,   r   r@   rp  bytesr   r=  r1   ru   outr   r   r   test_roundtrip_vlen_bytes  s   z%TestStrings.test_roundtrip_vlen_bytesc                 C   sT   t d}| jjt d|d}d}||d< |d }| t|t j | || dS )z[ Writing to and reading from fixed-length bytes dataset preserves
        type and content rE  r   r)   rs  r   N)rX   r*   r   r,   r   r@   rp  r  ru  r   r   r   test_roundtrip_fixed_bytes  s   
z&TestStrings.test_roundtrip_fixed_bytesc                 C   s`   t  }| jjt d|d}d}||d< | |d t | d }| |t | 	|| d S )Nr   r)      fàilter   )
r~   rY  r   r,   r   r}   rt  r`  r  r@   ru  r   r   r   test_retrieve_vlen_unicode  s   z&TestStrings.test_retrieve_vlen_unicodec                 C   s   | j jt dt d}d}||d< |d}| t |d  W d    n1 s+w   Y  | |ddd d | 	|dd | | d	t
|  tj| d d
 tj|gtd tjt| d d
 tj|gtd d S )Nr   r)   ry  r   rk  ignorefiltelatin-1rR   r	   )r   r,   r   r~   rY  r`  r[   UnicodeDecodeErrorr@   rU  r!  rX   r   r   r   r   asarray)r   r1   ru   strwrap1r   r   r   
test_asstr  s    

"zTestStrings.test_asstrc                 C   s   t jdd}| jjt 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 )Nrm   r   r   r)   rj  rg   r   rk  r{  r   r}  r	   )r~   rY  r   r,   r   rX   r   ri   r}   r  r`  r  r@   rU  r   r   r   ru  r   r   r   test_asstr_fixed  s   zTestStrings.test_asstr_fixedc                 C   sZ   t d}| jjt d|d}d}| t ||d< W d   dS 1 s&w   Y  dS )zGEncoding error when writing a non-ASCII string to an ASCII vlen datasetrk  r   r)   ry  r   N)r~   rY  r   r,   r   r[   UnicodeEncodeError)r   r=  r1   ru   r   r   r   test_unicode_write_error  s   

"z$TestStrings.test_unicode_write_errorc                 C   s^   t  }| jjt 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)   r  r  utf8r   N)
r~   rY  r   r,   r   r  ri   r@   rp  rt  ru  r   r   r   test_unicode_write_bytes  s   z$TestStrings.test_unicode_write_bytesc                 C   sX   t d}| jjt d|d}d}||d< |d }| t|t | ||d dS )z: Writing an ascii str to ascii vlen dataset is OK
        rk  r   r)   zASCII stringr   N)	r~   rY  r   r,   r   r@   rp  rt  ri   ru  r   r   r   test_vlen_bytes_write_ascii_str  s   
z+TestStrings.test_vlen_bytes_write_ascii_strN)r   r    r!   r7   r   rc  r  rf  rh  ri  ro  rp  rr  rw  rx  rz  r  r  r  r  r  r   r   r   r   rX  '  s&    
	
			
rX  c                   @   s0   e Zd ZdZd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
 ||< q+t }|| j	|< | j	| d }| 
t ||k | |j|j dS )z: Compound types are read back in correct order (issue 236)weightcputimewalltimeparents_offset	n_parentsstatusendpoint_typer  r)   r   .N)rX   r*   r  uint32uint8r8  fieldsr  r   r   r   r*  r@   )r   r=  r  keyr0   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 ||< qt }| j	j
|d|d}|jD ]}|| ||< q9| j	| d }| t ||k | |j|j d S )	Nr  r   r  r  r)   rN   r   .)rX   r*   r  r  r8  r  r  rA   r   r   r,   r   r*  r@   )r   r=  r  r  r0   r1   r  r   r   r   test_assign  s   

zTestCompound.test_assignc                 C   s0  t dt jfdt jfdt jfg}t jd|d}|jD ]}t jdd ||< qt }|| j|< | j| }t j	|ddgd d  |ddg  t j	|dd d  |d  t j	t 
|ddg|ddg  t dt jfg}t j	t j
|dg|d|dg | t|ddksJ d S )Nrr  r  r  r  r)   r   r  )rX   r*   r  r8  r  r  r   r   r   r   r  r(   astyper!  )r   r=  r  r  r0   r1   dt_intr   r   r   test_fields'  s4   


zTestCompound.test_fieldsc                 C   s   t dtt jfdtt jfg}t dt|fdt jfg}t jtddt jdt jtdd	t jdf}t jtd
dt jdt jtddt jdf}t jt j||g|ddft j|g|ddfg|d}t }|| j	|< | j	| }| j
||dd d S )Nr   r   f1f2r	   r   r)   rQ   r   rR   r  r     r   F)check_alignment)rX   r*   r~   
vlen_dtyper(   r   r   r  r   r   r   )r   dt_innerr=  inner1inner2ru   r0   rv  r   r   r   test_nested_compound_vlenL  s*   

z&TestCompound.test_nested_compound_vlenN)r   r    r!   r7   r  r  r  r  r   r   r   r   r    s    %r  c                   @   r   )TestSubarrayc                 C   sn   | j jt 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 NrF   3int8r)   r	   r   r   r   )r'   rm   rQ   )r   r,   r   rX   r   r   r4   r   r   r   test_write_listg  s
    zTestSubarray.test_write_listc                 C   sz   | j jt 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,   r   rX   r   r   r   r4   r   r   r   test_write_arrayo  s
    zTestSubarray.test_write_arrayN)r   r    r!   r  r  r   r   r   r   r  f  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	   rB  )REDGREENBLUEc                 C   sF   t j| jdd}| jjt d|d}|j}t |}| || j dS )z= Enum datasets can be created and type correctly round-trips rA  basetyper)  r)   N)	r~   
enum_dtypeEDICTr   r,   r   r*   check_enum_dtyper@   )r   r=  r1   dt2dict2r   r   r   r     s
   
zTestEnum.test_createc                 C   sr   t j| jdd}| jjt 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)   rB  )#   %   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   r@   r   rX   r   rq  r   r   r   test_readwrite  s   &zTestEnum.test_readwriteN)r   r    r!   r7   r  r   r  r   r   r   r   r  x  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   sL   | j jt d|d}| |j| tjd|d}||d< | |d | d S )Nr   r)   .)r   r,   r   r@   r*   rX   rw   r   )r   r=  rC   ru   r   r   r   	_exectest  s
   zTestFloats._exectestrG  zNumPy float16 support requiredc                 C   s   |  td dS )z Mini-floats round trip rG  N)r  rX   r*   r   r   r   r   	test_mini  s   zTestFloats.test_minic                 C   s>   t tdr| tjjtd dS | tjjtd dS )z Test mapping for float16 rG  z<f2z<f4N)rq   rX   r@   r   
IEEE_F16LEr*   r   r   r   r   test_mini_mapping  s   
zTestFloats.test_mini_mappingN)r   r    r!   r7   r  r
   
skipUnlessrq   rX   r  r  r   r   r   r   r    s    
r  c                   @   rC  )TestTrackTimesz"
        Feature: track_times
    c                 C   s6   | j jt 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&   Fr3   r  r*   r   N)	r   r,   r   r~   r  r  r  r  r@   )r   r1   ds_mtimer   r   r   test_disable_track_times  s   z'TestTrackTimes.test_disable_track_timesc                 C   r  )z3 check that when give track_times an invalid value r&   nullr3   r  NrZ   r   r   r   r   test_invalid_track_times  r  z'TestTrackTimes.test_invalid_track_timesN)r   r    r!   r7   r  r  r   r   r   r   r    s    r  c                   @   rC  )TestZeroShapez7
        Features of datasets with (0,)-shape axes
    c                 C   s   | j jtddddd}| |jt|j | j jtddddd}| |jt|j | j jtd	d
ddd}| |jt|j dS )z1 Empty datasets can be converted to NumPy arrays rr  r   Nr3   r  r  r   r   r  r   )NN)r   r,   r   r@   rA   rX   r   r4   r   r   r   test_array_conversion  s   z#TestZeroShape.test_array_conversionc                 C   s   ddg}| j jt 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   rA  r  r   r/  r)   .r   N)r   r,   r   rX   emptyr@   rA   r*   )r   r=  r1   r   r   r   r   test_reading  s   zTestZeroShape.test_readingN)r   r    r!   r7   r  r  r   r   r   r   r    s    r  c                   @   r2  )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)  rr  rt   .)	r   r   rX   r   r   ru   r   r,   rC   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  rR   r   rm   N)rX   r   rC   	regionrefr   ru   r   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   )rC   r  rN   )r   r  rv  r   r   r   test_empty_region  s   
z TestRegionRefs.test_empty_regionc                 C   s   | j jt ddd}tjtjj}|  tj|j	dtjj
|}|| ttdks0J |  tj|j	dtjj
|}|| |d ksJJ d S )N      ?r3   ru   r*      .r   )r   r,   r   r~   h5screateSCALARselect_noneh5rr   DATASET_REGIONr   rX   r*   
select_all)r   r1   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  rR   r   rm   )rR      N)rX   r   rC   r  r@   rA   	selectionr  r   r   r   test_ref_shape  s   zTestRegionRefs.test_ref_shapeN)	r   r    r!   r7   r   r  r  r  r  r   r   r   r   r    s    r  c                   @   r  )	
TestAstypez(.astype() wrapper & context manager
    c                 C   sN   | j jt ddd}td|d< |dd d  }| |tjddd d S Nr   r  r)   r   .r3   )r   r,   r   rX   r   r  r   r   rC   r   r   r   r   test_astype_wrapper  s   zTestAstype.test_astype_wrapperc                 C   s<   | j jt ddd}td|d< | dt|d d S r  )r   r,   r   rX   r   r@   r!  r  rB   r   r   r   test_astype_wrapper_len  s   z"TestAstype.test_astype_wrapper_lenc                 C   sP   | j jt ddd}td|d< tj|ddd}| |tjddd d S r  )r   r,   r   rX   r   r  r  r   r  r   r   r   test_astype_wrapper_asarray  s   z&TestAstype.test_astype_wrapper_asarrayN)r   r    r!   r7   r  r  r  r   r   r   r   r  
  s
    r  c                   @   rn  )TestScalarCompoundzl
        Retrieval of a single field from a scalar compound dataset should
        strip the field info
    c                 C   s<   t dg}| jjt d|d}| |d jt d d S )Nr@  r   r)   r   rA  )rX   r*   r   r,   r   r@   )r   r=  rC   r   r   r   test_scalar_compound'  s   z'TestScalarCompound.test_scalar_compoundN)r   r    r!   r7   r  r   r   r   r   r     s    r  c                   @   st   e 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 )TestVlenc                 C   sT  t t}| jjt 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 )
Nr&   r)   r   r   r	   r  r   rm   r'   )r~   r  intr   r,   r   rX   r   r   r   r   rq  r   r   r   r  /  s    
&"zTestVlen.test_intc                 C   s>   t t}| jjtdd|d}| jtdd|d j d S )Nrr  rF   r)   r  r   )r~   r  r  r   r,   r   r*   rq  r   r   r   test_reuse_from_otherA  s   
zTestVlen.test_reuse_from_otherc                 C   s   dt fdtt fg}|  }t|d}|jdd|d W d    n1 s(w   Y  t|d}|dd|d d d j W d    d S 1 sMw   Y  d S )	Nr   r   r   rr  rF   r)   r  r   )r  r~   r  r   r   r,   r*   )r   r=  r  r   r   r   r   test_reuse_struct_from_otherF  s   "z%TestVlen.test_reuse_struct_from_otherc                 C   sB  t t}| jjt 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 )Nr#  r)   gffffff?333333?r   r	   )r  r   r   r   r  )皙?g?g @g@r'   r'   rm   )r  r  皙@)皙?r  r  r   )r~   r  r  r   r,   r   rX   r   r   r   r   rq  r   r   r   test_convertP  s    
$zTestVlen.test_convertc                 C   s   t t}| jjt 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 )Nr-  r)   r	   r   r   r   )
r~   r  r  r   r,   r   rX   r   r   r   rq  r   r   r   test_multidima  s   
zTestVlen.test_multidimc                 C   s\  t |}| jjt 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
  t r| j  dS dS )zp
        Helper for testing various vlen numpy data types.
        :param np_dt: Numpy datatype to test
        rl   r)   )r         @g      >@)g33333Y@gi@gfffffX@g      %g     r)r	   r   rk  r(   )r  r  g      @ra  g      )r   ir   r	   i'  r   r   r	   r   r   r'   g333333?r  N)r~   r  r   r,   r   rX   r   r*   r  r   r  r   r   )r   np_dtr=  r1   array_0array_1array_2casted_array_2list_3list_array_3list_4list_array_4r   r   r   _help_float_testingj  s6   


zTestVlen._help_float_testingc                 C      t d}| | d S )NrG  rX   r*   r  r   r  r   r   r   test_numpy_float16     
zTestVlen.test_numpy_float16c                 C   r  )Nfloat32r  r  r   r   r   test_numpy_float32  r  zTestVlen.test_numpy_float32c                 C   r  )Nr  r  r  r   r   r   test_numpy_float64_from_dtype  r  z&TestVlen.test_numpy_float64_from_dtypec                 C   s   t j}| | d S r   )rX   r  r  r  r   r   r   test_numpy_float64_2  s   zTestVlen.test_numpy_float64_2c                 C   s   t  }| jj|dtdd | j| }tg d}|ddd |d< t|d |ddd ksAJ |d  d|ddd  dS )	z4Test that non-contiguous arrays are stored correctlyr   r  r)   )TFTTFFFNr   r    != r   r   r,   r~   r  rX   r   r*  )r   r0   r1   rr  r   r   r   test_non_contiguous_arrays_bool  s   
>z(TestVlen.test_non_contiguous_arrays_boolc                 C   s   t  }| jj|dtdd | j| }tg d}|d d d |d< t|d |d d d ksAJ |d  d|d d d  d S )Nr   int8r)   )r   r'   r	   rm   r   r   r   r   r   r  r  )r   r0   r1   r  r   r   r   test_non_contiguous_arrays_int  s   
>z'TestVlen.test_non_contiguous_arrays_intc                 C   sh   t jdd}d}| jjt d||d}tt tj	|
 td W d    d S 1 s-w   Y  d S )Nrk  rl  r^  r   r   r)   )r~   rY  r   r,   r   r:   r   r   rX   r   r`  r  ra  r   r   r   test_asstr_array_dtype  s   "zTestVlen.test_asstr_array_dtypeN)r   r    r!   r  r  r  r  r  r  r   r  r  r  r  r
  r  r   r   r   r   r  .  s    
	0
	r  c                   @   r   )TestLowOpenc                 C   s"   | j jt ddd}|j }dS )z Test H5Dget_access_plist r&   r3   r)   N)r   r,   r   r   r  )r   r1   p_listr   r   r   test_get_access_list  s   z TestLowOpen.test_get_access_listc                 C   sX   t  }tjtjj}| jj|ddd}~tj| jj	|
d|}| |tjj dS )z# Test the dapl keyword to h5d.open r   r3   r)   rg   N)r   r~   h5pr  DATASET_ACCESSr   r,   rH  r  r   ri   r}   	DatasetID)r   r0   daplrC   dsidr   r   r   	test_dapl  s   zTestLowOpen.test_daplN)r   r    r!   r  r  r   r   r   r   r    s    r  c            	   	   C   sh  ddl m}  |  }t }t|d}|j|dddd d|| d d < W d    n1 s.w   Y  |d t|d	l}|| j}| d
ksLJ t	d
D ]0}t
tt|dd }||}|j|kskJ |jdksrJ |jd usyJ |jdksJ qP|d}|jdksJ |jdksJ |jd usJ |jdksJ W d    d S 1 sw   Y  d S )Nr   BytesIOr   r)  r{   r  r  r	   r  r   rR   r   )ior  r   r~   r   r,   seekr   get_num_chunksr  r   rX   r   unravel_indexget_chunk_infochunk_offsetfilter_maskbyte_offsetrN   get_chunk_info_by_coord)	r  bufr0   foutfinr1   joffsetsir   r   r   test_get_chunk_details  s0   



"r&  )r	   r)  r   )r	   rR   rR   )r	   rR   c   zJchunk iteration requires  HDF5 1.10.10 and later 1.10, or 1.12.3 and laterc            	         s   ddl m}  |  }t }t|d}|j|dddd d|| d	d	< W d	   n1 s.w   Y  |d t|d
6}|| j}| }|dksNJ i  t	|D ]}|
|}| |j< qT fdd}|| W d	   d	S 1 sww   Y  d	S )z%H5Dchunk_iter() for chunk informationr   r  r   r)  r{   r  r  r	   Nr  r   c                    sN    | j  }| j |j ksJ | j|jksJ | j|jksJ | j|jks%J d S r   )r  r  r  rN   )
chunk_infoknowncir   r   callback
  s
   
z!test_chunk_iter.<locals>.callback)r  r  r   r~   r   r,   r  r   r  r  r  r  
chunk_iter)	r  r   r0   r   r  
num_chunksr#  r%  r,  r   r*  r   test_chunk_iter  s&   


"r/  c                 C   s0   | j t dd}|jd u sJ |jd u sJ d S )Nr(   r)   )r,   r   rA   r  )r   r1   r   r   r   test_empty_shape  s   r0  c                  C   s   ddl m}  |  }t|d}|jddd W d    n1 s!w   Y  |d t|d(}|d jd u s;J |d j d u sFJ |d j	 dksQJ W d    d S 1 s\w   Y  d S )Nr   r  r   r  r  r)   r  )
r  r  r~   r   r,   r  r  r   
get_offsetget_storage_size)r  r   r!  r"  r   r   r   test_zero_storage_size  s   
"r3  c                 C   s   t t jjt t jjd g}| jt |t jd}|jt t jks%J 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)   )rX   iinfor   maxr,   r   uint64r*   r   r   r   )r   ru   r1   r   r   r   test_python_int_uint64(  s    "&r7  c                 C   s>   | j t dtjd}tjjddd}||d d g ddf< d S )N)rm   r  r   r)      )rm   r   r   r  )r   r   r'   .)r,   r   rX   r  r  r  )r   r   blockr   r   r   test_setitem_fancy_indexing6  s   r:  c                  C   F   t td} | d d dksJ W d    d S 1 sw   Y  d S )Nzvlen_string_dset.h5DS1r   s   Partingr   r   r   r   r   r   test_vlen_spacepad=     "r?  c                  C   r;  )Nzvlen_string_dset_utc.h5ds1r   s   2009-12-20T10:16:18.662409Zr=  r>  r   r   r   test_vlen_nulltermB  r@  rB  c                 C   s@   d}| j t dtj|dd}t||jv sJ |jdksJ d S )N   r{   T)rA   r*   rO  allow_unknown_filterunknown)r,   r   rX   r  r  _filtersrO  )r   fake_filter_idr1   r   r   r   test_allow_unknown_filterG  s   rH  c               
   C   s  ddl m}  |  }t }t|d0}|j|dddddd	d
}|j  }|j 	 dd |ks5J |dks;J W d   n1 sEw   Y  |
d t|d0}|j|dddddd}|j  }|j 	 dd |kswJ |dks}J W d   dS 1 sw   Y  dS )z2Chunk cache configuration for individual datasets.r   r  r   )rR   r   )rm   r'   r      r    )rA   r  r*   rdcc_nbytesrdcc_w0rdcc_nslotsr	   N)rJ  rI  r  r    0 q=
ףp?  )rA   r*   rK  rL  rM  )rP  rN  rO  )r  r  r   r~   r   r,   r   r  get_chunk_cache	get_cacher  r   )r  r   r0   r!  r1   ds_chunk_cacher"  r   r   r   test_dset_chunk_cacheR  s,   
"rT  c                   @   rC  )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t |ttjj| d}t|d }t||k||kks%J t||k||kks2J d}t	|| }t||k||kksHJ t||k||kksUJ dS )z
        Create a h5py dataset, extract one element convert to numpy
        Check that it returns symmetric response to == and !=
        r   r	   r*   ru   r   gMbP?N)
r   r,   r   r  rX   r  r  r  r*  nanmax)r   rA   rC   valdeltanvalr   r   r   test_numpy_commutativeo  s   
z&TestCommutative.test_numpy_commutativec                 C   sV   d}| j jt |ttjj| d}td}||k||kksJ ||k||kks)J dS )z
        Create a h5py dataset and check basetype compatibility.
        Check that operation is symmetric, even if it is potentially
        not meaningful.
        rV  rW  ra  N)r   r,   r   r  rX   r  r  )r   rA   rC   rY  r   r   r   test_basetype_commutative  s   
z)TestCommutative.test_basetype_commutativeN)r   r    r!   r7   r\  r]  r   r   r   r   rU  j  s    rU  c                   @   rC  )TestVirtualPrefixz%
    Test setting virtual prefix
    c                 C   sT   d}d}| j jt |ttjj| |d}t|j	
    }||ks(J d S )NrV  /path/to/virtual)r*   ru   virtual_prefix)r   r,   r   r  rX   r  r  r  r  r   r  get_virtual_prefixr  r  )r   rA   r`  rC   virtual_prefix_readbackr   r   r   test_virtual_prefix_create  s   
z,TestVirtualPrefix.test_virtual_prefix_createc                 C   s`   d}| j jt dd|d}t|j   	 }| 
|| | |t | 
|jd d S )Nr_  r   r   )r`  )r   r   r   r  r  r   r  ra  r  r  r@   r}   r   rA   )r   r`  rC   rb  r   r   r   test_virtual_prefix_require  s   z-TestVirtualPrefix.test_virtual_prefix_requireN)r   r    r!   r7   rc  rd  r   r   r   r   r^    s    
r^  r   c                 C   s$   t jdd}d}| jt |||dS )Nrk  rl  s   fillr   )r~   rY  r,   r   )filerA   r=  rb  r   r   r   ds_str  s   rf  c                 C   sL   t dtjddfdt jfg}t jd|d}t }t ||| |< | | S )Nrf   rk  rl  bar)fillra  r)   )rX   r*   r~   rY  r  r  r   broadcast_to)re  rA   r=  rb  r0   r   r   r   	ds_fields  s   rj  zview_getter,make_dsc                 C   s   | S r   r   r1   r   r   r   <lambda>  s    rl  c                 C   s   | j tdS )Nr)   )r  r   rk  r   r   r   rl    s    c                 C   s   |   S r   )r`  rk  r   r   r   rl    s    c                 C   s
   |  dS )Nrf   )r  rk  r   r   r   rl    s   
 )r1   r  r`  r  )ids)r   r   Fr   Tc                 C   s"   ||}| |}t j||d d S )Nr   )rX   r   )view_gettermake_dsr   r   r1   viewr   r   r   test_array_copy  s   rr  z"forbidding copies requires numpy 2r  c                 C   sR   ||}| |}t jtdd tj|dd W d    d S 1 s"w   Y  d S )Nz#memory allocation cannot be avoidedr,  Frn  )r:   r   r   rX   r   ro  rp  r   r1   rq  r   r   r   test_array_copy_false  s
   "rt  c                 C   s2   ||}| |}t j|ddjt dksJ d S )NrE  r)   )rX   r   r*   rs  r   r   r   test_array_dtype  s   "ru  c                 C   sB   ||dd}| |}t |d ttfsJ t|jdksJ d S )Nr   rA   )r   rt  r  rX   r   rA   rs  r   r   r   test_array_scalar  s   rw  c                 C   s,   ||dd}| |}t |jdksJ d S )Nrm   rQ   rv  )rX   r   rA   rs  r   r   r   test_array_nd  s   ry  c                 C   sf   ||dd}| |}|j t tksJ |jdksJ |jdks"J |jdks)J t|dks1J d S )Nrx  rv  r   r   rm   )r*   rX   r   ndimrA   rN   r!  rs  r   r   r   test_view_properties  s   r{  zspawns thread pool itselfc                    s   d}d t | fddt|dfddt|D }W d    n1 s-w   Y  dd |D  t fd	d
t|D }t|ksNJ d S )Nr   rm   c                    s:      t D ]}jd| dd|dddd qd S )Nconcurrent_02d_)r  r  r)   )waitr  r,   )ithreadr#  )N_DATASETS_PER_THREADbarrierr   r   r   closure
	  s   "z1test_concurrent_dataset_creation.<locals>.closure)max_workersc                    s   g | ]}  |qS r   )submit)r  r  )r  executorr   r   rV  	  s    z4test_concurrent_dataset_creation.<locals>.<listcomp>c                 S   s   g | ]}|  qS r   )result)r  r   r   r   r   rV  	  s    c                 3   s2    | ]}t  D ]}d |dd|dV  qqdS )r|  r}  r~  N)r  )r  rA  r#  )r  r   r   r  	  s   0 z3test_concurrent_dataset_creation.<locals>.<genexpr>)	threadingBarrierr   r  set)r   	N_THREADSfuturesr   r   )r  r  r  r  r   r    test_concurrent_dataset_creation	  s   
r  c                 C   sP   t  }| j|dtjdddd}|jtjjtjjtjj	fksJ |j
dks&J d S )Nr  Tr  )rA   r*   r  r  rO  )r  r  r  )r   r,   rX   r  
filter_idsr~   r  FILTER_SHUFFLE
FILTER_LZFFILTER_FLETCHER32filter_names)r   r0   r1   r   r   r   test_filter_properties	  s   
r  c                 C   s   | j tdtdd}| j td| j|jgd}t|d tjs#J | |d  | ks-J t|d tjs7J | |d  |ksAJ | j td|jd}t|d tjjsVJ | |d  |ks`J d S )	Nrf   r)  rt   refsr   r	   
ref_scalarr   )	r,   r   rX   r   r  r   r~   	Referencer  )r   rA  refs_dsref_scalar_dsr   r   r   test_store_refs$	  s   r  c                 C   s   | j tdtdd}| j td|jd d |jdd  gd}t|d tjs+J tj	||d  td tj	||d  tdd | j td	d
tj
d}tjtdd |jd d |d< W d    d S 1 sow   Y  d S )Nrf   r)  rt   regrefsr   r	   r   r(  r  rF   r|   convertr,  rQ   )r,   r   rX   r   r  r   r~   RegionReferencer   r   	ref_dtyper:   r   r\   )r   rA  regionrefs_dsr  r   r   r   test_store_regionrefs2	  s   
"r  )r   )or7   r  r  r8   numpyrX   r`   r:   r  concurrent.futuresr   r~   r   r   h5py._hl.baser   r   r   r   commonr
   r   r   r   r   
data_filesr   h5py_warningsr   r   r"   r=   rr   r   r   r   r  r3  rD  r;   r   r  r(   r   r  r  r  rY  rm  ro  rp   rg  ri   rv  r  r  r  r  r  r  r  r  r  r  r0  rD  rK  rR  rX  r  r  r  r  r  r  r  r  r  r  r  r&  r  versionhdf5_version_tupler/  r0  r3  r7  r:  r?  rB  rH  rT  rU  r^  rf  rj  view_gettersCOPY_IF_NEEDEDrr  skipifrt  ru  rw  ry  r{  r<   r  r  r  r  r   r   r   r   <module>   s   			M\<(TD&T

/( sm5%>F Tl. 
-











