
    1Vh$                     >   d Z ddlZddlmZ ddlmZmZ ddlZddlm	Z	 ddlm
Z
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 G d de      Z G d de      Z G d de      Z G d de      Zd Zy)z
    Attributes testing module

    Covers all operations which access the .attrs property, with the
    exception of data read/write and type conversion.  Those operations
    are tested by module test_attrs_data.
    N)MutableMapping   )TestCaseut)File)h5ah5t)AttributeManagerc                       e Zd Zd Zd Zy)	BaseAttrsc                 B    t        | j                         d      | _        y )Nw)r   mktempfselfs    E/home/dcms/DCMS/lib/python3.12/site-packages/h5py/tests/test_attrs.pysetUpzBaseAttrs.setUp    s    dkkmS)    c                 R    | j                   r| j                   j                          y y N)r   closer   s    r   tearDownzBaseAttrs.tearDown#   s    66FFLLN r   N)__name__
__module____qualname__r   r    r   r   r   r      s    *r   r   c                       e Zd ZdZd Zy)TestReprzI Feature: AttributeManager provide a helpful
        __repr__ string
    c                 J   | j                   j                  d      }|j                  j                  dd       | j	                  t        |j                        t               |j                  j                          | j	                  t        |j                        t               y )Ngrpattr   )	r   create_groupattrscreateassertIsInstancereprstridr   )r   r!   s     r   	test_reprzTestRepr.test_repr-   sg    ff!!%(		"d399os3d399os3r   N)r   r   r   __doc__r*   r   r   r   r   r   '   s    4r   r   c                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)
TestAccesszG
        Feature: Attribute creation/retrieval via special methods
    c                    d| j                   j                  d<   | j                  t        | j                   j                  j	                               dg       | j                  | j                   j                  d   d       y)z) Attribute creation by direct assignment       @aNr   r$   assertEquallistkeysr   s    r   test_createzTestAccess.test_create;   sY    Sdffll//12SE:c*C0r   c                    | j                   j                  j                  dd       | j                  t	        | j                   j                  j                               dg       | j                  | j                   j                  d   d       y)z' Attribute creation by create() method r0   r/   N)r   r$   r%   r2   r3   r4   r   s    r   test_create_2zTestAccess.test_create_2A   s_    C%dffll//12SE:c*C0r   c                    d| j                   j                  d<   | j                  t        | j                   j                  j	                               dg       | j                  | j                   j                  d   d       d| j                   j                  d<   | j                  t        | j                   j                  j	                               dg       | j                  | j                   j                  d   d       y)z- Attributes are modified by direct assignment   r0      Nr1   r   s    r   test_modifyzTestAccess.test_modifyG   s    Sdffll//12SE:c*A.Sdffll//12SE:c*A.r   c                 p   | j                   j                  j                  dd       | j                  t	        | j                   j                  j                               dg       | j                  | j                   j                  d   d       | j                   j                  j                  dd       | j                  t	        | j                   j                  j                               dg       | j                  | j                   j                  d   d       | j                   j                  j                  dd       | j                  t	        | j                   j                  j                               ddg       | j                  | j                   j                  d   d       | j                  | j                   j                  d   d       t        j                  d      }| j                  t              5  | j                   j                  j                  d|       ddd       y# 1 sw Y   yxY w)z, Attributes are modified by modify() method r0   r9   r:   b   N)
r   r$   modifyr2   r3   r4   nparangeassertRaises	TypeError)r   	new_values     r   test_modify_2zTestAccess.test_modify_2P   s   C"dffll//12SE:c*A.C#dffll//12SE:c*A. 	C#dffll//12S#J?c*A.c*A. IIaL	y) 	0FFLLY/	0 	0 	0s   <'H,,H5c                     d| j                   j                  d<   d| j                   j                  d<   | j                  | j                   j                  d   d       y)z% Attributes are silently overwritten r/   r0         @Nr   r$   r2   r   s    r   test_overwritezTestAccess.test_overwritee   sC    SSc*C0r   c                    d| j                   j                  d<   | j                  | j                   j                  d   j                  d       | j	                  | j                   j                  d   t        j                  d             y)z Attribute rank is preserved )r/   rG   r0   )   N)r   r$   r2   shapeassertArrayEqualr@   arrayr   s    r   	test_rankzTestAccess.test_rankk   s]    &Sc*00$7dffll3/)1DEr   c                     t        j                  d      | j                  j                  d<   | j                  j                  d   }| j	                  |j
                  d       | j	                  |d   d       y)z/ Attributes of shape (1,) don't become scalars r   r0   r   r   N)r@   onesr   r$   r2   rL   r   outs     r   test_singlezTestAccess.test_singleq   sV    GGDMSffll3D)R!$r   c                     | j                  t              5  | j                  j                  d    ddd       y# 1 sw Y   yxY w)z0 Attempt to access missing item raises KeyError r0   NrB   KeyErrorr   r$   r   s    r   test_access_exczTestAccess.test_access_excx   s5    x( 	FFLL	 	 	s	   9Ac                 V   d| j                   j                  d<   | j                   j                  j                  d      }t        |t        j
                        sJ | j                  t              5  | j                   j                  j                  d       d d d        y # 1 sw Y   y xY w)Nr/   r0   r=   )r   r$   get_id
isinstancer   AttrIDrB   rX   )r   aids     r   test_get_idzTestAccess.test_get_id}   sy    Sffll!!#&#szz***x( 	%FFLL$	% 	% 	%s   0&BB(N)r   r   r   r+   r5   r7   r;   rE   rI   rO   rU   rY   r_   r   r   r   r-   r-   5   s5    11/0*1F%
%r   r-   c                       e Zd ZdZd Zd Zy)
TestDeletez?
        Feature: Deletion of attributes using __delitem__
    c                     d| j                   j                  d<   | j                  d| j                   j                         | j                   j                  d= | j                  d| j                   j                         y)z Deletion via "del" r/   r0   N)r   r$   assertInassertNotInr   s    r   test_deletezTestDelete.test_delete   sR    Sc466<<(FFLLdffll+r   c                     | j                  t              5  | j                  j                  d= ddd       y# 1 sw Y   yxY w)z0 Attempt to delete missing item raises KeyError r0   NrW   r   s    r   test_delete_exczTestDelete.test_delete_exc   s5    x( 	"S!	" 	" 	"s	   7A N)r   r   r   r+   re   rg   r   r   r   ra   ra      s    ,"r   ra   c                   "    e Zd ZdZd Zd Zd Zy)TestUnicodezM
        Feature: Attributes can be accessed via Unicode or byte strings
    c                     d| j                   j                  d<   | j                   j                  d   }| j                  |d       y)z# Access via pure-ASCII byte string *   s   asciiNrH   rS   s     r   
test_asciizTestUnicode.test_ascii   s6    !#Xffll8$b!r   c                     d}d| j                   j                  |<   | j                   j                  |   }| j                  |d       y)z" Access via non-ASCII byte string s
   non-asciirk   NrH   r   namerT   s      r   test_rawzTestUnicode.test_raw   s;    Tffll4 b!r   c                     dt        d      z   }d| j                  j                  |<   | j                  j                  |   }| j                  |d       y)z5 Access via Unicode string with non-ascii characters Omegai  rk   N)chrr   r$   r2   rn   s      r   test_unicodezTestUnicode.test_unicode   sD    V$Tffll4 b!r   N)r   r   r   r+   rl   rp   rt   r   r   r   ri   ri      s    """r   ri   c                       e Zd ZdZd Zd Zy)
TestCreatez5
        Options for explicit attribute creation
    c                    t        j                  d      | j                  d<   | j                  j                  j	                  dd| j                  d          | j                  | j                  j                  d   d       t        j                  | j                  j                  d      }|j                         }| j                  d   j                  }| j                  ||       | j                  |j                                y)zL Attributes created from named types link to the source type object
        u8typexrk   dtype   xN)r@   r|   r   r$   r%   r2   r   openr)   get_type
assertTrue	committed)r   r^   htypehtype2s       r   
test_namedzTestCreate.test_named   s     $vC466&>:c*B/hhtvvyy$'""')*r   c                    | j                   j                  j                  dt        j                  d             | j                  | j                   j                  d   t        j                  d             | j                   j                  j                  dt        j                  d             | j                  | j                   j                  d   t        j                  d             y)z0 Create attribute with h5py.Empty value
        emptyr   N)r   r$   r%   h5pyEmptyr2   r   s    r   
test_emptyzTestCreate.test_empty   s     	GTZZ_5g.

3@GTZZ%56g.

40@Ar   N)r   r   r   r+   r   r   r   r   r   rv   rv      s    
+Br   rv   c                       e Zd ZdZd Zd Zy)TestMutableMappingz^Tests if the registration of AttributeManager as a MutableMapping
    behaves as expected
    c                 |    t        t        t              sJ t        | j                  j
                  t              sJ y r   )
issubclassr
   r   r\   r   r$   r   s    r   test_resolutionz"TestMutableMapping.test_resolution   s+    *N;;;$&&,,777r   c                     t         j                   t         j                   t         j                   t         j                   t         j
                   y)zC
        Test that the required functions are implemented.
        N)r
   __getitem____setitem____delitem____iter____len__r   s    r   test_validityz TestMutableMapping.test_validity   s1     	$$$$$$!!  r   N)r   r   r   r+   r   r   r   r   r   r   r      s    8!r   r   c                       e Zd Zd Zd Zy)TestVlenc                 @   t        j                  t        j                  d      t        j                  d      gt        j                  t
                    }|| j                  j                  d<   | j                  | j                  j                  d   d   |d          y )Nr9   r:   r{   r0   r   )	r@   rN   rA   r	   
vlen_dtypeintr   r$   rM   )r   r0   s     r   	test_vlenzTestVlen.test_vlen   sk    HHbiilBIIaL1..%'Sdffll3/2AaD9r   c                 d   t        j                  t        j                  d            }t        j                  d|      }t        j
                  ddgd      |d<   | j                  j                  j                  d|       | j                  | j                  j                  d   d   |d          y )NS1rQ   r{      a   br   test)
r   r   r@   r|   r   rN   r   r$   r%   rM   )r   dtr0   s      r   test_vlen_s1zTestVlen.test_vlen_s1   s~    __RXXd^,HHT$xxtD1!FA&dffll6215qt<r   N)r   r   r   r   r   r   r   r   r   r      s    :=r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestTrackOrderc                     | j                   j                  d|      j                  }t        d      D ]  }||t	        |      <    |S )Nr   track_orderd   )r   r#   r$   ranger(   )r   r   r$   is       r   
fill_attrszTestTrackOrder.fill_attrs   sF    ##F#DJJs 	AE#a&M	r   c           	          | j                  d      }| j                  t        |      t        d      D cg c]  }t	        |       c}       y c c}w )NTr   r   )r   r2   r3   r   r(   r   r$   r   s      r   test_track_orderzTestTrackOrder.test_track_order   s?    D1e*/*5Q#a&5	75s   A
c                     | j                  d      }| j                  t        |      t        t	        d      D cg c]  }t        |       c}             y c c}w )NFr   r   )r   r2   r3   sortedr   r(   r   s      r   test_no_track_orderz"TestTrackOrder.test_no_track_order   sD    E2es <AQ <=	? <s   Ac                     | j                   j                  d|      }t        d      D ]  }||j                  t	        |      <    |S )Nr   r      )r   r#   r   r$   r(   )r   r   groupr   s       r   fill_attrs2zTestTrackOrder.fill_attrs2  sE    ##F#Dr 	$A"#EKKA	$r   c                 L   | j                  d      }| j                  |j                  d   d       d|j                  d<   | j                  |j                  d   d       | j                  d|j                         |j                  d= | j	                  d|j                         y )NTr   11   g      E@10)r   r2   r$   rc   rd   )r   r   s     r   !test_track_order_overwrite_deletez0TestTrackOrder.test_track_order_overwrite_delete	  s      T 2T*B/ DT*D1dEKK(KKu{{+r   N)r   r   r   r   r   r   r   r   r   r   r   r   r      s    7
?

,r   r   c                       e Zd Zd Zy)TestDatatypec                    t        j                  d      | j                  d<   | j                  d   }| j                  t	        |j
                  j                               g        |j
                  j                  dd       | j                  t	        |j
                  j                               dg       | j                  t	        |j
                  j                               dg       y )Nr   foor0   r/   )	r@   r|   r   r2   r3   r$   r4   r%   values)r   r   s     r   test_datatypezTestDatatype.test_datatype  s    uVVE]bhhmmo.3
S!bhhmmo.6bhhoo/03%8r   N)r   r   r   r   r   r   r   r   r     s    9r   r   c                    | }t        j                  t         j                        j                  t        j                  t         j                        j                  dz   g}|j                  j                  d|t         j                         |j                  d   j                  t        j                  t         j                        k(  sJ t         j                  j                  |j                  d   t        j                  |t         j                               |j                  j                  d|       t         j                  j                  |j                  d   t        j                  |t         j                               y )Nr   r0   r{   )r@   iinfoint64maxr$   r%   uint64r|   testingassert_array_equalrN   r?   )writable_filer   datas      r   test_python_int_uint64r      s    AHHRXX""BHHRXX$6$:$:Q$>?D GGNN3BIIN.773<"))!4444JJ!!!''#,RYY0OP GGNN3JJ!!!''#,RYY0OPr   )r+   numpyr@   collections.abcr   commonr   r   r   r   r   r	   r
   r   r   r-   ra   ri   rv   r   r   r   r   r   r   r   r   <module>r      s     *      ! 4x 4N% N%`" "&") "6B B8! !$=y = ",Y ",J99 9Qr   