o
    i e                     @   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ut)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   I/var/www/myenv/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                   @       e Zd ZdZdd Zdd ZdS )
TestScalarzB
        Feature: Scalar types map correctly to array scalars
    c                 C   s6   t jdt jd| jjd< | jjd }| |t j dS )z) Integers are read as correct NumPy type r   dtypexN)nparrayint8r   attrsassertIsInstance)r   outr   r   r   test_int*   s   zTestScalar.test_intc                 C   sf   t ddg}t jd|d}|| jjd< | jjd }| |t j | || | |d |d  dS )z) Compound scalars are read as numpy.void )ai)br   )r   g@r   r   r'   N)r   r   r   r   r!   r"   voidassertEqualr   dtdatar#   r   r   r   test_compound0   s   zTestScalar.test_compoundN)r   r   r   __doc__r$   r-   r   r   r   r   r   $   s    r   c                   @   r   )	TestArrayzK
        Feature: Non-scalar types are correctly retrieved as ndarrays
    c                 C   sF   t jddd}|| jjd< | jjd }| |t j | |jd dS )z/ Single-element arrays are correctly recovered r   r   r   r   N)r   ndarrayr   r!   r"   r)   shaper   r,   r#   r   r   r   test_singleA   s
   zTestArray.test_singlec                 C   sj   t jddd}d|dd< d|dd< || jjd	< | jjd	 }| |t j | |jd | || dS )
z' Rank-1 arrays are correctly recovered )*   r   r   g      E@Ng     G
   #   r   )r   r1   r   r!   r"   r)   r2   assertArrayEqualr3   r   r   r   
test_multiI   s   zTestArray.test_multiN)r   r   r   r.   r4   r9   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 )	TestTypeszF
        Feature: All supported types can be stored in attributes
    c                 C   sz   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d< | j
jd }| |j| | || qdS )z Storage of integer types r0   r   r5   .r   N)r   r    int16int32int64uint8uint16uint32uint64r1   r   r!   r)   r   r8   r   dtypesr+   r,   r#   r   r   r   r$   [   s   zTestTypes.test_intc                 C   s   t dd dD }|D ]3}tjd|d}d|d< || jjd< | jjd }td	|j| td
|| | |j| | || qdS )z! Storage of floating point types c                 s       | ]}t |V  qd S r   r   r   .0r   r   r   r   	<genexpr>i       z'TestTypes.test_float.<locals>.<genexpr>)z<f4z>f4z>f8z<f8r0   r   gfffff&E@.r   zdtype: zvalue: N)	tupler   r1   r   r!   printr   r)   r8   rB   r   r   r   
test_floatg   s   zTestTypes.test_floatc                 C   sh   t dd dD }|D ]&}tjd|d}d|d< || jjd< | jjd }| |j| | || qd	S )
z Storage of complex types c                 s   rD   r   rE   rF   r   r   r   rH   x   rI   z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16r0   r   y33333A@.r   N)rJ   r   r1   r   r!   r)   r   r8   rB   r   r   r   test_complexv   s   zTestTypes.test_complexc                 C   sp   t dd dD }|D ]*}tjd|d}d|d< || jjd< | jjd }| |j| | |d	 |d	  qd
S )z! Storage of fixed-length strings c                 s   rD   r   rE   rF   r   r   r   rH      rI   z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10r0   r   h.r   r   N)rJ   r   r1   r   r!   r)   r   rB   r   r   r   test_string   s   zTestTypes.test_stringc                 C   sl   t jdt jd}d|d< || jjd< | jjd }| |j|j | |d |d  | |d |d  dS )	z Storage of NumPy booleans    r   )TF.r   r   r   N)r   r1   bool_r   r!   r)   r   r3   r   r   r   	test_bool   s   zTestTypes.test_boolc                 C   st   t jdd}tjd|d}d|d< || jjd< | jjd }| |j| | |d |d  | |d	 |d	  d
S )z# Storage of vlen byte string arraysascii)encodingrP   r   )HellozHi there!  This is HDF5!.r   r   r   N)h5pystring_dtyper   r1   r   r!   r)   r   r*   r   r   r   test_vlen_string_array   s   z TestTypes.test_vlen_string_arrayc                 C   s   d| j jd< | j jd }| |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   Hellor   rV      xN)r   r!   r)   typestrrW   r   openidget_typer   TypeStringIDget_cset
CSET_ASCII
assertTrueis_variable_strr   r#   aidtidr   r   r   test_string_scalar   s   zTestTypes.test_string_scalarc                 C   s   dt d d | jjd< | jjd }| |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) rV   i@#  z!!r   rZ   N)chrr   r!   r)   r[   r\   rW   r   r]   r^   r_   r   r`   ra   	CSET_UTF8rc   rd   re   r   r   r   test_unicode_scalar   s   zTestTypes.test_unicode_scalarN)r   r   r   r.   r$   rL   rM   rO   rS   rY   rh   rk   r   r   r   r   r:   U   s    r:   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 )Nr6   rZ   S10)r
   r   r   createNULLr   C_S1copyset_sizer   r   r^   rW   Emptyr   r   	empty_obj)r   sidrg   rf   r   r   r   r      s   


zTestEmpty.setUpc                 C   s   |  | j| jjd  d S Nr   )r)   rt   r   r!   r   r   r   r   	test_read   s   zTestEmpty.test_readc                 C   s,   | j | jjd< | tt| jjd d S )Ny   y)rt   r   r!   rc   r	   r   r]   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IOErrorr   r!   modifyr   r   r   r   test_modify   s   "zTestEmpty.test_modifyc                 C   $   t | jj }| | jg| d S r   listr   r!   valuesr)   rt   r   r   r   r   r   test_values   s   zTestEmpty.test_valuesc                 C   (   t | jj }| d| jfg| d S rv   r   r   r!   itemsr)   rt   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   rv   r   r   r   r   r   test_iteritems   r   zTestEmpty.test_iteritemsN)r   r   r   r   rw   rz   r~   r   r   r   r   r   r   r   r   rl      s    rl   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   sd   d}z|| j jd< W n	 ty   Y nw | t | j jd  W d   dS 1 s+w   Y  dS )z0 ValueError on string write wipes out attribute s   Hello Hellor   N)r   r!   
ValueErrorr{   KeyError)r   sr   r   r   rz      s   "zTestWriteException.test_writeN)r   r   r   r.   rz   r   r   r   r   r      s    r   )r.   numpyr   commonr   r   rW   r   r   r   r   h5py._hl.baser	   r
   r   r/   r:   rl   r   r   r   r   r   <module>   s   	
o1