a
    v=ic                     @   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   k/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/h5py/tests/test_attrs_data.pysetUp   s    zBaseAttrs.setUpc                 C   s   | j r| j   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                   @   s    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                   @   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   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   r0   r   r    r!   r(   r1   assertArrayEqualr2   r   r   r   
test_multiI   s    zTestArray.test_multiN)r   r   r   r-   r3   r8   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 ]L}t j	d|d}d|d< || j
jd< | j
jd }| |j| | || q(dS )z Storage of integer types r/   r   r4   .r   N)r   r   int16int32int64Zuint8Zuint16Zuint32Zuint64r0   r   r    r(   r   r7   r   Zdtypesr*   r+   r"   r   r   r   r#   [   s    zTestTypes.test_intc                 C   s   t dd dD }|D ]f}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   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<f8r/   r   gfffff&E@.r   zdtype: zvalue: N)	tupler   r0   r   r    printr   r(   r7   r=   r   r   r   
test_floatg   s    zTestTypes.test_floatc                 C   sh   t dd dD }|D ]L}tjd|d}d|d< || jjd< | jjd }| |j| | || qd	S )
z Storage of complex types c                 s   s   | ]}t |V  qd S r   r>   r?   r   r   r   rA   x   rB   z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16r/   r   y33333A@.r   N)rC   r   r0   r   r    r(   r   r7   r=   r   r   r   test_complexv   s    zTestTypes.test_complexc                 C   sp   t dd dD }|D ]T}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   s   | ]}t |V  qd S r   r>   r?   r   r   r   rA      rB   z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10r/   r   h.r   r   N)rC   r   r0   r   r    r(   r   r=   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   r0   Zbool_r   r    r(   r   r2   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)encodingrI   r   )HellozHi there!  This is HDF5!.r   r   r   N)h5pyZstring_dtyper   r0   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   rN      xN)r   r    r(   typestrrO   r   openidget_typer   TypeStringIDget_csetZ
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) rN   i@#  z!!r   rQ   N)chrr   r    r(   rR   rS   rO   r   rT   rU   rV   r   rW   rX   Z	CSET_UTF8rY   rZ   r[   r   r   r   test_unicode_scalar   s    zTestTypes.test_unicode_scalarN)r   r   r   r-   r#   rE   rF   rH   rK   rP   r^   r`   r   r   r   r   r9   U   s   r9   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 )Nr5   rQ   ZS10)r
   r   r   createZNULLr   ZC_S1copyZset_sizer   r   rU   rO   Emptyr   r   	empty_obj)r   Zsidr]   r\   r   r   r   r      s    


zTestEmpty.setUpc                 C   s   |  | j| jjd  d S Nr   )r(   re   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)re   r   r    rY   r	   r   rT   rU   r   r   r   r   
test_write   s    zTestEmpty.test_writec                 C   s>   |  t  | jjdd W d    n1 s00    Y  d S )Nr   r   )assertRaisesIOErrorr   r    modifyr   r   r   r   test_modify   s    zTestEmpty.test_modifyc                 C   s$   t | jj }| | jg| d S r   listr   r    valuesr(   re   r   rq   r   r   r   test_values   s    zTestEmpty.test_valuesc                 C   s(   t | jj }| d| jfg| d S rf   rp   r   r    itemsr(   re   r   ru   r   r   r   
test_items   s    zTestEmpty.test_itemsc                 C   s$   t | jj }| | jg| d S r   ro   rr   r   r   r   test_itervalues   s    zTestEmpty.test_itervaluesc                 C   s(   t | jj }| d| jfg| d S rf   rt   rv   r   r   r   test_iteritems   s    zTestEmpty.test_iteritemsN)r   r   r   r   rg   rj   rn   rs   rw   rx   ry   r   r   r   r   ra      s   ra   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   sb   d}z|| j jd< W n ty&   Y n0 | t | j jd  W d   n1 sT0    Y  dS )z0 ValueError on string write wipes out attribute s   Hello Hellor   N)r   r    
ValueErrorrk   KeyError)r   sr   r   r   rj      s    zTestWriteException.test_writeN)r   r   r   r-   rj   r   r   r   r   rz      s   rz   )r-   numpyr   commonr   r   rO   r   r   r   r   Zh5py._hl.baser	   r
   r   r.   r9   ra   rz   r   r   r   r   <module>
   s   
o1