B
    ¬»ˆdi%  ã               @   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               @   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   úG/var/www/html/venv/lib/python3.7/site-packages/h5py/tests/test_attrs.pyÚsetUp    s    zBaseAttrs.setUpc             C   s   | j r| j  ¡  d S )N)r   Úclose)r   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ÚgrpZattr   )	r   Úcreate_groupÚattrsÚcreateZ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 g      @ÚaN)r   r   ÚassertEqualÚlistÚkeys)r   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"   g      @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"   é   N)r   r   r#   r$   r%   )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Q R X 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 g      @r"   g      @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 )g      @g      @r"   )é   N)r   r   r#   ÚshapeÚassertArrayEqualr.   Úarray)r   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)r.   Zonesr   r   r#   r6   )r   Úoutr   r   r   Útest_singleq   s    zTestAccess.test_singlec          	   C   s&   |   t¡ | jjd  W dQ R X dS )z0 Attempt to access missing item raises KeyError r"   N)r0   ÚKeyErrorr   r   )r   r   r   r   Útest_access_excx   s    zTestAccess.test_access_excc          	   C   sR   d| j jd< | j j d¡}t|tjƒs*t‚|  t¡ | j j d¡ W d Q R X d S )Ng      @r"   r+   )	r   r   Zget_idÚ
isinstancer   ZAttrIDÚAssertionErrorr0   r<   )r   Úaidr   r   r   Útest_get_id}   s
    zTestAccess.test_get_idN)r   r   r   r    r&   r'   r*   r3   r4   r9   r;   r=   rA   r   r   r   r   r!   5   s   	r!   c               @   s    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" g      @r"   N)r   r   ÚassertInÚassertNotIn)r   r   r   r   Útest_delete‹   s    
zTestDelete.test_deletec          	   C   s$   |   t¡ | jjd= W dQ R X dS )z0 Attempt to delete missing item raises KeyError r"   N)r0   r<   r   r   )r   r   r   r   Útest_delete_exc’   s    zTestDelete.test_delete_excN)r   r   r   r    rE   rF   r   r   r   r   rB   …   s   rB   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   asciiN)r   r   r#   )r   r:   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-asciiþrH   N)r   r   r#   )r   Únamer:   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©  rH   N)Úchrr   r   r#   )r   rJ   r:   r   r   r   Útest_unicode«   s    zTestUnicode.test_unicodeN)r   r   r   r    rI   rK   rN   r   r   r   r   rG   ˜   s   rG   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )Ú
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ÚxrH   )Údtypeó   xN)r.   rS   r   r   r   r#   r   Úopenr   Úget_typeÚ
assertTrueZ	committed)r   r@   ZhtypeZ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    rX   r\   r   r   r   r   rO   ³   s   rO   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestMutableMappingz^Tests if the registration of AttributeManager as a MutableMapping
    behaves as expected
    c             C   s$   t ttƒst‚t| jjtƒs t‚d S )N)Ú
issubclassr	   r   r?   r>   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    r_   re   r   r   r   r   r]   Ï   s   r]   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú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)   )rS   r"   r   )	r.   r8   r/   r   Ú
vlen_dtypeÚintr   r   r7   )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 )NZS1)r   )rS   ó   aó   br   Útest)
rZ   rg   r.   rS   rY   r8   r   r   r   r7   )r   Údtr"   r   r   r   Útest_vlen_s1è   s
    zTestVlen.test_vlen_s1N)r   r   r   ri   rn   r   r   r   r   rf   á   s   rf   c               @   s\   e Zd Zdd„ Ze ejjdkd¡dd„ ƒZ	dd„ Z
d	d
„ Ze ejjdkd¡dd„ ƒZdS )ÚTestTrackOrderc             C   s4   | j jd|dj}xtdƒD ]}||t|ƒ< qW |S )Nrl   )Útrack_orderéd   )r   r   r   Úranger   )r   rp   r   Úir   r   r   Ú
fill_attrsò   s    zTestTrackOrder.fill_attrs)r   é
   é   zHDF5 1.10.6 requiredc             C   s.   | j dd}|  t|ƒdd„ tdƒD ƒ¡ d S )NT)rp   c             S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0rs   r   r   r   ú
<listcomp>ý   s    z3TestTrackOrder.test_track_order.<locals>.<listcomp>rq   )rt   r#   r$   rr   )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 )NF)rp   c             S   s   g | ]}t |ƒ‘qS r   )r   )rw   rs   r   r   r   rx     s    z6TestTrackOrder.test_no_track_order.<locals>.<listcomp>rq   )rt   r#   r$   Úsortedrr   )r   r   r   r   r   Útest_no_track_orderÿ   s    
z"TestTrackOrder.test_no_track_orderc             C   s4   | j jd|d}xtdƒD ]}||jt|ƒ< qW |S )Nrl   )rp   é   )r   r   rr   r   r   )r   rp   Úgrouprs   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 )NT)rp   Z11é   g      E@Ú10)r~   r#   r   rC   rD   )r   r}   r   r   r   Ú!test_track_order_overwrite_delete
  s    
z0TestTrackOrder.test_track_order_overwrite_deleteN)r   r   r   rt   r   Z
skipUnlessrZ   ÚversionZhdf5_version_tuplery   r{   r~   r   r   r   r   r   ro   ñ   s
   ro   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   Zfoor"   g      @)	r.   rS   r   r#   r$   r   r%   r   Úvalues)r   rm   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sTt‚t j	 
|jd t j|t jd¡ |j d|¡ t j	 
|jd t j|t jd¡ d S )Nr   r"   )rS   )r.   ZiinfoZint64Úmaxr   r   Zuint64rS   r?   ÚtestingZassert_array_equalr8   r-   )Zwritable_filer   Údatar   r   r   Útest_python_int_uint64"  s      r‰   )r    Únumpyr.   Úcollections.abcr   Úcommonr   r   rZ   r   r   r   r	   r
   r   r!   rB   rG   rO   r]   rf   ro   rƒ   r‰   r   r   r   r   Ú<module>   s$   	P'
