U
    md                     @   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   S/home/sam/Atlas/atlas_env/lib/python3.8/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   Zint16Zint32Z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   s     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   r>   x   s     z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16r/   r   y33333A@.r   N)r?   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   r>      s     z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10r/   r   h.r   r   N)r?   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)encodingrE   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   rJ      xN)r   r    r(   typestrrK   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) rJ   i@#  z!!r   rM   N)chrr   r    r(   rN   rO   rK   r   rP   rQ   rR   r   rS   rT   Z	CSET_UTF8rU   rV   rW   r   r   r   test_unicode_scalar   s    zTestTypes.test_unicode_scalarN)r   r   r   r-   r#   rA   rB   rD   rG   rL   rZ   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   rM   ZS10)r
   r   r   createZNULLr   ZC_S1copyZset_sizer   r   rQ   rK   Emptyr   r   	empty_obj)r   ZsidrY   rX   r   r   r   r      s    


zTestEmpty.setUpc                 C   s   |  | j| jjd  d S Nr   )r(   ra   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)ra   r   r    rU   r	   r   rP   rQ   r   r   r   r   
test_write   s    zTestEmpty.test_writec              	   C   s*   |  t | jjdd W 5 Q R X 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(   ra   r   rm   r   r   r   test_values   s
     zTestEmpty.test_valuesc                 C   s(   t | jj }| d| jfg| d S rb   rl   r   r    itemsr(   ra   r   rq   r   r   r   
test_items   s
    
 zTestEmpty.test_itemsc                 C   s$   t | jj }| | jg| d S r   rk   rn   r   r   r   test_itervalues   s
     zTestEmpty.test_itervaluesc                 C   s(   t | jj }| d| jfg| d S rb   rp   rr   r   r   r   test_iteritems   s
    
 zTestEmpty.test_iteritemsN)r   r   r   r   rc   rf   rj   ro   rs   rt   ru   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   sP   d}z|| j jd< W n tk
r(   Y nX | t | j jd  W 5 Q R X dS )z0 ValueError on string write wipes out attribute s   Hello Hellor   N)r   r    
ValueErrorrg   KeyError)r   sr   r   r   rf      s    zTestWriteException.test_writeN)r   r   r   r-   rf   r   r   r   r   rv      s   rv   )r-   numpyr   commonr   r   rK   r   r   r   r   Zh5py._hl.baser	   r
   r   r.   r9   r]   rv   r   r   r   r   <module>
   s   
o1