o
    2h$                     @   s   d Z ddlZddlmZ ddl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)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   P/var/www/html/chatgem/venv/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.   r/   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assertArrayEqualr4   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)r4   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r6   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'   r1   )r   r   get_id
isinstancer   AttrIDr6   rH   )r   aidr   r   r   test_get_id}   s   "zTestAccess.test_get_idN)r   r   r   r$   r,   r-   r0   r9   r<   rA   rF   rI   rN   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'   NrG   r   r   r   r   test_delete_exc   s   "zTestDelete.test_delete_excN)r   r   r   r$   rS   rT   r   r   r   r   rP      s    rP   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;   rD   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-asciirV   Nr;   r   namerE   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  rV   N)chrr   r   r)   rX   r   r   r   test_unicode   s   zTestUnicode.test_unicodeN)r   r   r   r$   rW   rZ   r]   r   r   r   r   rU      s
    rU   c                   @   rO   )
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xrV   dtype   xN)r4   rc   r   r   r   r)   r   openr"   get_type
assertTrue	committed)r   rM   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$   rk   ro   r   r   r   r   r^      s    r^   c                   @   rO   )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   rK   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$   rr   rx   r   r   r   r   rp      s    rp   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.   r/   rb   r'   r   )	r4   r@   r5   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S1rB   rb      a   br   test)
rm   rz   r4   rc   rl   r@   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   ry      s    ry   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   rQ   rR   )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&   )	r4   rc   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'   rb   )r4   iinfoint64maxr   r   uint64rc   testingassert_array_equalr@   r3   )writable_filer   datar   r   r   test_python_int_uint64   s     $r   )r$   numpyr4   collections.abcr   commonr   rm   r   r   r   r   r
   r   r%   rP   rU   r^   rp   ry   r   r   r   r   r   r   r   <module>   s&   		P%
