3
_½µ_è  ã               @   s¨   d Z ddlmZ ddlmZmZ ddlmZmZm	Z	 ddl
ZddlZddl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 )zv
    Common high-level operations test

    Tests features common to all high-level objects, like the .name property.
é    )ÚFile)Úis_hdf5ÚEmptyé   )ÚutÚTestCaseÚUNICODE_FILENAMESNc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseTestc             C   s   t | jƒ dƒ| _d S )NÚw)r   ÚmktempÚf)Úself© r   ú6/tmp/pip-install-xpigntgx/h5py/h5py/tests/test_base.pyÚsetUp   s    zBaseTest.setUpc             C   s   | j r| j jƒ  d S )N)r   Úclose)r   r   r   r   ÚtearDown   s    zBaseTest.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 )ÚTestNamez>
        Feature: .name attribute returns the object name
    c             C   s   | j jdƒ}| j|jdƒ dS )z" Anonymous objects have name None N)r   Úcreate_groupZassertIsÚname)r   Úgrpr   r   r   Útest_anonymous(   s    zTestName.test_anonymousN)r   r   r   Ú__doc__r   r   r   r   r   r   "   s   r   c               @   s   e Zd ZdZdd„ ZdS )Ú
TestParentzG
        test the parent group of the high-level interface objects
    c          
   C   sV   | j jd ƒ}| jtƒ� |j W d Q R X | j jdƒ}|jdƒ}|jj}| j|dƒ d S )NÚbarZfooz/bar)r   r   ZassertRaisesÚ
ValueErrorÚparentr   ZassertEqual)r   r   Zsub_grpr   r   r   r   Útest_object_parent3   s    
zTestParent.test_object_parentN)r   r   r   r   r    r   r   r   r   r   -   s   r   c                   s8   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Z‡  ZS )
ÚTestMappingzX
        Test if the registration of Group as a
        Mapping behaves as expected
    c                s2   t ƒ jƒ  d}| jjdƒ| _| jjjd|ƒ| _d S )NÚaÚbr   Úx)r"   r#   )Úsuperr   r   r   r   ÚattrsÚcreateÚattr)r   Údata)Ú	__class__r   r   r   G   s    
zTestMapping.setUpc             C   s8   | j jƒ }| jt|ƒtƒ | jjƒ }| jt|ƒtƒ d S )N)r   ÚkeysÚassertIsInstanceÚreprÚstrr   )r   Zkey_1Zkey_2r   r   r   Ú	test_keysM   s    

zTestMapping.test_keysc             C   s8   | j jƒ }| jt|ƒtƒ | jjƒ }| jt|ƒtƒ d S )N)r   Úvaluesr,   r-   r.   r   )r   Zvalue_1Zvalue_2r   r   r   Útest_valuesS   s    

zTestMapping.test_valuesc             C   s8   | j jƒ }| jt|ƒtƒ | jjƒ }| jt|ƒtƒ d S )N)r   Úitemsr,   r-   r.   r   )r   Zitem_1Zitem_2r   r   r   Ú
test_itemsY   s    

zTestMapping.test_items)	r   r   r   r   r   r/   r1   r3   Ú__classcell__r   r   )r*   r   r!   @   s
   r!   c               @   s^   e Zd ZdZedƒedƒ Zdd„ Zdd„ Zdd	„ Zd
d„ Z	dd„ Z
eje dƒdd„ ƒZdS )ÚTestReprz7
        repr() works correctly with Unicode names
    éü   éß   c             C   s   | j t|ƒtƒ d S )N)r,   r-   r.   )r   Úobjr   r   r   Ú_check_typeh   s    zTestRepr._check_typec             C   s   | j j| jƒ}| j|ƒ dS )z Group repr() with unicode N)r   r   ÚUSTRINGr9   )r   r   r   r   r   Ú
test_groupk   s    zTestRepr.test_groupc             C   s   | j j| jdƒ}| j|ƒ dS )z Dataset repr() with unicode r   N)r   )r   Zcreate_datasetr:   r9   )r   Zdsetr   r   r   Útest_datasetp   s    zTestRepr.test_datasetc             C   s(   t jdƒ| jd< | jd }| j|ƒ dS )z  Named type repr() with unicode r   ÚtypeN)ÚnpÚdtyper   r9   )r   Útypr   r   r   Útest_namedtypeu   s    
zTestRepr.test_namedtypec             C   s*   t dd�}| jt dd�|ƒ | j|ƒ d S )Nr   )r?   Úi)r   ZassertNotEqualr9   )r   r)   r   r   r   Ú
test_empty{   s    
zTestRepr.test_emptyz#Filesystem unicode support requiredc             C   s`   t j| jd ƒ}z$t|dƒ�}| j|ƒ W dQ R X W dytj|ƒ W n tk
rX   Y nX X dS )z! File object repr() with unicode z.hdf5r
   N)Útempfiler   r:   r   r9   ÚosÚunlinkÚ	Exception)r   Úfnamer   r   r   r   Ú	test_file€   s    zTestRepr.test_fileN)r   r   r   r   Úchrr:   r9   r;   r<   rA   rC   r   ZskipIfr   rI   r   r   r   r   r5   `   s   r5   c              C   s6   t tjƒ dƒj} t| ƒst‚tjƒ } t| ƒ s2t‚d S )Nr
   )r   rD   r   Úfilenamer   ÚAssertionError)rK   r   r   r   Útest_is_hdf5�   s    rM   )r   Zh5pyr   Zh5py._hl.baser   r   Úcommonr   r   r   Znumpyr>   rE   rD   r	   r   r   r!   r5   rM   r   r   r   r   Ú<module>   s   
 -