o
    gi'                     @   s   d Z ddlZddlmZmZ ddlZddl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eZG dd deZdS )z{
    Attribute data transfer testing module

    Covers all data read/write and type-conversion operations for attributes.
    N   )TestCase	make_name)h5ah5sh5t)File)is_empty_dataspacec                   @   s   e Zd Zdd Zdd ZdS )	BaseAttrsc                 C   s   t |  d| _d S )Nw)r   mktempfself r   X/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/h5py/tests/test_attrs_data.pysetUp   s   zBaseAttrs.setUpc                 C   s   | j r
| j   d S d S N)r   closer   r   r   r   tearDown   s   zBaseAttrs.tearDownN)__name__
__module____qualname__r   r   r   r   r   r   r
      s    r
   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )
TestScalarzB
        Feature: Scalar types map correctly to array scalars
    c                 C   s<   t  }tjdtjd| jj|< | jj| }| |tj dS )z) Integers are read as correct NumPy type r   dtypeN)r   nparrayint8r   attrsassertIsInstance)r   nameoutr   r   r   test_int*   s   zTestScalar.test_intc                 C   sl   t  }tddg}tjd|d}|| jj|< | jj| }| |tj | || | |d |d  dS )z) Compound scalars are read as numpy.void )ai)br   )r   g@r   r&   N)	r   r   r   r   r   r   r    voidassertEqualr   r!   dtdatar"   r   r   r   test_compound1   s   zTestScalar.test_compoundc                 C   s   t  }tdttjfdttjfg}tjtjttddtjdtjttddtjdf|dd }|| j	j
|< | j	j
| }| j||d	d
 dS )z; Compound scalars with vlen fields can be written and read r$   r&   r      r      
   r   Fcheck_alignmentN)r   r   r   h5py
vlen_dtypeint32r   listranger   r   assertArrayEqualr)   r   r   r   test_compound_with_vlen_fields<   s   z)TestScalar.test_compound_with_vlen_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|dd }t }|| j	j
|< | j	j
| }| j||dd dS )zK Compound scalars with nested compound vlen fields can be written and read r$   r&   f1f2r      r      	   r/               r   Fr0   N)r   r   r2   r3   r4   int64r   r6   r   r   r   r7   )r   dt_innerr*   inner1inner2r+   r!   r"   r   r   r   &test_nesting_compound_with_vlen_fieldsL   s.   z1TestScalar.test_nesting_compound_with_vlen_fieldsc                 C   s   t dt fdt fg}t dt|fg}t }t jt jddg|df|dd }|| jj|< | jj| }| j	||dd	 d
S )zV Compound scalars with vlen compounds containing vlen strings can be written and read r$   r&   r   )s   appless   bananas)s   peachess   orangesr   r   Fr0   N)
r   r   r2   string_dtyper3   r   r   r   r   r7   )r   rC   r*   r!   r+   r"   r   r   r   #test_vlen_compound_with_vlen_stringc   s   
"z.TestScalar.test_vlen_compound_with_vlen_stringN)	r   r   r   __doc__r#   r,   r8   rF   rH   r   r   r   r   r   $   s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )	TestArrayzK
        Feature: Non-scalar types are correctly retrieved as ndarrays
    c                 C   sL   t  }tjddd}|| jj|< | jj| }| |tj | |jd dS )z/ Single-element arrays are correctly recovered r   r   r   N)r   r   ndarrayr   r   r    r(   shaper   r!   r+   r"   r   r   r   test_singlew   s   zTestArray.test_singlec                 C   sp   t  }tjddd}d|dd< d|dd< || jj|< | jj| }| |tj | |jd | || dS )	z' Rank-1 arrays are correctly recovered )*   r   r   g      E@Ng     Gr/   #   )	r   r   rL   r   r   r    r(   rM   r7   rN   r   r   r   
test_multi   s   zTestArray.test_multiN)r   r   r   rI   rO   rR   r   r   r   r   rJ   q   s    	rJ   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 )	TestTypeszF
        Feature: All supported types can be stored in attributes
    c                 C   s   t  }tjtjtjtjtjtjtjtj	f}|D ]&}tj
d|d}d|d< || jj|< | jj| }| |j| | || qdS )z Storage of integer types rK   r   rP   .N)r   r   r   int16r4   rB   uint8uint16uint32uint64rL   r   r   r(   r   r7   r   r!   dtypesr*   r+   r"   r   r   r   r#      s   zTestTypes.test_intc                 C   n   t  }tdd dD }|D ]&}tjd|d}d|d< || jj|< | jj| }| |j| | || qdS )	z! Storage of floating point types c                 s       | ]}t |V  qd S r   r   r   .0xr   r   r   	<genexpr>       z'TestTypes.test_float.<locals>.<genexpr>)z<f4z>f4z>f8z<f8rK   r   gfffff&E@.N	r   tupler   rL   r   r   r(   r   r7   rY   r   r   r   
test_float      zTestTypes.test_floatc                 C   r[   )	z Storage of complex types c                 s   r\   r   r]   r^   r   r   r   ra      rb   z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16rK   r   y33333A@.Nrc   rY   r   r   r   test_complex   rf   zTestTypes.test_complexc                 C   sv   t  }tdd dD }|D ]*}tjd|d}d|d< || jj|< | jj| }| |j| | |d |d  qd	S )
z! Storage of fixed-length strings c                 s   r\   r   r]   r^   r   r   r   ra      rb   z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10rK   r   h.r   N)r   rd   r   rL   r   r   r(   r   rY   r   r   r   test_string   s   zTestTypes.test_stringc                 C   sr   t  }tjdtjd}d|d< || jj|< | jj| }| |j|j | |d |d  | |d |d  dS )z Storage of NumPy booleans rA   r   )TF.r   r   N)r   r   rL   bool_r   r   r(   r   rN   r   r   r   	test_bool   s   zTestTypes.test_boolc                 C   sz   t  }tjdd}tjd|d}d|d< || jj|< | jj| }| |j| | |d |d  | |d |d  d	S )
z# Storage of vlen byte string arraysascii)encodingrj   r   )HellozHi there!  This is HDF5!.r   r   N)	r   r2   rG   r   rL   r   r   r(   r   r)   r   r   r   test_vlen_string_array   s   z TestTypes.test_vlen_string_arrayc                 C   s   t  }d| jj|< | jj| }| |d | t|t tj| jj	|
d}| }| t|tjj | | tjj | |  dS )z@ Storage of variable-length byte string scalars (auto-creation) s   Helloro   utf-8N)r   r   r   r(   typestrr2   r   openidencodeget_typer   TypeStringIDget_cset
CSET_ASCII
assertTrueis_variable_strr   r!   r"   aidtidr   r   r   test_string_scalar   s   zTestTypes.test_string_scalarc                 C   s   t  }dtd d | jj|< | jj| }| |dtd d  | t|t tj	| jj
|d}| }| t|tjj | | tjj | |  dS )z< Storage of variable-length unicode strings (auto-creation) ro   i@#  z!!rq   N)r   chrr   r   r(   rr   rs   r2   r   rt   ru   rv   rw   r   rx   ry   	CSET_UTF8r{   r|   r}   r   r   r   test_unicode_scalar   s   zTestTypes.test_unicode_scalarN)r   r   r   rI   r#   re   rg   ri   rl   rp   r   r   r   r   r   r   rS      s    rS   c                   @   sL   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S )	TestEmptyc                 C   sT   t |  ttj}tj }|d t	| j
jd||}ttd| _d S )Nr/      xS10)r
   r   r   createNULLr   C_S1copyset_sizer   r   ru   r2   Emptyr   r   	empty_obj)r   sidr   r~   r   r   r   r      s   


zTestEmpty.setUpc                 C   s   |  | j| jjd  d S Nr`   )r(   r   r   r   r   r   r   r   	test_read  s   zTestEmpty.test_readc              	   C   s8   t  }| j| jj|< | tt| jj|	d d S )Nrq   )
r   r   r   r   r{   r	   r   rt   ru   rv   )r   r!   r   r   r   
test_write  s
   zTestEmpty.test_writec                 C   s@   |  t | jjdd W d    d S 1 sw   Y  d S )Nr`   r   )assertRaisesOSErrorr   r   modifyr   r   r   r   test_modify  s   "zTestEmpty.test_modifyc                 C   $   t | jj }| | jg| d S r   r5   r   r   valuesr(   r   r   r   r   r   r   test_values  s   zTestEmpty.test_valuesc                 C   (   t | jj }| d| jfg| d S r   r5   r   r   itemsr(   r   r   r   r   r   r   
test_items     zTestEmpty.test_itemsc                 C   r   r   r   r   r   r   r   test_itervalues%  s   zTestEmpty.test_itervaluesc                 C   r   r   r   r   r   r   r   test_iteritems+  r   zTestEmpty.test_iteritemsN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )TestWriteExceptionzH
        Ensure failed attribute writes don't leave garbage behind.
    c                 C   sv   d}|  t || jjd< W d   n1 sw   Y  |  t | jjd  W d   dS 1 s4w   Y  dS )z0 ValueError on string write wipes out attribute s   Hello Hellor`   N)r   
ValueErrorr   r   KeyError)r   sr   r   r   r   8  s   "zTestWriteException.test_writeN)r   r   r   rI   r   r   r   r   r   r   2  s    r   )rI   numpyr   commonr   r   r2   r   r   r   r   h5py._hl.baser	   r
   r   rJ   rS   r   r   r   r   r   r   <module>   s   	
Mq4