3
_½µ_Ô  ã               @   s€   d Z ddlZddlZddljjZddljj	Z
ddlmZ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dS )z0
    Tests for the (internal) selections module
é    Né   )ÚTestCaseÚutc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseSelectionc             C   s(   t j| jƒ dƒ| _| jjdf ƒj| _d S )NÚwÚx)Úh5pyZFileÚmktempÚfÚcreate_datasetÚidÚdsid)Úself© r   ú</tmp/pip-install-xpigntgx/h5py/h5py/tests/test_selections.pyÚsetUp   s    zBaseSelection.setUpc             C   s   | j r| j jƒ  d S )N)r
   Úclose)r   r   r   r   ÚtearDown   s    zBaseSelection.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d„ Zdd„ ZdS )	ÚTestTypeGenerationzU
        Internal feature: Determine output types from dataset dtype and fields.
    c             C   s<   t jdƒ}tj|f ƒ\}}| j||ƒ | j|t jdƒƒ dS )z. Non-compound types are handled appropriately ÚiN)ÚnpÚdtypeÚsel2Úread_dtypesÚassertEqual)r   ÚdtÚoutÚformatr   r   r   Útest_simple$   s    
zTestTypeGeneration.test_simplec          
   C   s4   t jdƒ}| jtƒ� tj|dƒ\}}W dQ R X dS )z3 Field names for non-field types raises ValueError r   ÚaN)r"   )r   r   ÚassertRaisesÚ
ValueErrorr   r   )r   r   r   r    r   r   r   Útest_simple_fieldexc+   s    
z'TestTypeGeneration.test_simple_fieldexcc             C   sÊ   t jd
ddgƒ}tj|f ƒ\}}| j||ƒ | j||ƒ tj|dƒ\}}| j||ƒ | j|t jddgƒƒ tj|dƒ\}}| j|t jdƒƒ | j|t jdgƒƒ | jtƒ� tj|dƒ\}}W d	Q R X d	S )z( Compound types with elemental subtypes r"   r   Úbr
   Úcú|S10ÚjÚkN)r"   r   )r&   r
   )r'   r(   )r"   r&   )r"   r   )r&   r
   )r"   )r"   r   )r)   r*   )r   r   r   r   r   r#   r$   )r   r   r   r    r   r   r   Útest_compound_simple1   s    z'TestTypeGeneration.test_compound_simpleN)r   r   r   Ú__doc__r!   r%   r+   r   r   r   r   r      s   r   c               @   s   e Zd ZdZdd„ ZdS )ÚTestScalarSliceRuleszD
        Internal feature: selections rules for scalar datasets
    c             C   sÀ   t j| jf ƒ\}}| j|dƒ | j|jƒ dƒ t j| jtfƒ\}}| j|f ƒ | j|jƒ dƒ | jtƒ� t j| jdƒ\}}W dQ R X | jj	ddƒj
}| jtƒ� t j|dƒ\}}W dQ R X dS )z* Permissible arguments for scalar slicing Nr   Úy)r   )r   )r   )r   Zread_selections_scalarr   r   Zget_select_npointsÚEllipsisr#   r$   r
   r   r   ÚRuntimeError)r   ÚshapeZ	selectionr   r   r   r   Ú	test_argsN   s    zTestScalarSliceRules.test_argsN)r   r   r   r,   r2   r   r   r   r   r-   H   s   r-   c               @   s   e Zd ZdZdd„ ZdS )ÚTestSelectionz/ High-level routes to generate a selection
    c             C   s8  | j jddƒ}|jdd…dd…f }tjdtdddgƒ|ƒ}| j|tjƒ tjdtj	d	d
d
d
d	gƒ|ƒ}| j|tj
ƒ tjdd|ƒ}| j|tjƒ tjd||ƒ}| j|tjƒ | jtƒ� tjd|d ƒ W d Q R X | jtƒ� tjd||ƒ W d Q R X tjd||ƒ}| j||ƒ | jtƒ� tjd||ƒ W d Q R X d S )NÚdsetéd   r   é
   r   é   é   é   TF)r5   r5   )r6   )r9   )r6   )r5   r5   )r5   )r5   )r5   r5   )r5   )r
   r   Z	regionrefÚselÚselectÚlistZassertIsInstanceZFancySelectionr   ÚarrayZPointSelectionZSimpleSelectionZ	Selectionr#   Ú	TypeErrorr   )r   r4   ZregrefÚstZst1Zst2Zst3Zst4r   r   r   Útest_selectiond   s$    zTestSelection.test_selectionN)r   r   r   r,   r@   r   r   r   r   r3   _   s   r3   )r,   Znumpyr   r   Zh5py._hl.selectionsZ_hlZ
selectionsr:   Zh5py._hl.selections2Zselections2r   Úcommonr   r   r   r   r-   r3   r   r   r   r   Ú<module>   s   	*