o
    2hC                    @   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 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 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( Z-G d)d* d*eZ.e/d+ej0j1vd,G d-d. d.eZ2e/d+ej0j1vd,G d/d0 d0eZ3e/d1ej0j1vd2G d3d4 d4eZ4e/d5ej0j1vd6G d7d8 d8eZ5e/d9ej0j1vd:G d;d< d<eZ6e/d=ej0j1vd>G d?d@ d@eZ7e/dAej0j1vdBG dCdD dDeZ8G dEdF dFeZ9G dGdH dHeZ:G dIdJ dJeZ;G dKdL dLeZ<G dMdN dNeZ=G dOdP dPeZ>G dQdR dReZ?G dSdT dTeZ@G dUdV dVeZAG dWdX dXeZBG dYdZ dZeZCG d[d\ d\eZDG d]d^ d^eZEG d_d` d`eZFG dadb dbeZGG dcdd ddeZHG dedf dfeZIG dgdh dheZJG didj djeZKG dkdl dleZLdmdn ZMeNejOjPdokp%ejOjPdpko%ejOjPdqk drdsdt ZQdudv ZRdwdx ZSdydz ZTd{d| ZUd}d~ ZVdd ZWdd ZXdd ZYG dd deZZG 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Z^edk rdndZ_ej$%dde_ge^dd Z`ej$jaedk dde^dd Zbe^dd Zce^dd Zde^dd Zee^dd Zfdd Zgd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   )utTestCase)get_data_file_path)FileDataset)is_empty_dataspaceproduct)h5fh5t)NUMPY_RELEASE_VERSIONc                   @      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   R/var/www/html/chatgem/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                   @   s:   e Zd ZdZejdkrdndZdd Zdd Zd	d
 Z	dS )TestReprz5
        Feature: repr(Dataset) behaves sensibly
    big><c                 C   s0   | j jdddd}t|d| j dksJ d S )Nfoo   int32dtypez'<HDF5 dataset "foo": shape (4,), type "i4">r   create_datasetreprendian_markr   dsr   r   r   test_repr_basic3      zTestRepr.test_repr_basicc                 C   s,   | j dd}| j   t|dksJ dS )z( repr() works on live and dead datasets r"   r#   z<Closed HDF5 dataset>N)r   r*   r   r+   r-   r   r   r   test_repr_closed7   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   r   test_repr_anonymous=   r0   zTestRepr.test_repr_anonymousN)
r   r   r   __doc__sys	byteorderr,   r/   r1   r2   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       | 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_scalarH      z"TestCreateShape.test_create_scalarc                 C   r7   )z Create a size-1 dataset r"   r   Nr8   r;   r   r   r   test_create_simpleM   r>   z"TestCreateShape.test_create_simplec                 C       | j dd}| |jd dS )z+ Create a size-1 dataset with integer shaper"   r   r?   Nr8   r;   r   r   r   test_create_integerR   r>   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"   ?   rE   bar   
   <   Nr   r*   r9   r:   sizer;   r   r   r   test_create_extendedW      z$TestCreateShape.test_create_extendedc                 C   sX   | j dd}| |jd | |jd | j dd}| |jd | |jd dS )rC   r"   rE   rD   rF   rG   rJ   NrK   r;   r   r   r   test_create_integer_extended`   rN   z,TestCreateShape.test_create_integer_extendedc                 C   s&   | j dd}| |jtd dS )) Confirm that the default dtype is float r"   rD   z=f4Nr   r*   r9   r'   npr;   r   r   r   test_default_dtypei   s   z"TestCreateShape.test_default_dtypec                 C   s<   |  t | jd W d   dS 1 sw   Y  dS )z  Missing shape raises TypeError r"   NassertRaises	TypeErrorr   r*   r   r   r   r   test_missing_shapen   s   "z"TestCreateShape.test_missing_shapec                 C   sF   | j jddtjd}t dv rtdt   | |j	tj dS )rP   r"   rD   r&   )ppc64lez(Storage of long double deactivated on %sN)
r   r*   rR   
longdoubleplatformmachinepytestxfailr9   r'   r;   r   r   r   test_long_doubles   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 )rP   r"   rD   r_   r&   N)r   r*   rR   r'   r9   r;   r   r   r   test_complex256z   s   
zTestCreateShape.test_complex256c                 C   s<   | j dd}| |jd | j dd}| |jd d S )Ns   foor?   s   bar/baz   r8   r   r<   dset2r   r   r   test_name_bytes   s   zTestCreateShape.test_name_bytesN)r   r   r   r3   r=   r@   rB   rM   rO   rS   rW   r^   r   skipIfhasattrrR   r`   re   r   r   r   r   r6   B   s    		
r6   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   0   t dd}| jjd|d}| |j|j dS )z- Create a scalar dataset from existing array r   r   r"   dataNrR   onesr   r*   r9   r:   r   rk   r<   r   r   r   r=         z!TestCreateData.test_create_scalarc                 C   ri   )z/ Create an extended dataset from existing data rD   r   r"   rj   Nrl   rn   r   r   r   rM      ro   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rI   rI   z<i4)r:   r'   N)r   r*   assertIsInstanceh5pyr   
assertTruer-   r   r   r   test_dataset_intermediate_group      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   r&   r"   rI      r:   rk   .N)rR   aranger   r*   r9   r:   assertArrayEqualreshapern   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)rU   
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   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                        j | tjd d d S Nr   )r   r   
CSET_ASCIIr<   r   r   r   check_vlen_ascii      z?TestCreateData.test_create_bytestring.<locals>.check_vlen_asciia   abcrj   b   defcdr&   Nr   r*   rR   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   S3r&   rj   rx   r   )r   r*   rR   r   r   r   r   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                    r   r   )r   r   	CSET_UTF8r   r   r   r   check_vlen_utf8   r   z;TestCreateData.test_create_strings.<locals>.check_vlen_utf8r   abcrj   r   defr   r   r&   r   )r   r   r   r   r   test_create_strings   s   z"TestCreateData.test_create_stringsc                 C   sN   |  t | jjdtjddgddd W d    d S 1 s w   Y  d S )Nr   r   r   U3r&   rj   )rU   rV   r   r*   rR   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   r&   )r   r*   rs   r	   r   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   r&   rj   )r   r*   rr   Emptyrs   r	   r   r   r   r   r   !test_empty_create_via_Empty_class   s   z0TestCreateData.test_empty_create_via_Empty_classc                 C   sH   |  t | jjddtdd W d    d S 1 sw   Y  d S )NrF   r$   rx   ry   )rU   r   r   r*   rR   rz   r   r   r   r   test_create_incompatible_data   s   "z,TestCreateData.test_create_incompatible_dataN)r   r   r   r3   r=   rM   rt   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   rh      s    

rh   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   rI   2   rJ   F   Z   Nrv   rI      r   r         	   rH   rb   rH   rx   c           
      C   sl   t jt|dd|}|jd||d}t j|ddd}| }	|| |	|< |||| t j	||	 d S )Nint64r&   r<   rj   )
rR   rz   r
   r|   r*   fullcopyread_directtestingassert_array_equal)
r   writable_filesource_shape
dest_shape
source_seldest_sel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<   rI   rI   r   r&   rj   )r*   rR   rz   rm   r   r   r   r   r   r<   r   r   r   r   test_no_sel   s   
zTestReadDirectly.test_no_selc                 C   sl   |j ddd}tdd}tt ||tjdd tjdd  W d    d S 1 s/w   Y  d S 	Nedsetr   r&   r   r   rI   r   rJ   )r*   rR   rm   r\   raisesrV   r   s_)r   r   
empty_dsetr   r   r   r   
test_empty   s
   $"zTestReadDirectly.test_emptyc                 C   T   |j dddd}td}tt || W d    d S 1 s#w   Y  d S Nr<   r   r   r&      r*   rR   rm   r\   r   rV   r   r   r   r   r   test_wrong_shape  
   
"z!TestReadDirectly.test_wrong_shapec                 C   X   |j dddd}tjddd}tt || W d    d S 1 s%w   Y  d S Nr<   rp   r   r&   F)orderr   r   r   r   r   test_not_c_contiguous  
   "z&TestReadDirectly.test_not_c_contiguousc                 C   sz   d}|j d|tjd}tj|tjd}|| tjdtjd}tt || W d    d S 1 s6w   Y  d S )N)r   r   r<   r&   )r      )r*   rR   r   zerosr   r\   r   rV   )r   r   r:   r<   r   arr2r   r   r   test_zero_length  s   
"z!TestReadDirectly.test_zero_length)r   r   r   r3   r\   markparametrizerR   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   rI   r   rJ   r   r   Nr   r   r   r   r   rb   rH   rx   c           	      C   sj   |j d|ddd}tt||}tj|ddd}|| ||< |||| tj|d d  | d S )Nr<   r%   r   r'   	fillvaluer&   )	r*   rR   rz   r
   r|   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   sf   |j d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   rV   r   rR   rm   r   )r   r   r   r   r   r   r   3  s   *"zTestWriteDirectly.test_emptyc                 C   r   r   r*   rR   rm   r\   r   rV   r   r   r   r   r   r   8  r   z"TestWriteDirectly.test_wrong_shapec                 C   r   r   r   r   r   r   r   r   >  r   z'TestWriteDirectly.test_not_c_contiguous)r   r   r   r3   r\   r   r   rR   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"   rw   r   N)r   require_datasetrq   r   r9   r:   r;   r   r   r   test_createK  s   zTestCreateRequire.test_createc                 C   s0   | j ddd}| j ddd}| || dS )z) require_dataset yields existing dataset r"   rw   r   Nr   r   r9   rc   r   r   r   test_create_existingQ  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"   rI   r   rF   r   bazs   bazNr   rc   r   r   r   test_create_1DW  s   z TestCreateRequire.test_create_1Dc                 C   sP   | j ddd | t | j ddd W d   dS 1 s!w   Y  dS )z6 require_dataset with shape conflict yields TypeError r"   rw   r   )rI   r$   Nr   r*   rU   rV   r   r   r   r   r   test_shape_conflicte  s   "z%TestCreateRequire.test_shape_conflictc                 C   sL   | j d | t | j ddd W d   dS 1 sw   Y  dS )z< require_dataset with object type conflict yields TypeError r"   rw   r   N)r   create_grouprU   rV   r   r   r   r   r   test_type_conflictk  s   "z$TestCreateRequire.test_type_conflictc                 C   sP   | j ddd}| t | j ddd W d   dS 1 s!w   Y  dS )zL require_dataset with dtype conflict (strict mode) yields TypeError
        r"   rw   r   S10Nr   r;   r   r   r   test_dtype_conflictq  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"   rw   r   TexactN)r   r*   r   r9   rc   r   r   r   test_dtype_exactx  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"   rw   i4i2Fr   N)r   r*   r   r9   r'   rR   rc   r   r   r   test_dtype_close  s   z"TestCreateRequire.test_dtype_closeN)r   r   r   r3   r   r   r   r   r   r   r   r   r   r   r   r   r   E  s    r   c                   @   X   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*   r9   r  r;   r   r   r   test_create_chunks     z$TestCreateChunked.test_create_chunksc                 C   s$   | j jdddd}| |jd dS )z Create via chunks integer r"   r   rI   r  r   Nr  r;   r   r   r   test_create_chunks_integer  r  z,TestCreateChunked.test_create_chunks_integerc                 C   B   |  t | jjdddd W d   dS 1 sw   Y  dS )z& Illegal chunk size raises ValueError r"   r   r   r  NrU   r   r   r*   r   r   r   r   test_chunks_mismatch     "z&TestCreateChunked.test_chunks_mismatchc                 C   D   |  t | jj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   r   F)r:   maxshaper  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   r   r  NrT   r   r   r   r   test_chunks_scalar  r
  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  rb   N)r   r*   rq   r  tupler9   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"   rx   
S100000000Tr:   r'   r  r?   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"   )rx   r   r   )r   r   r   r  rI   r   N(         r   rb   )r   r*   rR   r%   rs   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 sw   Y  t jtdd}| jjdddd	 W d   dS 1 s<w   Y  dS )
z, Auto-chunking of empty datasets not allowedr   matchr"   S100T)r'   r  Nr   r'   r  )r\   r   rV   r   r*   )r   errr   r   r   test_auto_chunks_no_shape  s   "z+TestCreateChunked.test_auto_chunks_no_shapeN)r   r   r   r3   r  r  r	  r  r  r  r  r  r!  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   s6   | j jdddd}| |d d | |d d dS )z- Fill value is reflected in dataset contents r"   r         @r   r   r   N)r   r*   r9   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*   r9   r   assertNotIsInstancerR   ndarrayr;   r   r   r   test_property  ru   z!TestCreateFillvalue.test_propertyc                 C   rA   )z0 .fillvalue property works correctly if not set r"   r   r   N)r   r*   r9   r   r;   r   r   r   test_property_none  r>   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   i8r?   r&   r   r"   r   r   r$   N)rR   r'   rm   r   r*   r9   r   assertAlmostEqual)r   dtvr<   r   r   r   test_compound  s
   z!TestCreateFillvalue.test_compoundc                 C   sH   |  t | jjddddgdd}W d   dS 1 sw   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   r3   r&  r)  r*  r0  r4  r   r   r   r   r#    s    r#  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   sT   | j jdddd}|j }| | tjj | |d d | |d d dS )z Fill time default to IFSET r"   r   r$  r%  r   r   N	r   r*   r   get_create_plistr9   get_fill_timerr   h5dFILL_TIME_IFSETr   r<   plistr   r   r   test_fill_time_default  s
   
z#TestFillTime.test_fill_time_defaultgzipDEFLATE is not installedc                 C   sV   | j j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"   r   r>  r$  )compressionr   r   r   Nr6  r;  r   r   r   test_compressed_default  s   
z$TestFillTime.test_compressed_defaultc                 C   sV   | j jddddd}|j }| | tjj | 	|d d | 	|d d dS )	z Fill time set to NEVER r"   r   r$  neverr   	fill_timer   r   N)
r   r*   r   r7  r9   r8  rr   r9  FILL_TIME_NEVERassertNotEqualr;  r   r   r   test_fill_time_never	  s   
z!TestFillTime.test_fill_time_neverc                 C   s6   | j jddddd}|j }| | tjj dS )z# Fill time explicitly set to ALLOC r"   r   r$  allocrC  N)	r   r*   r   r7  r9   r8  rr   r9  FILL_TIME_ALLOCr;  r   r   r   test_fill_time_alloc  s
   
z!TestFillTime.test_fill_time_allocc                 C   s8   | j jdddddd}|j }| | tjj dS )z# Fill time explicitly set to IFSET r"   r   ra   r$  ifset)r  r   rD  Nr6  r;  r   r   r   test_fill_time_ifset  s
   
z!TestFillTime.test_fill_time_ifsetc                 C   B   |  t | jjdddd}W d   dS 1 sw   Y  dS )z2 Choice of fill_time is 'alloc', 'never', 'ifset' r"   r   fill_badrD  Nr  r;   r   r   r   test_invalid_fill_time!  r
  z#TestFillTime.test_invalid_fill_timec                 C   rM  )z fill_time must be a string r"   r   rb   rO  Nr  r;   r   r   r   test_non_str_fill_time&  r
  z#TestFillTime.test_non_str_fill_timec                 C   sx   | j j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"   r  r   r   )r  r  N        )r   r*   r   r7  r9   r8  rr   r9  r:  rR   iscloser  resizer;  r   r   r   #test_resize_chunk_fill_time_default+  s   

 z0TestFillTime.test_resize_chunk_fill_time_defaultc                 C   s|   | j j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"   r  r   r$  rB  rR  )r  r   rD  r  N)r   r*   r   r7  r9   r8  rr   r9  rE  rR   rT  anyrU  r;  r   r   r   !test_resize_chunk_fill_time_never7  s   

 z.TestFillTime.test_resize_chunk_fill_time_neverN)r   r   r   r3   r=  r   rf   rr   filtersencoderA  rG  rJ  rL  rP  rQ  rV  rX  r   r   r   r   r5    s    
	
r5  zdt,expectedrS  utf-8r   encodingr       asciir]  c                 C   s"   |j dd| d}|j|ksJ d S )Nr"   r   r&   )r*   r   )r.  r   r   r<   r   r   r   test_get_unset_fill_valueE  s   ra  c                   @      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   r&   N)	rR   r'   r   r*   r9   r   r   rs   	committedr;   r   r   r   
test_named^  s
   zTestCreateNamedType.test_namedN)r   r   r   r3   rh  r   r   r   r   rc  X      rc  r>  r?  c                   @   0   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   rv   r>  r   r@  compression_optsNr   r*   r9   r@  rn  r;   r   r   r   	test_gzipn  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"   rl  r>  r@  r$   Nro  r;   r   r   r   test_gzip_implicitu     z!TestCreateGzip.test_gzip_implicitc                 C   s   | j jdddd}| |jd | |jd tjjj}z4t	 tjj_| 
t | j jdddd}W d   n1 s<w   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 r"   rl  r   rq  r>  N)r   r*   r9   r@  rn  rr   _hldataset_LEGACY_GZIP_COMPRESSION_VALSr  rU   r   )r   r<   original_compression_valsr   r   r   test_gzip_number{  s   
zTestCreateGzip.test_gzip_numberc                 C   s   |  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 s9w   Y  |  t | jjddddd W d   dS 1 sYw   Y  dS )	z= Illegal gzip level (explicit or implicit) raises ValueError r"   rl     rq  Nr>  rm  )rU   r   RuntimeErrorr   r*   r   r   r   r   test_gzip_exc  s   "zTestCreateGzip.test_gzip_excN)r   r   r   r3   rp  rr  rx  r|  r   r   r   r   rk  g  s    rk  c                   @       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}zt t jj_| jjddt jj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 7r"   rl  )r   rm  r>  r   N)rr   rt  ru  rv  r  r   r*   h5zFILTER_DEFLATEr9   r@  rn  )r   rw  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 sw   Y  | dt|j |  t}| jjdddd W d   n1 s@w   Y  | dt|j tjj	j
}z6t tjj	_
|  t | jjddtjjd W d   n1 suw   Y  W |tjj	_
dS W |tjj	_
dS |tjj	_
w )	z* Create with invalid compression numbers  r"   rl  irq  NzInvalid filterr   zUnknown compression)rU   r   r   r*   assertInstr	exceptionrr   rt  ru  rv  r  
IndexErrorr  r  )r   erw  r   r   r   test_compression_number_invalid  s"   
z;TestCreateCompressionNumber.test_compression_number_invalidN)r   r   r   r3   r  r  r   r   r   r   r~    s    r~  lzfzLZF is not installedc                   @   r}  )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"   rl  r  rq  Nr   rF   )rk   r@  r   )	r   r*   r9   r@  rn  rR   rz   flushr{   )r   r<   testdatareaddatar   r   r   test_lzf  s   

zTestCreateLZF.test_lzfc                 C   r  )z& Giving lzf options raises ValueError r"   rl  r  r$   rm  Nr  r   r   r   r   test_lzf_exc  s
   "zTestCreateLZF.test_lzf_excN)r   r   r   r3   r  r  r   r   r   r   r    s    r  szipzSZIP is not installedc                   @   rb  )TestCreateSZIPr  c                 C   s   | j jddddd}dS )z Create with explicit szip r"   rl  r  )ec   rm  N)r   r*   r;   r   r   r   	test_szip  s   
zTestCreateSZIP.test_szipN)r   r   r   r3   r  r   r   r   r   r        r  shufflezSHUFFLE is not installedc                   @   rb  )TestCreateShufflez8
        Feature: Datasets can use shuffling filter
    c                 C   "   | j jdddd}| |j dS )z Enable shuffle filter r"   rl  T)r  N)r   r*   rs   r  r;   r   r   r   test_shuffle     zTestCreateShuffle.test_shuffleN)r   r   r   r3   r  r   r   r   r   r    r  r  
fletcher32zFLETCHER32 is not installedc                   @   rb  )TestCreateFletcher32z=
        Feature: Datasets can use the fletcher32 filter
    c                 C   r  )z Enable fletcher32 filter r"   rl  T)r  N)r   r*   rs   r  r;   r   r   r   test_fletcher32  r  z$TestCreateFletcher32.test_fletcher32N)r   r   r   r3   r  r   r   r   r   r    ri  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
    c                 C   D   |  t | jjd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 r"   rl  Tr'   r  NrU   r   r   r*   floatr;   r   r   r    test_float_fails_without_options     "z6TestCreateScaleOffset.test_float_fails_without_optionsc                 C   r  )z# Check when scaleoffset is negetiver"   rl  gr  Nr  r;   r   r   r   test_non_integer  r  z&TestCreateScaleOffset.test_non_integerc                 C   r  )z% Check when dtype is unsupported typer"   rl  Tr  N)rU   rV   r   r*   boolr;   r   r   r   test_unsupport_dtype  r  z*TestCreateScaleOffset.test_unsupport_dtypec                 C   s   d}d}dd|  }t jj| d | }| jjd|t j|d}|jdus&J ||d	< | jj}| j  t	
|d
| _| jd d	 }| j||d|  d ||k rTJ dS )z2 Scaleoffset filter works for floating point data r$   r   i,  r   rI   g      ?r"   r  N.r)	precision)rR   randomrandr   r*   float64r  filenamer   rr   r   r{   r  )r   scalefacr:   ranger  r<   r  r  r   r   r   
test_float  s   
z TestCreateScaleOffset.test_floatc                 C   s   d}d}t jjdd| d |t jd}| jjd|t jdd	}|jd
us%J ||d< | jj}| j  t	
|d| _| jd d }| || d
S )zB Scaleoffset filter works for integer data with default precision r  r  r   rb   r   rL   r'   r"   Tr  N.r  )rR   r  randintr   r   r*   r  r  r   rr   r   r{   r   nbitsr:   r  r<   r  r  r   r   r   test_int2  s   
zTestCreateScaleOffset.test_intc                 C   s   d}d}t jjdd| |t jd}| jjd|t j|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   rb   r  r"   r  .r  N)rR   r  r  r   r   r*   rs   r  r  r   rr   r   r{   r  r   r   r   test_int_with_minbitsG  s   
z+TestCreateScaleOffset.test_int_with_minbitsc                 C   s   d}d}t jjdd|d  d |t jd}| jjd|t j|d}| |jdk ||d	< | jj}| j	  t
|d
| _| jd d	 }||k rKJ dS )r  r  r  r   rb   r   r  r"   r  .r  N)rR   r  r  r   r   r*   rs   r  r  r   rr   r   r  r  r   r   r   test_int_with_minbits_lossy[  s   "
z1TestCreateScaleOffset.test_int_with_minbits_lossyN)r   r   r   r3   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d||j|dd}||d< |jdus*J t	|d}|
 }W d   n1 s>w   Y  || ksKJ t|j    }t| jjj }	||	ksiJ dS )	z' Create and access an external dataset rH   r   r   r"   z	${ORIGIN}r'   externalefile_prefix.Nrb)rR   r  r   r   	UNLIMITEDr   r*   r'   r  openreadtobytespathlibPathr   get_access_plistget_efile_prefixdecodeas_posixr  parent)
r   r:   r  ext_filer  r<   fidcontentsr  r  r   r   r   test_contentsv  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s2J t|d}| }W d   n1 sFw   Y  || ksSJ t|j    }t|j }	||	ksoJ | jjd||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"   r  .Nr  )r  r   )rR   r  r   ospathbasenamer   r  r   r*   r'   dirnamer  r  r  r  r  r  r   r  r  r  r  r  r   )r   r:   r  r  r  r<   r  r  r  r  rd   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"   r  r  N)r   r*   r   r   r   r   r   test_name_str  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"   r  r  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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   .0rf  r  r   r   	<genexpr>  s    z/TestExternal.test_iter_multi.<locals>.<genexpr>poor  r  N)r   iterr  r   r*   r  r  )r   Nr  r<   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d||d W d   n1 sPw   Y  q3dS )z" Test with invalid external lists r  r   zh5f.UNLIMITEDr"   r  N)r   rV   r   r  r   rU   r   r*   )r   r:   r  exc_typer  r   r   r   test_invalid  s   

	zTestExternal.test_invalidc                 C   sR   |   }d}d}| jjd|||d}|jdu sJ |j|ks J |j|ks'J dS )z$ Create expandable external dataset )   @   )Nr  r"   )r:   r  r  N)r   r   r*   r  r:   r  )r   r  r:   r  exp_dsetr   r   r   test_create_expandable  s   z#TestExternal.test_create_expandableN)r   r   r   r3   r  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   r9   re  rr   r   r   r   r   )r   r.   r   variabler   r   r   r   assert_string_type  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 thererf     as   bcyr&   zN)r   r  rr   r   r   rR   r   object_r   r   r   r   test_vlen_bytes  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   rf  r   bcr  r&   r  N)	chrr   r  rr   r   r   rR   r   r  r   r   r   r   test_vlen_unicode  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  rf  F)r  r  N)rR   bytes_r   r  rr   r   r   r9   r   r   r   r-   r   r   r   test_string_fixed  s   
z TestAutoCreate.test_string_fixedN)T)r   r   r   r3   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 )Nr   r   lollike_lolr   r   )	rR   rz   r|   r   create_dataset_liker9   r:   assertIsr  )r   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 )
Nhondar  T)rk   track_timesr   hyundaiibmFlenovo)r   r*   rR   rz   rF  rr   h5gget_objinfo_idmtimer  r9   )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  r9   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                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestChunkIteratorc                 C   sF   | j dd}| t |  W d    d S 1 sw   Y  d S )Nr"   r   )r   r*   rU   rV   iter_chunksr;   r   r   r   r  (  s   
"z TestChunkIterator.test_no_chunksc                 C   sV   | j jdddd}| t |tdddf W d    d S 1 s$w   Y  d S )Nr"   r       r     C   r   )r   r*   rU   r   r  slicer;   r   r   r   test_rank_mismatch-  s   "z$TestChunkIterator.test_rank_mismatchc                 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| 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   r  r  r   r  r   r  `   r   r   a   r   r*   r  r9   listr  rR   r   r   r<   r   r   r   r   test_1d2  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| 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 )Nr"   r   r   )r  r  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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  rb   rb   r  rx   r$   r   r   )r   r*   r  r9   r  r  )r   r<   r   selr   r   r   test_2d_partial_sliceZ  s   
"z'TestChunkIterator.test_2d_partial_sliceN)r   r   r   r  r  r  r"  r%  r   r   r   r   r  '  s    r  c                   @   r   )
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"   rl  r   rJ   r  Nr   r*   assertIsNotr  r9   r  r;   r   r   r   r   k  rs  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  NrF   r(  r;   r   r   r   r   q  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"   rl  r'  r  r   r   Nr   r*   r9   r:   rU  r;   r   r   r   test_resizez  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  )rv   Nr+  r;   r   r   r   test_resize_1D  s   
zTestResize.test_resize_1Dc                 C   sL   | j jdddd}| t |d W d   dS 1 sw   Y  dS )z. Resizing past maxshape triggers an exception r"   rl  r'  r  )r   r   N)r   r*   rU   	ExceptionrU  r;   r   r   r   test_resize_over  s   "zTestResize.test_resize_overc                 C   sH   | j dd}| t |d W d   dS 1 sw   Y  dS )z/ Resizing non-chunked dataset raises TypeError r"   rl  r'  N)r   r*   rU   rV   rU  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"   rl  r'  r  r   r   axisr*  N)r   r*   rU  r9   r:   r;   r   r   r   test_resize_axis  rs  zTestResize.test_resize_axisc                 C   sP   | j jdddd}| t |jddd W d   dS 1 s!w   Y  dS )	z  Illegal axis raises ValueError r"   rl  r'  r  r   rb   r1  N)r   r*   rU   r   rU  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   )r5  Nr  N)r   r*   r9   r:   r  r;   r   r   r   test_zero_dim  rs  zTestResize.test_zero_dimN)r   r   r   r3   r   r   r,  r-  r/  r0  r3  r4  r6  r   r   r   r   r&  e  s    		r&  c                   @   r}  )	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"   rR  |S10NrQ   r;   r   r   r   
test_dtype  s   zTestDtype.test_dtypec                 C   s<   t dt jfdt jfg}| jdd|}| |j| dS )z7 Retrieve dtype from complex float16 dataset (gh-2156) r  r2  r"   rR  N)rR   r'   float16r   r*   r9   )r   	complex32r<   r   r   r   test_dtype_complex32  s   zTestDtype.test_dtype_complex32N)r   r   r   r3   r9  r<  r   r   r   r   r7        r7  c                   @   r}  )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  r5  r?  N)r   r*   r9   r  r;   r   r   r   test_len  s   zTestLen.test_lenc                 C   s~   | j dd}| |jd tjdkr-| t t| W d   n1 s'w   Y  n| t|d | | d dS )z Python len() vs Dataset.len() r"   )        r5  iNrA  )	r   r*   r9   r:   r4   maxsizerU   OverflowErrorr  r;   r   r   r   test_len_big  s   

zTestLen.test_len_bigN)r   r   r   r3   r@  rD  r   r   r   r   r>    r=  r>  c                   @   r}  )TestIterz;
        Feature: Iterating over a dataset yields rows
    c                 C   s\   t jdddd}| jjd|d}t||ddD ]\}}| t|d	 | || qd
S )z& Iterating over a dataset yields rows rv   r   r&   rw   r"   rj   T)strictrx   N)	rR   rz   r|   r   r*   zipr9   r  r{   )r   rk   r<   rf  r  r   r   r   	test_iter  s   zTestIter.test_iterc                 C   sN   | j j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"   r   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*   rU   rV   r;   r   r   r   test_iter_scalar  s   "zTestIter.test_iter_scalarN)r   r   r   r3   rH  rK  r   r   r   r   rE    s    rE  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   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 r_  r`  rf  r   r&   N)rr   string_dtyper   r*   r   r   r9   re  r   r   r   r   check_string_dtyper'   r]  r   r.  r.   r   string_infor   r   r   r    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 )	& Vlen bytes dataset handles fillvalue r_  r`     barrf  r   r   r   Nrr   rM  r   r*   r9   asstrr  r   r   r.  
fill_valuer.   r   r   r   test_vlen_bytes_fillvalue  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 rf  r   r&   r[  N)rr   rM  r   r*   r   r   r9   re  r   r   r   r   rN  r'   r]  rO  r   r   r   r    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 )( Vlen unicode dataset handles fillvalue    bárrf  r   r   r   r[  N)rr   rM  r   r*   r9   rZ  rT  r   rU  r   r   r   test_vlen_unicode_fillvalue  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
        r8  rf  r   r&   rI   r_  N)rR   r'   r   r*   r   r   r9   re  rr   r   r   assertFalser   r   r   r   rN  r]  r   rO  r   r   r   test_fixed_ascii  s   

zTestStrings.test_fixed_asciic                 C   sr   t jddd}d}| jjdd||d}| | jd d | | | jd  d |  | | jd j| d	S )
rQ  r_  rI   r\  rR  rf  r   r   r   NrS  rU  r   r   r   test_fixed_bytes_fillvalue#  s   z&TestStrings.test_fixed_bytes_fillvaluec                 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 sow   Y  tj|d d tj|
dgd dd d S )Nr[  r   r\  rf  r   r&      cùr   r   rb   r$   rH      UrI   S)rr   rM  r   r*   r   r   r9   r   r   r   rZ  rR   r   r   rU   rV   r   r   )r   r.  r.   r   sr   r   r   test_fixed_utf8,  s   
"0zTestStrings.test_fixed_utf8c                 C   sz   t jddd}dd}| jjdd||d}| | jd d | | | jd  d |d | | jd j| d	S )
rX  r[  rI   r\  rY  rf  r   r   r   N)	rr   rM  rZ  r   r*   r9   rT  r  r   rU  r   r   r   test_fixed_utf_8_fillvalue<  s   
 z&TestStrings.test_fixed_utf_8_fillvaluec                 C   sL   t d}| t | jjdd|d}W d   dS 1 sw   Y  dS )zA Fixed-length unicode datasets are unsupported (raise TypeError) z|U10rf  r   r&   N)rR   r'   rU   rV   r   r*   r   r.  r.   r   r   r   test_fixed_unicodeE  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`  rf  r   r&      Hellor   N)rr   rM  r   r*   r9   re  bytesr   r.  r.   rk   outr   r   r   test_roundtrip_vlen_bytesK  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 r8  rf  r   r&   rg  r   N)rR   r'   r   r*   r9   re  r  ri  r   r   r   test_roundtrip_fixed_bytesV  s   
z&TestStrings.test_roundtrip_fixed_bytesc                 C   s^   t  }| jjdd|d}d}||d< | |d t | d }| |t | || d S )Nrf  r   r&      fàilter   )	rr   rM  r   r*   rq   rh  rT  r  r9   ri  r   r   r   test_retrieve_vlen_unicodea  s   z&TestStrings.test_retrieve_vlen_unicodec                 C   s   | j jd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 )Nrf  r   r&   rm  r   r_  ignorefiltelatin-1rI   r   )r   r*   rr   rM  rT  rU   UnicodeDecodeErrorr9   rF  r  rR   r   r   r   r   asarray)r   r.   rk   strwrap1r   r   r   
test_asstrk  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   r   rf  r   r&   r^  r[  r   r_  ro  r   rq  r   )rr   rM  r   r*   rR   r   rZ  rq   r  rT  r  r9   rF  r   r   r   ri  r   r   r   test_asstr_fixed  s   zTestStrings.test_asstr_fixedc                 C   sX   t d}| jjd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 datasetr_  rf  r   r&   rm  r   N)rr   rM  r   r*   rU   UnicodeEncodeError)r   r.  r.   rk   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
        rf  r   r&   r  r  utf8r   N)	rr   rM  r   r*   r  rZ  r9   re  rh  ri  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_  rf  r   r&   zASCII stringr   N)rr   rM  r   r*   r9   re  rh  rZ  ri  r   r   r   test_vlen_bytes_write_ascii_str  s   
z+TestStrings.test_vlen_bytes_write_ascii_strN)r   r   r   r3   r  rW  r  rZ  r\  r]  rc  rd  rf  rk  rl  rn  ru  rv  rx  rz  r{  r   r   r   r   rL    s&    
	
			
rL  c                   @   rj  )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+|| jd< | jd 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   test.N)rR   r'   r  uint32uint8r(  fieldsr  r   rs   r  r9   )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 ||< q| jj	dd|d}|jD ]}|| ||< q6| jd d	 }| 
t ||k | |j|j d S )
Nr}  rx   r  r  r&   rL   r   r  .)rR   r'   r  r  r(  r  r  r:   r   r*   rs   r  r9   )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 ||< q|| jd< t j| jd ddgd d  |ddg  t j| jd dd d  |d  t jt 	| jd ddg|ddg  t dt j
fg}t jt j	| jd dg|d|dg | t| jd ddksJ d S )	Nrf  r  r  r  r&   r   r  r  )rR   r'   r  r(  r  r  r   r   r   rs  r%   astyper  )r   r.  r  r  dt_intr   r   r   test_fields  s0   

$" 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}|| jd< | jd }| j	||dd d S )Nr   r   f1f2r   rx   r&   rH   r   rI   ry  r     rb   r.   F)check_alignment)
rR   r'   rr   
vlen_dtyper%   r   r   r  r   r{   )r   dt_innerr.  inner1inner2rk   rj  r   r   r   test_nested_compound_vlen	  s(   

z&TestCompound.test_nested_compound_vlenN)r   r   r   r3   r  r  r  r  r   r   r   r   r|    s    #r|  c                   @   r   )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   r?   3int8r&   r   rb   rx   r   )r$   r   rH   )r   r*   rR   r   r   r-   r   r   r   test_write_list#  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*   rR   r   r   r   r-   r   r   r   test_write_array+  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   r3  )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 r2  basetyperf  r  r&   N)rr   
enum_dtypeEDICTr   r*   r'   check_enum_dtyper9   )r   r.  r.   dt2dict2r   r   r   r   <  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  rf  r  r&   r3  )#   %   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   )	rr   r  r  r   r*   r9   r{   rR   r   re  r   r   r   test_readwriteD  s   &zTestEnum.test_readwriteN)r   r   r   r3   r  r   r  r   r   r   r   r  4  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 )Nrf  r   r&   .)r   r*   r9   r'   rR   rm   r{   )r   r.  r<   rk   r   r   r   	_exectestT  s
   zTestFloats._exectestr:  zNumPy float16 support requiredc                 C   s   |  td dS )z Mini-floats round trip r:  N)r  rR   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 r:  z<f2z<f4N)rg   rR   r9   r   
IEEE_F16LEr'   r   r   r   r   test_mini_mappinga  s   
zTestFloats.test_mini_mappingN)r   r   r   r3   r  r   
skipUnlessrg   rR   r  r  r   r   r   r   r  N  s    
r  c                   @   r}  )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*   rr   r  r  r  r  r9   )r   r.   ds_mtimer   r   r   test_disable_track_timeso  s   z'TestTrackTimes.test_disable_track_timesc                 C   r  )z3 check that when give track_times an invalid value r"   r#   nullr  NrT   r   r   r   r   test_invalid_track_timesu  r
  z'TestTrackTimes.test_invalid_track_timesN)r   r   r   r3   r  r  r   r   r   r   r  i  s    r  c                   @   r}  )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 rf  r   Nr  r  r   r   r  r   r   )NN)r   r*   r9   r:   rR   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   r2  rf  r  r   r  r&   .r   N)r   r*   rR   emptyr9   r:   r'   )r   r.  r.   r   r   r   r   test_reading  s   zTestZeroShape.test_readingN)r   r   r   r3   r  r  r   r   r   r   r  {  s    r  c                   @   r"  )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  rf  rj   .)	r   r   rR   rz   r|   rk   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  rI   r   r   N)rR   r   r<   	regionrefr{   rk   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   )r<   r  rL   )r   r  rj  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sIJ d S )Nscalar      ?r+  rk   r'      .r   )r   r*   rr   h5screateSCALARselect_noneh5rr   DATASET_REGIONr   rR   r'   
select_all)r   r.   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  rI   r   r   )rI      N)rR   r   r<   r  r9   r:   	selectionr  r   r   r   test_ref_shape  s   zTestRegionRefs.test_ref_shapeN)	r   r   r   r3   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 )	
TestAstypez(.astype() wrapper & context manager
    c                 C   sL   | j jdddd}td|d< |dd d  }| |tjddd d S Nrf  r   r   r&   r   .r+  )r   r*   rR   rz   r  r{   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*   rR   rz   r9   r  r  r;   r   r   r   test_astype_wrapper_len  s   z"TestAstype.test_astype_wrapper_lenc                 C   sN   | j jdddd}td|d< tj|ddd}| |tjddd d S r  )r   r*   rR   rz   rs  r  r{   r  r   r   r   test_astype_wrapper_asarray  s   z&TestAstype.test_astype_wrapper_asarrayN)r   r   r   r3   r  r  r  r   r   r   r   r    s
    r  c                   @   rb  )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 )Nr1  rf  r   r&   r   r2  )rR   r'   r   r*   r9   )r   r.  r<   r   r   r   test_scalar_compound  s   z'TestScalarCompound.test_scalar_compoundN)r   r   r   r3   r  r   r   r   r   r    s    r  c                   @   sn   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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#   r&   rx   r   r   r  rb   r   r$   )
rr   r  intr   r*   rR   rz   r{   r   r   re  r   r   r   r    s    
&"zTestVlen.test_intc                 C   s6   t t}| jjdd|d}| jdd|d j d S )Nr  r?   r&   vlen2r   )rr   r  r  r   r*   r'   re  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   r  r?   r&   r  r   )	r  rr   r  r   r*   r  r   r   r'   )r   r.  r.   fnamer   r   r   test_reuse_struct_from_other  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 )Nr  r  r&   gffffff?333333?r   r   )r  rb   rx   rb   r  )皙?g?g @g@r$   r$   r   )r  r  皙@)皙?r  r  rx   )
rr   r  r  r   r*   rR   r   r{   rz   r   re  r   r   r   test_convert
  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 )Nr  r#  r&   r   r  rx   rb   )	rr   r  r  r   r*   rR   rz   r   r   re  r   r   r   test_multidim  s   
zTestVlen.test_multidimr  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.
        rR  r&   )r         @g      >@)g33333Y@gi@gfffffX@g      %g     r)r   rb   r_  r%   )r  r  g      @rS  g      )r   ir   r   i'  r   r   r   rb   rx   r$   g333333?r  N)rr   r  r   r*   rR   r   r'   r  r{   r  r   )r   np_dtdataset_namer.  r.   array_0array_1array_2casted_array_2list_3list_array_3list_4list_array_4r   r   r   _help_float_testing$  s2   


zTestVlen._help_float_testingc                 C      t d}| | d S )Nr:  rR   r'   r  r   r  r   r   r   test_numpy_float16T     
zTestVlen.test_numpy_float16c                 C   r  )Nfloat32r  r  r   r   r   test_numpy_float32X  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   )rR   r  r  r  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sBJ | 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sJ | j d
 d  d	|ddd  dS )z4Test that non-contiguous arrays are stored correctlyncr   r  r&   )TFTTFFFNrb   r   z != nc2int8)rb   r$   r   r   r   rx   r   )r   r*   rr   r  rR   r   r  )r   rf  r  r   r   r   test_non_contiguous_arraysd  s   FJz#TestVlen.test_non_contiguous_arraysc                 C   sf   t jdd}d}| jjdd||d}tt tj|	 t
d W d    d S 1 s,w   Y  d S )Nr_  r`  rR  rf  r   r   r&   )rr   rM  r   r*   r\   r   r   rR   r   rT  r  rU  r   r   r   test_asstr_array_dtyper  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 dd}|j }dS )z Test H5Dget_access_plist r"   r#   N)r   r*   r   r  )r   r.   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 rf  r      xN)rr   h5pr  DATASET_ACCESSr   r*   r9  r  r   rq   	DatasetID)r   daplr<   dsidr   r   r   	test_dapl  s
   zTestLowOpen.test_daplN)r   r   r   r  r  r   r   r   r   r  z  s    r  c               	   C   sb  ddl m}  |  }t|d}|jddddd d	|d d d < W d    n1 s+w   Y  |d t|d
l}|d j}| dksIJ tdD ]0}t	t
t
|dd }||}|j|kshJ |jdksoJ |jd usvJ |jdks}J qM|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  rp   r   r:   r  r'   r   r  r   rI   r  )ior  rr   r   r*   seekr   get_num_chunksr  r  rR   r   unravel_indexget_chunk_infochunk_offsetfilter_maskbyte_offsetrL   get_chunk_info_by_coord)r  buffoutfinr.   joffsetsir   r   r   test_get_chunk_details  s.   



"r"  )r   r  rx   )r   rI   rI   )r   rI   c   zJchunk iteration requires  HDF5 1.10.10 and later 1.10, or 1.12.3 and laterc                     s   ddl m}  |  }t|d}|jddddd d	|d d
d
< W d
   n1 s+w   Y  |d t|d6}|d j}| }|dksKJ i  t|D ]}|	|}| |j
< qQ fdd}|| W d
   d
S 1 stw   Y  d
S )z%H5Dchunk_iter() for chunk informationr   r  r   r  r  rp   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  rL   )
chunk_infoknowncir   r   callback  s
   
z!test_chunk_iter.<locals>.callback)r  r  rr   r   r*   r  r   r  r  r  r  
chunk_iter)r  r  r   r  
num_chunksr  r!  r(  r   r&  r   test_chunk_iter  s$   


"r+  c                 C   s.   | j ddd}|jd u sJ |jd u sJ d S )Nr  r%   r&   )r*   r:   r  )r   r.   r   r   r   test_empty_shape  s   r,  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  rr   r   r*   r  r  r   
get_offsetget_storage_size)r  r  r  r  r   r   r   test_zero_storage_size  s   
"r/  c                 C   s   t t jjt t jjd g}| jd|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   rf  r  r&   )
rR   iinfor   maxr*   uint64r'   r   r   r   )r   rk   r.   r   r   r   test_python_int_uint64  s    "&r3  c                 C   s<   | j ddtjd}tjjddd}||d d g ddf< d S )	Nrk   )r   r  rb   r&      )r   rx   rb   r  )r   rb   r$   .)r*   rR   r  r  r  )r   r   blockr   r   r   test_setitem_fancy_indexing  s   r6  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   r7  )Nzvlen_string_dset_utc.h5ds1r   s   2009-12-20T10:16:18.662409Zr9  r:  r   r   r   test_vlen_nullterm  r<  r>  c                 C   s0   d}| j ddtj|dd}t||jv sJ d S )N   rk   rp   T)r:   r'   r@  allow_unknown_filter)r*   rR   r  r  _filters)r   fake_filter_idr.   r   r   r   test_allow_unknown_filter  s   
rC  c               
   C   s  ddl m}  |  }t|d0}|jdddddd	d
d}|j  }|j  dd |ks2J |dks8J W d   n1 sBw   Y  |	d t|d0}|j
ddddddd}|j  }|j  dd |kstJ |dkszJ W d   dS 1 sw   Y  dS )z2Chunk cache configuration for individual datasets.r   r  r   rf  )rI   r   )r   r$   r       r    )r:   r  r'   rdcc_nbytesrdcc_w0rdcc_nslotsr   N)rE  rD  r  r    0 q=
ףp?  )r:   r'   rF  rG  rH  )rK  rI  rJ  )r  r  rr   r   r*   r   r  get_chunk_cache	get_cacher  r   )r  r  r  r.   ds_chunk_cacher  r   r   r   test_dset_chunk_cache  s*   
"rO  c                   @   r}  )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s$J t||k||kks1J d}t|| }t||k||kksGJ t||k||kksTJ dS )z
        Create a h5py dataset, extract one element convert to numpy
        Check that it returns symmetric response to == and !=
        r   r   r  r'   rk   r  gMbP?N)	r   r*   r  rR   r  r  r  r  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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.
        rQ  r  rR  rS  N)r   r*   r  rR   r  r  )r   r:   r<   rT  r   r   r   test_basetype_commutative6  s   
z)TestCommutative.test_basetype_commutativeN)r   r   r   r3   rW  rX  r   r   r   r   rP    s    rP  c                   @   r}  )TestVirtualPrefixz%
    Test setting virtual prefix
    c                 C   sR   d}d}| j jd|ttjj| |d}t|j	 
   }||ks'J d S )NrQ  /path/to/virtualr  )r'   rk   virtual_prefix)r   r*   r  rR   r  r  r  r  r   r  get_virtual_prefixr  r  )r   r:   r[  r<   virtual_prefix_readbackr   r   r   test_virtual_prefix_createJ  s   
z,TestVirtualPrefix.test_virtual_prefix_createc                 C   s^   d}| j jddd|d}t|j    }| 	|| | 
|t | 	|jd d S )NrZ  r"   rw   r   )r[  )r   r   r  r  r   r  r\  r  r  r9   rq   r   r:   )r   r[  r<   r]  r   r   r   test_virtual_prefix_requireT  s   z-TestVirtualPrefix.test_virtual_prefix_requireN)r   r   r   r3   r^  r_  r   r   r   r   rY  F  s    
rY  r   c                 C   s"   t jdd}d}| jd|||dS )Nr_  r`  s   fillrf  r   )rr   rM  r*   filer:   r.  rV  r   r   r   ds_str]  s   rb  c                 C   sF   t dtjddfdt jfg}t jd|d}t ||| d< | d S )Nr"   r_  r`  rF   )fillrS  r&   rf  )rR   r'   rr   rM  r  rs  broadcast_tor`  r   r   r   	ds_fieldsc  s   re  zview_getter,make_dsc                 C   s   | S r   r   r.   r   r   r   <lambda>p  s    rg  c                 C   s   | j tdS )Nr&   )r  r   rf  r   r   r   rg  q  s    c                 C   s   |   S r   )rT  rf  r   r   r   rg  r  s    c                 C   s
   |  dS )Nr"   )r  rf  r   r   r   rg  s  s   
 )r.   r  rT  r  )ids)rb   r   Fr   Tc                 C   s"   ||}| |}t j||d d S )Nr   )rR   r   )view_gettermake_dsr   r   r.   viewr   r   r   test_array_copy{  s   rm  z"forbidding copies requires numpy 2)reasonc                 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  Fri  )r\   r   r   rR   r   rj  rk  r   r.   rl  r   r   r   test_array_copy_false  s
   "rp  c                 C   s2   ||}| |}t j|ddjt dksJ d S )Nr8  r&   )rR   r   r'   ro  r   r   r   test_array_dtype  s   "rq  c                 C   sB   ||dd}| |}t |d ttfsJ t|jdksJ d S )Nr   rI  )r   rh  r  rR   r   r:   ro  r   r   r   test_array_scalar  s   rr  c                 C   s,   ||dd}| |}t |jdksJ d S )Nr   rH   rI  )rR   r   r:   ro  r   r   r   test_array_nd  s   rt  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 )Nrs  rI  rb   rv   r   )r'   rR   r   ndimr:   rL   r  ro  r   r   r   test_view_properties  s   rv  c                    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   r   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   rJ    s    z4test_concurrent_dataset_creation.<locals>.<listcomp>c                 S   s   g | ]}|  qS r   )result)r  r   r   r   r   rJ    s    c                 3   s2    | ]}t  D ]}d |dd|dV  qqdS )rw  rx  ry  N)r  )r  r2  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  )r   )hr3   r  r  r4   numpyrR   rZ   r\   r  concurrent.futuresr   commonr   r   
data_filesr   rr   r   r   h5py._hl.baser	   r
   r   r   h5py.tests.commonr   r   r   r6   rh   r   r   r   r   r#  r5  r   r   r  r%   r   r  r  r  rM  ra  rc  rf   rY  rZ  rk  r~  r  r  r  r  r  r  r  r  r  r&  r7  r>  rE  rL  r|  r  r  r  r  r  r  r  r  r  r  r"  r  versionhdf5_version_tupler+  r,  r/  r3  r6  r;  r>  rC  rO  rP  rY  rb  re  view_gettersCOPY_IF_NEEDEDrm  skipifrp  rq  rr  rt  rv  r  r   r   r   r   <module>   s   			FY<(CC&T

,'ql,>D Tg. 

-











