o
    2h$&                     @   s   d Z ddlZddl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)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   U/var/www/html/chatgem/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   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_compoundc                 C   s   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	d	< | jj	d	 }| j
||d
d dS )z; Compound scalars with vlen fields can be written and read r#   r%   r      r      
   r   r   Fcheck_alignmentN)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 }|| jj	d< | jj	d }| 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   r   Fr/   N)r   r   r1   r2   r3   int64r   r5   r   r   r6   )r   dt_innerr)   inner1inner2r*   r!   r   r   r   &test_nesting_compound_with_vlen_fieldsI   s,   z1TestScalar.test_nesting_compound_with_vlen_fieldsc                 C   s   t dt fdt fg}t dt|fg}t jt jddg|df|dd }|| jjd< | jjd }| 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   r   Fr/   N)	r   r   r1   string_dtyper2   r   r   r   r6   )r   rB   r)   r*   r!   r   r   r   #test_vlen_compound_with_vlen_string_   s   
"z.TestScalar.test_vlen_compound_with_vlen_stringN)	r   r   r   __doc__r"   r+   r7   rE   rG   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_singler   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     Gr.   #   r   )r   rK   r   r   r    r'   rL   r6   rM   r   r   r   
test_multiz   s   zTestArray.test_multiN)r   r   r   rH   rN   rQ   r   r   r   r   rI   l   s    rI   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 rJ   r   rO   .r   N)r   r   int16r3   rA   uint8uint16uint32uint64rK   r   r   r'   r   r6   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>       z'TestTypes.test_float.<locals>.<genexpr>)z<f4z>f4z>f8z<f8rJ   r   gfffff&E@.r   zdtype: zvalue: N)	tupler   rK   r   r   printr   r'   r6   rX   r   r   r   
test_float   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   rZ   r   r[   r\   r   r   r   r^      r_   z)TestTypes.test_complex.<locals>.<genexpr>)z<c8z>c8z<c16z>c16rJ   r   y33333A@.r   N)r`   r   rK   r   r   r'   r   r6   rX   r   r   r   test_complex   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   rZ   r   r[   r\   r   r   r   r^      r_   z(TestTypes.test_string.<locals>.<genexpr>)z|S1z|S10rJ   r   h.r   r   N)r`   r   rK   r   r   r'   r   rX   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@   r   )TF.r   r   r   N)r   rK   bool_r   r   r'   r   rM   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)encodingrf   r   )HellozHi there!  This is HDF5!.r   r   r   N)r1   rF   r   rK   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   rk      xN)r   r   r'   typestrr1   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) rk   i@#  z!!r   rm   N)chrr   r   r'   rn   ro   r1   r   rp   rq   rr   r   rs   rt   	CSET_UTF8rv   rw   rx   r   r   r   test_unicode_scalar   s   zTestTypes.test_unicode_scalarN)r   r   r   rH   r"   rb   rc   re   rh   rl   r{   r~   r   r   r   r   rR      s    rR   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.   rm   S10)r	   r   r   createNULLr   C_S1copyset_sizer   r   rq   r1   Emptyr   r   	empty_obj)r   sidrz   ry   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   s,   | j | jjd< | tt| jjd d S )Ny   y)r   r   r   rv   r   r   rp   rq   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   r4   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   r4   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   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   r   ,  s   "zTestWriteException.test_writeN)r   r   r   rH   r   r   r   r   r   r   &  s    r   )rH   numpyr   commonr   r1   r   r   r   r   h5py._hl.baser   r	   r   rI   rR   r   r   r   r   r   r   <module>   s   	
Ho1