B
    d                 @   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   L/var/www/html/venv/lib/python3.7/site-packages/h5py/tests/test_attrs_data.pysetUp   s    zBaseAttrs.setUpc             C   s   | j r| j   d S )N)r   close)r   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   r+   r   r   r   r%   r,   assertArrayEqual)r   r'   r   r   r   r   
test_multiI   s    zTestArray.test_multiN)r   r   r   r)   r-   r2   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   s~   t jt jt jt jt jt jt jt jf}xT|D ]L}t j	d|d}d|d< || j
jd< | j
jd }| |j| | || q*W dS )z Storage of integer types )r   )r   r.   .r   N)r   r   Zint16Zint32Zint64Zuint8Zuint16Zuint32Zuint64r+   r   r   r%   r   r1   )r   dtypesr&   r'   r   r   r   r   r    [   s    
zTestTypes.test_intc             C   s   t dd dD }xn|D ]f}tjd|d}d|d< || jjd< | jjd }td	|j| td
|| | |j| | || qW dS )z! Storage of floating point types c             s   s   | ]}t |V  qd S )N)r   r   ).0r   r   r   r   	<genexpr>i   s    z'TestTypes.test_float.<locals>.<genexpr>)z<f4z>f4z>f8z<f8)r   )r   gfffff&E@.r   zdtype: zvalue: N)	tupler   r+   r   r   printr   r%   r1   )r   r4   r&   r'   r   r   r   r   
test_floatg   s    
zTestTypes.test_floatc             C   sl   t dd dD }xT|D ]L}tjd|d}d|d< || jjd< | jjd }| |j| | || qW d	S )
z Storage of complex types c             s   s   | ]}t |V  qd S )N)r   r   )r5   r   r   r   r   r6   x   s    z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16)r   )r   y33333A@.r   N)r7   r   r+   r   r   r%   r   r1   )r   r4   r&   r'   r   r   r   r   test_complexv   s    
zTestTypes.test_complexc             C   st   t dd dD }x\|D ]T}tjd|d}d|d< || jjd< | jjd }| |j| | |d	 |d	  qW d
S )z! Storage of fixed-length strings c             s   s   | ]}t |V  qd S )N)r   r   )r5   r   r   r   r   r6      s    z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10)r   )r   h.r   r   N)r7   r   r+   r   r   r%   r   )r   r4   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   r+   Zbool_r   r   r%   r   )r   r'   r   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)encoding)r=   )r   )HellozHi there!  This is HDF5!.r   r   r   N)h5pyZstring_dtyper   r+   r   r   r%   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   rA      xN)r   r   r%   typestrrB   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) rA   i@#  z!!r   rD   N)chrr   r   r%   rE   rF   rB   r   rG   rH   rI   r   rJ   rK   Z	CSET_UTF8rL   rM   )r   r   rN   rO   r   r   r   test_unicode_scalar   s    zTestTypes.test_unicode_scalarN)r   r   r   r)   r    r9   r:   r<   r>   rC   rP   rR   r   r   r   r   r3   U   s   r3   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/   rD   ZS10)r
   r   r   createZNULLr   ZC_S1copyZset_sizer   r   rH   rB   Emptyr   r   	empty_obj)r   ZsidrO   rN   r   r   r   r      s    


zTestEmpty.setUpc             C   s   |  | j| jjd  d S )Nr   )r%   rW   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)rW   r   r   rL   r	   r   rG   rH   )r   r   r   r   
test_write   s    zTestEmpty.test_writec          	   C   s*   |  t | jjdd W d Q R X d S )Nr   r   )assertRaisesIOErrorr   r   modify)r   r   r   r   test_modify   s    zTestEmpty.test_modifyc             C   s$   t | jj }| | jg| d S )N)listr   r   valuesr%   rW   )r   ra   r   r   r   test_values   s    zTestEmpty.test_valuesc             C   s(   t | jj }| d| jfg| d S )Nr   )r`   r   r   itemsr%   rW   )r   rc   r   r   r   
test_items   s    zTestEmpty.test_itemsc             C   s$   t | jj }| | jg| d S )N)r`   r   r   ra   r%   rW   )r   ra   r   r   r   test_itervalues   s    zTestEmpty.test_itervaluesc             C   s(   t | jj }| d| jfg| d S )Nr   )r`   r   r   rc   r%   rW   )r   rc   r   r   r   test_iteritems   s    zTestEmpty.test_iteritemsN)r   r   r   r   rX   r[   r_   rb   rd   re   rf   r   r   r   r   rS      s   rS   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}y|| j jd< W n tk
r(   Y nX | t | j jd  W dQ R X dS )z0 ValueError on string write wipes out attribute s   Hello Hellor   N)r   r   
ValueErrorr\   KeyError)r   sr   r   r   r[      s    zTestWriteException.test_writeN)r   r   r   r)   r[   r   r   r   r   rg      s   rg   )r)   numpyr   commonr   r   rB   r   r   r   r   Zh5py._hl.baser	   r
   r   r*   r3   rS   rg   r   r   r   r   <module>   s   
o1