
    &Vf(&                         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	e          Z G d
 de          Z G d de          Z G d de          Z G d de          Z G 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                       e Zd Zd Zd ZdS )	BaseAttrsc                 T    t          |                                 d          | _        d S )Nw)r	   mktempfselfs    W/var/www/html/software/conda/lib/python3.11/site-packages/h5py/tests/test_attrs_data.pysetUpzBaseAttrs.setUp   s    dkkmmS))    c                 J    | j         r| j                                          d S d S N)r   closer   s    r   tearDownzBaseAttrs.tearDown   s)    6 	FLLNNNNN	 	r   N)__name__
__module____qualname__r   r    r   r   r   r      s2        * * *    r   r   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )
TestScalarzB
        Feature: Scalar types map correctly to array scalars
    c                     t          j        dt           j                  | 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   outs     r   test_intzTestScalar.test_int*   sM    HQbg666Sfl3c27+++++r   c                 P   t          j        ddg          }t          j        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)   s       r   test_compoundzTestScalar.test_compound0   s    Xz:.//x+++ Sfl3c27+++d###S49-----r   c                 <   t          j        dt          j        t           j                  fdt          j        t           j                  fg          }t          j        t          j        t          t          dd                    t           j                  t          j        t          t          dd                    t           j                  f|          d         }|| j        j	        d	<   | j        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'   assertArrayEqualr1   s       r   test_compound_with_vlen_fieldsz)TestScalar.test_compound_with_vlen_fields:   s    XT_RX667T_RX6679 : : x$uQ{{"3"328DDDeArll!3!328DDDFMOQ Q QQSU !Sfl3 	c4?????r   c                 `   t          j        dt          j        t           j                  fdt          j        t           j                  fg          }t          j        dt          j        |          fdt           j        fg          }t          j        t          dd          t           j                  t          j        t          dd	          t           j                  f}t          j        t          d
d          t           j                  t          j        t          dd          t           j                  f}t          j        t          j        ||g|          df|          d         }|| j        j	        d<   | j        j	        d         }| 
                    ||d           dS )zK Compound scalars with nested compound vlen fields can be written and read r,   r.   f1f2r      r!      	   r8               r   r#   Fr9   N)r$   r"   r;   r<   r=   int64r%   r?   r   r'   r@   )r   dt_innerr2   inner1inner2r3   r)   s          r   &test_nesting_compound_with_vlen_fieldsz1TestScalar.test_nesting_compound_with_vlen_fieldsI   sv   8c4?28#<#<=!4?28#<#<=? @ @ Xdoh778bh') * * (5A;;bh777(5A;;bh7779 (5R==999(5R==999; x66"2(CCC " " ""$& !Sfl3c4?????r   c                    t          j        dt          j                    fdt          j                    fg          }t          j        dt          j        |          fg          }t          j        t          j        ddg|          f|          d         }|| j        j        d<   | j        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#   Fr9   N)	r$   r"   r;   string_dtyper<   r%   r   r'   r@   )r   rM   r2   r3   r)   s        r   #test_vlen_compound_with_vlen_stringz.TestScalar.test_vlen_compound_with_vlen_string_   s    8c4#4#6#67!4#4#6#679 : : XT_X667899x#:<T"U]efffhoqrrrsuv Sfl3c4?????r   N)	r   r   r   __doc__r*   r4   rA   rP   rS   r   r   r   r   r   $   st         , , ,. . .@ @ @@ @ @,
@ 
@ 
@ 
@ 
@r   r   c                       e Zd ZdZd Zd ZdS )	TestArrayzK
        Feature: Non-scalar types are correctly retrieved as ndarrays
    c                     t          j        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(   r0   shaper   r3   r)   s      r   test_singlezTestArray.test_singler   sh    z$c*** Sfl3c2:...D)))))r   c                 2   t          j        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     Gr8   #   r#   )r$   rY   r   r'   r(   r0   rZ   r@   r[   s      r   
test_multizTestArray.test_multiz   s    z%s+++QQQRU Sfl3c2:...E***c4(((((r   N)r   r   r   rT   r\   r`   r   r   r   rV   rV   l   s<         * * *	) 	) 	) 	) 	)r   rV   c                   B    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )	TestTypeszF
        Feature: All supported types can be stored in attributes
    c                    t           j        t           j        t           j        t           j        t           j        t           j        t           j        t           j        f}|D ]o}t          j	        d|          }d|d<   || j
        j        d<   | j
        j        d         }|                     |j        |           |                     ||           pdS )z Storage of integer types rX   r!   r^   .r#   N)r$   r&   int16r=   rL   uint8uint16uint32uint64rY   r   r'   r0   r"   r@   r   dtypesr2   r3   r)   s        r   r*   zTestTypes.test_int   s    '28RXrx(BIry")= 	- 	-B:d"---DDI $DFL&,s#CSY+++!!#t,,,,	- 	-r   c                 j   t          d dD                       }|D ]}t          j        d|          }d|d<   || j        j        d<   | j        j        d         }t          d|j        |           t          d	||           |                     |j        |           |                     ||           d
S )z! Storage of floating point types c              3   >   K   | ]}t          j        |          V  d S r   r$   r"   .0r#   s     r   	<genexpr>z'TestTypes.test_float.<locals>.<genexpr>   s*      IIqrx{{IIIIIIr   )z<f4z>f4z>f8z<f8rX   r!   gfffff&E@.r#   zdtype: zvalue: N)	tupler$   rY   r   r'   printr"   r0   r@   ri   s        r   
test_floatzTestTypes.test_float   s    II,HIIIII 		- 		-B:d"---DDI $DFL&,s#C)SY+++)S$'''SY+++!!#t,,,,		- 		-r   c                    t          d dD                       }|D ]o}t          j        d|          }d|d<   || j        j        d<   | j        j        d         }|                     |j        |           |                     ||           pdS )	z Storage of complex types c              3   >   K   | ]}t          j        |          V  d S r   rm   rn   s     r   rp   z)TestTypes.test_complex.<locals>.<genexpr>   s*      KKqrx{{KKKKKKr   )z<c8z>c8z<c16z>c16rX   r!   y33333A@.r#   N)rq   r$   rY   r   r'   r0   r"   r@   ri   s        r   test_complexzTestTypes.test_complex   s    KK,JKKKKK 	- 	-B:d"---D$DI $DFL&,s#CSY+++!!#t,,,,	- 	-r   c                 4   t          d dD                       }|D ]{}t          j        d|          }d|d<   || j        j        d<   | j        j        d         }|                     |j        |           |                     |d         |d                    |d	S )
z! Storage of fixed-length strings c              3   >   K   | ]}t          j        |          V  d S r   rm   rn   s     r   rp   z(TestTypes.test_string.<locals>.<genexpr>   s*      <<qrx{{<<<<<<r   )z|S1z|S10rX   r!   h.r#   r   N)rq   r$   rY   r   r'   r0   r"   ri   s        r   test_stringzTestTypes.test_string   s    <<O<<<<< 	. 	.B:d"---DDI $DFL&,s#CSY+++SVT!W----	. 	.r   c                 Z   t          j        dt           j                  }d|d<   || j        j        d<   | j        j        d         }|                     |j        |j                   |                     |d         |d                    |                     |d         |d                    dS )	z Storage of NumPy booleans rK   r!   )TF.r#   r   r   N)r$   rY   bool_r   r'   r0   r"   r[   s      r   	test_boolzTestTypes.test_bool   s     z$bh///S	 Sfl3DJ///Qa)))Qa)))))r   c                 f   t          j        d          }t          j        d|          }d|d<   || j        j        d<   | j        j        d         }|                     |j        |           |                     |d         |d                    |                     |d	         |d	                    d
S )z# Storage of vlen byte string arraysascii)encodingr|   r!   )HellozHi there!  This is HDF5!.r#   r   r   N)r;   rR   r$   rY   r   r'   r0   r"   r1   s       r   test_vlen_string_arrayz TestTypes.test_vlen_string_array   s    000z$b)))7S	 Sfl3B'''Qa)))Qa)))))r   c                 `   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#   r      xN)r   r'   r0   typestrr;   r   openidget_typer   TypeStringIDget_cset
CSET_ASCII
assertTrueis_variable_strr   r)   aidtids       r   test_string_scalarzTestTypes.test_string_scalar   s     %Sfl3g&&&cC(((hmmDFIt,,llnncDH$9:::)<===++--.....r   c                    dt          d          z   dz   | j        j        d<   | j        j        d         }|                     |dt          d          z   dz              |                     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) r   i@#  z!!r#   r   N)chrr   r'   r0   r   r   r;   r   r   r   r   r   r   r   	CSET_UTF8r   r   r   s       r   test_unicode_scalarzTestTypes.test_unicode_scalar   s     %s6{{2U:Sfl3hV4u<===cC(((hmmDFIt,,llnncDH$9:::);<<<++--.....r   N)r   r   r   rT   r*   rs   rv   rz   r~   r   r   r   r   r   r   rb   rb      s         
- 
- 
-- - -
- 
- 
-
. 
. 
.	* 	* 	** * */ / // / / / /r   rb   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
	TestEmptyc                 t   t                               |            t          j        t          j                  }t
          j                                        }|                    d           t          j        | j
        j        d||          }t          j        t          j        d                    | _        d S )Nr8   r   S10)r   r   r   createNULLr   C_S1copyset_sizer   r   r   r;   Emptyr$   r"   	empty_obj)r   sidr   r   s       r   r   zTestEmpty.setUp   s|    j""hmmooRjD#s33BHUOO44r   c                 \    |                      | j        | j        j        d                    d S Nr#   )r0   r   r   r'   r   s    r   	test_readzTestEmpty.test_read   s4    NDFL-	
 	
 	
 	
 	
r   c                     | j         | j        j        d<   |                     t	          t          j        | j        j        d                               d S )Ny   y)r   r   r'   r   r
   r   r   r   r   s    r   
test_writezTestEmpty.test_write  sC     NS*38DFIt+D+DEEFFFFFr   c                     |                      t                    5  | j        j                            dd           d d d            d S # 1 swxY w Y   d S )Nr#   r   )assertRaisesOSErrorr   r'   modifyr   s    r   test_modifyzTestEmpty.test_modify  s    w'' 	( 	(FLQ'''	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   !A		AAc                     t          | j        j                                                  }|                     | j        g|           d S r   r>   r   r'   valuesr0   r   r   r   s     r   test_valueszTestEmpty.test_values  sK    dfl))++,,^f	
 	
 	
 	
 	
r   c                     t          | j        j                                                  }|                     d| j        fg|           d S r   r>   r   r'   itemsr0   r   r   r   s     r   
test_itemszTestEmpty.test_items  P    TV\''))**DN#$e	
 	
 	
 	
 	
r   c                     t          | j        j                                                  }|                     | j        g|           d S r   r   r   s     r   test_itervalueszTestEmpty.test_itervalues  sK    dfl))++,,^f	
 	
 	
 	
 	
r   c                     t          | j        j                                                  }|                     d| j        fg|           d S r   r   r   s     r   test_iteritemszTestEmpty.test_iteritems  r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s        5 5 5
 
 

G G G( ( (
 
 

 
 

 
 

 
 
 
 
r   r   c                       e Zd ZdZd ZdS )TestWriteExceptionzH
        Ensure failed attribute writes don't leave garbage behind.
    c                     d}	 || j         j        d<   n# t          $ r Y nw xY w|                     t                    5  | j         j        d          ddd           dS # 1 swxY w Y   dS )z0 ValueError on string write wipes out attribute s   Hello Hellor#   N)r   r'   
ValueErrorr   KeyError)r   ss     r   r   zTestWriteException.test_write,  s     	 !DFL 	 	 	D	 x(( 	 	FL	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    
!!AA"%A"N)r   r   r   rT   r   r   r   r   r   r   &  s-             r   r   )rT   numpyr$   commonr   r   r;   r   r   r   r	   h5py._hl.baser
   r   r   rV   rb   r   r   r   r   r   <module>r      s                                         , , , , , ,       E@ E@ E@ E@ E@ E@ E@ E@P) ) ) ) )	 ) ) )4l/ l/ l/ l/ l/	 l/ l/ l/^.
 .
 .
 .
 .
	 .
 .
 .
b         r   