o
    bi$                     @   s  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
 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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d ZdS )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d Zdd ZdS )	BaseAttrsc                 C   s   t |  d| _d S )Nw)r   mktempfself r   I/home/ubuntu/.local/lib/python3.10/site-packages/h5py/tests/test_attrs.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                   @   s   e Zd ZdZdd ZdS )TestReprzI Feature: AttributeManager provide a helpful
        __repr__ string
    c                 C   sL   | j d}|jdd | t|jt |j  | t|jt d S )Ngrpattr   )	r   create_groupattrscreateassertIsInstancereprstridr   )r   r   r   r   r   	test_repr-   s
   
zTestRepr.test_reprN)r   r   r   __doc__r$   r   r   r   r   r   '   s    r   c                   @   sX   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d ZdS )
TestAccesszG
        Feature: Attribute creation/retrieval via special methods
    c                 C   s>   d| j jd< | t| j j dg | | j jd d dS )z) Attribute creation by direct assignment       @aNr   r   assertEquallistkeysr   r   r   r   test_create;   s   zTestAccess.test_createc                 C   sB   | j jdd | t| j j dg | | j jd d dS )z' Attribute creation by create() method r(   r'   N)r   r   r   r*   r+   r,   r   r   r   r   test_create_2A   s   zTestAccess.test_create_2c                 C   sx   d| j jd< | t| j j dg | | j jd d d| j jd< | t| j j dg | | j jd d dS )z- Attributes are modified by direct assignment   r(      Nr)   r   r   r   r   test_modifyG   s   zTestAccess.test_modifyc                 C   s  | j jdd | t| j j dg | | j jd d | j jdd | t| j j dg | | j jd d | j jdd | t| j j ddg | | j jd d | | j jd d td}| t	 | j jd| W d   dS 1 sw   Y  dS )z, Attributes are modified by modify() method r(   r/   r0   b   N)
r   r   modifyr*   r+   r,   nparangeassertRaises	TypeError)r   	new_valuer   r   r   test_modify_2P   s   
"zTestAccess.test_modify_2c                 C   s0   d| j jd< d| j jd< | | j jd d dS )z% Attributes are silently overwritten r'   r(         @Nr   r   r*   r   r   r   r   test_overwritee   s   zTestAccess.test_overwritec                 C   s@   d| j jd< | | j jd jd | | j jd td dS )z Attribute rank is preserved )r'   r;   r(   )   N)r   r   r*   shapeassertArrayEqualr5   arrayr   r   r   r   	test_rankk   s   zTestAccess.test_rankc                 C   s@   t d| jjd< | jjd }| |jd | |d d dS )z/ Attributes of shape (1,) don't become scalars r   r(   r   r   N)r5   onesr   r   r*   r?   r   outr   r   r   test_singleq   s   zTestAccess.test_singlec                 C   s<   |  t | jjd  W d   dS 1 sw   Y  dS )z0 Attempt to access missing item raises KeyError r(   Nr7   KeyErrorr   r   r   r   r   r   test_access_excx   s   "zTestAccess.test_access_excc                 C   sh   d| j jd< | j jd}t|tjsJ | t | j jd W d    d S 1 s-w   Y  d S )Nr'   r(   r2   )r   r   get_id
isinstancer   AttrIDr7   rI   )r   aidr   r   r   test_get_id}   s   "zTestAccess.test_get_idN)r   r   r   r%   r-   r.   r1   r:   r=   rB   rG   rJ   rO   r   r   r   r   r&   5   s    	r&   c                   @       e Zd ZdZdd Zdd ZdS )
TestDeletez?
        Feature: Deletion of attributes using __delitem__
    c                 C   s:   d| j jd< | d| j j | j jd= | d| j j dS )z Deletion via "del" r'   r(   N)r   r   assertInassertNotInr   r   r   r   test_delete   s   
zTestDelete.test_deletec                 C   s:   |  t | jjd= W d   dS 1 sw   Y  dS )z0 Attempt to delete missing item raises KeyError r(   NrH   r   r   r   r   test_delete_exc   s   "zTestDelete.test_delete_excN)r   r   r   r%   rT   rU   r   r   r   r   rQ      s    rQ   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	TestUnicodezM
        Feature: Attributes can be accessed via Unicode or byte strings
    c                 C   s(   d| j jd< | j jd }| |d dS )z# Access via pure-ASCII byte string *   s   asciiNr<   rE   r   r   r   
test_ascii   s   zTestUnicode.test_asciic                 C   s,   d}d| j j|< | j j| }| |d dS )z" Access via non-ASCII byte string s
   non-asciirW   Nr<   r   namerF   r   r   r   test_raw   s   zTestUnicode.test_rawc                 C   s4   dt d }d| jj|< | jj| }| |d dS )z5 Access via Unicode string with non-ascii characters Omegai  rW   N)chrr   r   r*   rY   r   r   r   test_unicode   s   zTestUnicode.test_unicodeN)r   r   r   r%   rX   r[   r^   r   r   r   r   rV      s
    rV   c                   @   rP   )
TestCreatez5
        Options for explicit attribute creation
    c                 C   s   t d| jd< | jjjdd| jd d | | jjd d t| jjd}|	 }| jd j}| || | 
|  dS )zL Attributes created from named types link to the source type object
        u8typexrW   dtype   xN)r5   rd   r   r   r   r*   r   openr#   get_type
assertTrue	committed)r   rN   htypehtype2r   r   r   
test_named   s   zTestCreate.test_namedc                 C   sd   | j jdtd | | j jd td | j jdtd | | j jd td dS )z0 Create attribute with h5py.Empty value
        emptyr   N)r   r   r   h5pyEmptyr*   r   r   r   r   
test_empty   s   zTestCreate.test_emptyN)r   r   r   r%   rl   rp   r   r   r   r   r_      s    r_   c                   @   rP   )TestMutableMappingz^Tests if the registration of AttributeManager as a MutableMapping
    behaves as expected
    c                 C   s$   t ttsJ t| jjtsJ d S r   )
issubclassr	   r   rL   r   r   r   r   r   r   test_resolution   s   z"TestMutableMapping.test_resolutionc                 C   s"   t j t j t j t j t j dS )zC
        Test that the required functions are implemented.
        N)r	   __getitem____setitem____delitem____iter____len__r   r   r   r   test_validity   s
   
z TestMutableMapping.test_validityN)r   r   r   r%   rs   ry   r   r   r   r   rq      s    rq   c                   @   r
   )TestVlenc                 C   sP   t jt dt dgttd}|| jjd< | | jjd d |d  d S )Nr/   r0   rc   r(   r   )	r5   rA   r6   r   
vlen_dtypeintr   r   r@   )r   r(   r   r   r   	test_vlen   s
    zTestVlen.test_vlenc                 C   sd   t td}tjd|d}tjddgdd|d< | jjd| | 	| jjd d |d  d S )NS1rC   rc      a   br   test)
rn   r{   r5   rd   rm   rA   r   r   r   r@   )r   dtr(   r   r   r   test_vlen_s1   s
    zTestVlen.test_vlen_s1N)r   r   r   r}   r   r   r   r   r   rz      s    rz   c                   @   s4   e Zd Zdd Zdd Zdd Zdd Zd	d
 ZdS )TestTrackOrderc                 C   s0   | j jd|dj}tdD ]}||t|< q|S )Nr   track_orderd   )r   r   r   ranger"   )r   r   r   ir   r   r   
fill_attrs   s   zTestTrackOrder.fill_attrsc                 C   s.   | j dd}| t|dd tdD  d S )NTr   c                 S      g | ]}t |qS r   r"   .0r   r   r   r   
<listcomp>       z3TestTrackOrder.test_track_order.<locals>.<listcomp>r   )r   r*   r+   r   r   r   r   r   r   test_track_order   s   
zTestTrackOrder.test_track_orderc                 C   s2   | j dd}| t|tdd tdD  d S )NFr   c                 S   r   r   r   r   r   r   r   r     r   z6TestTrackOrder.test_no_track_order.<locals>.<listcomp>r   )r   r*   r+   sortedr   r   r   r   r   test_no_track_order   s   
z"TestTrackOrder.test_no_track_orderc                 C   s0   | j jd|d}tdD ]	}||jt|< q|S )Nr   r      )r   r   r   r   r"   )r   r   groupr   r   r   r   fill_attrs2  s   zTestTrackOrder.fill_attrs2c                 C   sb   | j dd}| |jd d d|jd< | |jd d | d|j |jd= | d|j d S )NTr   11   g      E@10)r   r*   r   rR   rS   )r   r   r   r   r   !test_track_order_overwrite_delete	  s   
z0TestTrackOrder.test_track_order_overwrite_deleteN)r   r   r   r   r   r   r   r   r   r   r   r   r      s    r   c                   @   s   e Zd Zdd ZdS )TestDatatypec                 C   sr   t d| jd< | jd }| t|j g  |jdd | t|j dg | t|j dg d S )Nr   foor(   r'   )	r5   rd   r   r*   r+   r   r,   r   values)r   r   r   r   r   test_datatype  s   
zTestDatatype.test_datatypeN)r   r   r   r   r   r   r   r   r     s    r   c                 C   s   | }t t jjt t jjd g}|jjd|t jd |jd jt t jks*J t j	|jd t j
|t jd |jd| t j	|jd t j
|t jd d S )Nr   r(   rc   )r5   iinfoint64maxr   r   uint64rd   testingassert_array_equalrA   r4   )writable_filer   datar   r   r   test_python_int_uint64   s     $r   )r%   numpyr5   collections.abcr   commonr   r   rn   r   r   r   r	   r   r   r&   rQ   rV   r_   rq   rz   r   r   r   r   r   r   r   <module>   s&   		P%
