3
_½µ_Š!  ã               @   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 | jƒ dƒ| _d S )NÚw)r   ÚmktempÚf)Úself© r   ú7/tmp/pip-install-xpigntgx/h5py/h5py/tests/test_attrs.pyÚsetUp    s    zBaseAttrs.setUpc             C   s   | j r| j 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 jdƒ}|jjddƒ | jt|jƒtƒ |jjƒ  | 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< | jt| j jjƒ ƒdgƒ | j| 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jddƒ | jt| j jjƒ ƒdgƒ | j| 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< | 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ƒ 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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	ƒ� | j 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   Z	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 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 jd jdƒ | j| j jd tjdƒƒ dS )	z Attribute rank is preserved ç      @ç      @r"   é   N)r4   r5   )r6   )r4   r5   )r   r   r#   ÚshapeÚassertArrayEqualr.   Úarray)r   r   r   r   Ú	test_rankk   s    zTestAccess.test_rankc             C   s@   t jdƒ| jjd< | jjd }| j|jdƒ | j|f  dƒ dS )z/ Attributes of shape (1,) don't become scalars r   r"   N)r   )r   )r.   Zonesr   r   r#   r7   )r   Úoutr   r   r   Útest_singleq   s    zTestAccess.test_singlec          	   C   s&   | j 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jdƒ}t|tjƒs*t‚| jtƒ� | j 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*   r2   r3   r:   r<   r>   rB   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< | jd| j jƒ | j jd= | jd| j jƒ dS )z Deletion via "del" g      @r"   N)r   r   ZassertInZassertNotIn)r   r   r   r   Útest_delete‹   s    
zTestDelete.test_deletec          	   C   s$   | j 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    rD   rE   r   r   r   r   rC   …   s   rC   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 }| j|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| }| j|dƒ dS )z" Access via non-ASCII byte string s
   non-asciiþrG   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| }| j|dƒ dS )z5 Access via Unicode string with non-ascii characters ÚOmegai©  rG   N)Úchrr   r   r#   )r   rI   r;   r   r   r   Útest_unicode«   s    zTestUnicode.test_unicodeN)r   r   r   r    rH   rJ   rM   r   r   r   r   rF   ˜   s   rF   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 jdƒ| jd< | jjjdd| jd d� | j| jjd dƒ tj| jjdƒ}|j	ƒ }| jd j}| j||ƒ | j
|jƒ ƒ dS )zL Attributes created from named types link to the source type object
        Úu8ÚtypeÚxrG   )Údtypeó   xN)r.   rR   r   r   r   r#   r   Úopenr   Úget_typeZ
assertTrueZ	committed)r   rA   ZhtypeZhtype2r   r   r   Ú
test_named¹   s    zTestCreate.test_namedc             C   sd   | 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ƒƒ 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    rV   rZ   r   r   r   r   rN   ³   s   rN   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]   rc   r   r   r   r   r[   Ï   s   r[   c               @   s   e Zd Zdd„ ZdS )ÚTestVlenc             C   sP   t jt jdƒt jdƒgtjtƒd�}|| jjd< | j| jjd d |d ƒ d S )Nr(   r)   )rR   r"   r   )	r.   r9   r/   r   Z
vlen_dtypeÚintr   r   r8   )r   r"   r   r   r   Ú	test_vlenâ   s    zTestVlen.test_vlenN)r   r   r   rf   r   r   r   r   rd   á   s   rd   c               @   s8   e Zd Zdd„ Zejejjdkdƒdd„ ƒZ	d	d
„ Z
dS )ÚTestTrackOrderc             C   s4   | j jd|d�j}xtdƒD ]}||t|ƒ< qW |S )NÚtest)Útrack_orderéd   )r   r   r   Úranger   )r   ri   r   Úir   r   r   Ú
fill_attrsé   s    zTestTrackOrder.fill_attrsr   é
   é   zHDF5 1.10.6 requiredc             C   s.   | j dd�}| jt|ƒdd„ tdƒD ƒƒ d S )NT)ri   c             S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0rl   r   r   r   ú
<listcomp>ô   s    z3TestTrackOrder.test_track_order.<locals>.<listcomp>rj   )rm   r#   r$   rk   )r   r   r   r   r   Útest_track_orderï   s    
zTestTrackOrder.test_track_orderc             C   s2   | j dd�}| jt|ƒtdd„ tdƒD ƒƒƒ d S )NF)ri   c             S   s   g | ]}t |ƒ‘qS r   )r   )rp   rl   r   r   r   rq   ù   s    z6TestTrackOrder.test_no_track_order.<locals>.<listcomp>rj   )rm   r#   r$   Úsortedrk   )r   r   r   r   r   Útest_no_track_orderö   s    
z"TestTrackOrder.test_no_track_orderN)r   rn   ro   )r   r   r   rm   r   Z
skipUnlessrX   ÚversionZhdf5_version_tuplerr   rt   r   r   r   r   rg   è   s   rg   c               @   s   e Zd Zdd„ ZdS )ÚTestDatatypec             C   sr   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ƒ d S )Nr   Zfoor"   g      @)	r.   rR   r   r#   r$   r   r%   r   Úvalues)r   Údtr   r   r   Útest_datatypeþ   s    
zTestDatatype.test_datatypeN)r   r   r   ry   r   r   r   r   rv   ü   s   rv   c             C   s¦   | }t jt jƒjt jt jƒjd g}|jjd|t jd� |jd jt jt jƒksTt‚t j	j
|jd t j|t jd�ƒ |jjd|ƒ t j	j
|jd t j|t jd�ƒ d S )Nr   r"   )rR   )r.   ZiinfoZint64Úmaxr   r   Zuint64rR   r@   ZtestingZassert_array_equalr9   r-   )Zwritable_filer   Údatar   r   r   Útest_python_int_uint64  s      r|   )r    Znumpyr.   Úcollections.abcr   Úcommonr   r   rX   r   r   r   r	   r
   r   r!   rC   rF   rN   r[   rd   rg   rv   r|   r   r   r   r   Ú<module>   s$   	P
