3
½ìœ]ž£  ã               @   s   d Z ddlmZ ddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZmZmZ ddlmZ ddlmZm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G dd„ deƒZG dd„ deƒZG dd„ deƒZe
jdejjkdƒG dd„ deƒƒZe
jdejjkdƒG dd„ deƒƒZ e
jdejjkd ƒG d!d"„ d"eƒƒZ!e
jd#ejjkd$ƒG d%d&„ d&eƒƒZ"e
jd'ejjkd(ƒG d)d*„ d*eƒƒZ#e
jd+ejjkd,ƒG d-d.„ d.eƒƒZ$e
jd/ejjkd0ƒG d1d2„ d2eƒƒZ%G d3d4„ d4eƒZ&G d5d6„ d6eƒZ'G d7d8„ d8eƒZ(G d9d:„ d:eƒZ)G d;d<„ d<eƒZ*G d=d>„ d>eƒZ+G d?d@„ d@eƒZ,G dAdB„ dBeƒZ-G dCdD„ dDeƒZ.G dEdF„ dFeƒZ/G dGdH„ dHeƒZ0G dIdJ„ dJeƒZ1G dKdL„ dLeƒZ2G dMdN„ dNeƒZ3G dOdP„ dPeƒZ4G dQdR„ dReƒZ5G dSdT„ dTeƒZ6G dUdV„ dVeƒZ7dS )Wzü
    Dataset testing operations.

    Tests all dataset operations, including creation, with the exception of:

    1. Slicing operations for read and write, handled by module test_slicing
    2. Type conversion for read and write (currently untested)
é    )Úabsolute_importNé   )ÚutÚTestCase)ÚFileÚGroupÚDataset)Úis_empty_dataspace)Úh5fÚh5tc               @   s   e Zd Zdd„ Zdd„ ZdS )ÚBaseDatasetc             C   s   t | jƒ dƒ| _d S )NÚw)r   ÚmktempÚf)Úself© r   ú7/tmp/pip-build-pcqn41bp/h5py/h5py/tests/test_dataset.pyÚsetUp'   s    zBaseDataset.setUpc             C   s   | j r| j jƒ  d S )N)r   Úclose)r   r   r   r   ÚtearDown*   s    zBaseDataset.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 )ÚTestReprz5
        Feature: repr(Dataset) behaves sensibly
    c             C   s@   | j jddƒ}| jt|ƒtjƒ | j jƒ  | jt|ƒtjƒ dS )z( repr() works on live and dead datasets Úfooé   N)r   )r   Úcreate_datasetÚassertIsInstanceÚreprÚsixÚstring_typesr   )r   Údsr   r   r   Útest_repr_open4   s    
zTestRepr.test_repr_openN)r   r   r   Ú__doc__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d	„ Zd
d„ Zdd„ Z	e
jeedƒ dƒdd„ ƒZdS )ÚTestCreateShapez@
        Feature: Datasets can be created from a shape only
    c             C   s    | j jdf ƒ}| j|jf ƒ dS )z Create a scalar dataset r   N)r   r   ÚassertEqualÚshape)r   Údsetr   r   r   Útest_create_scalarB   s    z"TestCreateShape.test_create_scalarc             C   s    | j jddƒ}| j|jdƒ dS )z Create a size-1 dataset r   r   N)r   )r   )r   r   r%   r&   )r   r'   r   r   r   Útest_create_simpleG   s    z"TestCreateShape.test_create_simplec             C   sX   | j jddƒ}| j|jd	ƒ | j|jdƒ | j jdd
ƒ}| j|jdƒ | j|jdƒ dS )z Create an extended dataset r   é?   Úbaré   é
   é<   N)r*   )r*   )r,   r-   )r,   r-   )r   r   r%   r&   Úsize)r   r'   r   r   r   Útest_create_extendedL   s    z$TestCreateShape.test_create_extendedc             C   s&   | j jddƒ}| j|jtjdƒƒ dS )z) Confirm that the default dtype is float r   r*   z=f4N)r*   )r   r   r%   ÚdtypeÚnp)r   r'   r   r   r   Útest_default_dtypeU   s    z"TestCreateShape.test_default_dtypec          	   C   s&   | j tƒ� | jjdƒ W dQ R X dS )z  Missing shape raises TypeError r   N)ÚassertRaisesÚ	TypeErrorr   r   )r   r   r   r   Útest_missing_shapeZ   s    z"TestCreateShape.test_missing_shapec             C   sF   | j jddtjd�}tjƒ dkr2tjdtjƒ  ƒ | j|j	tjƒ dS )	z) Confirm that the default dtype is float r   r*   )r1   Úppc64lez(Storage of long double deactivated on %sN)r*   )r7   )
r   r   r2   Z
longdoubleÚplatformÚmachineÚpytestZxfailr%   r1   )r   r'   r   r   r   Útest_long_double_   s    z TestCreateShape.test_long_doubleÚ
complex256zNo support for complex256c             C   s0   | j jddtjdƒd�}| j|jtjdƒƒ dS )z) Confirm that the default dtype is float r   r*   r<   )r1   N)r*   )r   r   r2   r1   r%   )r   r'   r   r   r   Útest_complex256f   s    
zTestCreateShape.test_complex256N)r   r   r   r#   r(   r)   r0   r3   r6   r;   r   ÚskipIfÚhasattrr2   r=   r   r   r   r   r$   <   s   	r$   c               @   sV   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Ze	j
dd„ ƒZdd„ Zdd„ ZdS )ÚTestCreateDatazA
        Feature: Datasets can be created from existing data
    c             C   s0   t jf dƒ}| jjd|d�}| j|j|jƒ dS )z- Create a scalar dataset from existing array r   r   )ÚdataN)r2   Úonesr   r   r%   r&   )r   rA   r'   r   r   r   r(   t   s    z!TestCreateData.test_create_scalarc             C   s0   t jddƒ}| jjd|d�}| j|j|jƒ dS )z/ Create an extended dataset from existing data r*   r   r   )rA   N)r*   )r2   rB   r   r   r%   r&   )r   rA   r'   r   r   r   r0   z   s    z#TestCreateData.test_create_extendedc             C   s4   | j jdddd�}| j|tjƒ | jd| j kƒ dS )z1 Create dataset with missing intermediate groups z/foo/bar/bazr-   z<i4)r&   r1   N)r-   r-   )r   r   r   Úh5pyr   Ú
assertTrue)r   r!   r   r   r   Útest_dataset_intermediate_group€   s    z.TestCreateData.test_dataset_intermediate_groupc             C   sH   t jddd�}| jjdd
|d�}| j|jdƒ | j|d |jdƒƒ d	S )z8 Create from existing data, and make it fit a new shape é   r   )r1   r   r-   é   )r&   rA   .N)r-   rG   )r-   rG   )r-   rG   )r2   Úaranger   r   r%   r&   ÚassertArrayEqualÚreshape)r   rA   r'   r   r   r   Útest_reshape†   s    zTestCreateData.test_reshapec          
   C   s*   | j tƒ� t| jd jƒ W dQ R X dS )zE Binding Dataset to a non-DatasetID identifier fails with ValueError ú/N)r4   Ú
ValueErrorr   r   Úid)r   r   r   r   Útest_appropriate_low_level_id�   s    z,TestCreateData.test_appropriate_low_level_idc             C   s   | j ddƒ dS )z= Creating dataset with byte string yields vlen ASCII dataset TFN)r%   )r   r   r   r   Útest_create_bytestring’   s    z%TestCreateData.test_create_bytestringc             C   s*   | j jddd� | jt| j d jƒƒ d S )Nr   r   )r1   )r   r   rD   r	   rN   )r   r   r   r   Ú test_empty_create_via_None_shape˜   s    z/TestCreateData.test_empty_create_via_None_shapec             C   s2   | j jdtjdd�d� | jt| j d jƒƒ d S )Nr   r   )r1   )rA   )r   r   rC   ÚEmptyrD   r	   rN   )r   r   r   r   Ú!test_empty_create_via_Empty_classœ   s    z0TestCreateData.test_empty_create_via_Empty_classN)r   r   r   r#   r(   r0   rE   rK   rO   r   ÚexpectedFailurerP   rQ   rS   r   r   r   r   r@   n   s   r@   c               @   s@   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S )ÚTestCreateRequirezS
        Feature: Datasets can be created only if they don't exist in the file
    c             C   s.   | j jdddƒ}| j|tƒ | j|jdƒ dS )z& Create new dataset with no conflicts r   r-   rG   r   N)r-   rG   )r-   rG   )r   Úrequire_datasetr   r   r%   r&   )r   r'   r   r   r   Útest_create§   s    zTestCreateRequire.test_createc             C   s0   | j jdddƒ}| j jdddƒ}| j||ƒ dS )z) require_dataset yields existing dataset r   r-   rG   r   N)r-   rG   )r-   rG   )r   rV   r%   )r   r'   Údset2r   r   r   Útest_create_existing­   s    z&TestCreateRequire.test_create_existingc             C   s:   | j jdddƒ | jtƒ� | j jdddƒ W dQ R X dS )	z6 require_dataset with shape conflict yields TypeError r   r-   rG   r   r   N)r-   rG   )r-   r   )r   r   r4   r5   rV   )r   r   r   r   Útest_shape_conflict³   s    z%TestCreateRequire.test_shape_conflictc             C   s6   | j jdƒ | jtƒ� | j jdddƒ W dQ R X dS )z< require_dataset with object type conflict yields TypeError r   r-   rG   r   N)r-   rG   )r   Zcreate_groupr4   r5   rV   )r   r   r   r   Útest_type_conflict¹   s    z$TestCreateRequire.test_type_conflictc             C   s:   | j jdddƒ}| jtƒ� | j jdddƒ W dQ R X dS )	zL require_dataset with dtype conflict (strict mode) yields TypeError
        r   r-   rG   r   ZS10N)r-   rG   )r-   rG   )r   r   r4   r5   rV   )r   r'   r   r   r   Útest_dtype_conflict¿   s    z%TestCreateRequire.test_dtype_conflictc             C   sH   | j jdd	dƒ}| j jdd
ddd�}| j||ƒ | j|jtjdƒƒ dS )zJ require_dataset with convertible type succeeds (non-strict mode)
        r   r-   rG   Úi4Úi2F)ÚexactN)r-   rG   )r-   rG   )r   r   rV   r%   r1   r2   )r   r'   rX   r   r   r   Útest_dtype_closeÆ   s    z"TestCreateRequire.test_dtype_closeN)
r   r   r   r#   rW   rY   rZ   r[   r\   r`   r   r   r   r   rU   ¡   s   rU   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestCreateChunkedzL
        Feature: Datasets can be created by manually specifying chunks
    c             C   s$   | j jdddd�}| j|jdƒ dS )	z Create via chunks tuple r   éd   r-   )r&   ÚchunksN)rb   )r-   )r-   )r   r   r%   rc   )r   r'   r   r   r   Útest_create_chunksÕ   s    z$TestCreateChunked.test_create_chunksc             C   s,   | j tƒ� | jjdddd� W dQ R X dS )z& Illegal chunk size raises ValueError r   rb   éÈ   )r&   rc   N)rb   )re   )r4   rM   r   r   )r   r   r   r   Útest_chunks_mismatchÚ   s    z&TestCreateChunked.test_chunks_mismatchc             C   s,   | j tƒ� | jjdf dd� W dQ R X dS )z> Attempting to create chunked scalar dataset raises TypeError r   é2   )r&   rc   N)rg   )r4   r5   r   r   )r   r   r   r   Útest_chunks_scalarß   s    z$TestCreateChunked.test_chunks_scalarc             C   s6   | j jdddd�}| j|jtƒ | jt|jƒdƒ dS )	z Auto-chunking of datasets r   é   rb   T)r&   rc   é   N)ri   rb   )r   r   r   rc   Útupler%   Úlen)r   r'   r   r   r   Útest_auto_chunksä   s    z"TestCreateChunked.test_auto_chunksc             C   s&   | j jddddd�}| j|jd	ƒ dS )
z7 Auto-chunking with pathologically large element sizes r   rG   Z
S100000000T)r&   r1   rc   r   N)rG   )r   )r   r   r%   rc   )r   r'   r   r   r   Útest_auto_chunks_abuseê   s    z(TestCreateChunked.test_auto_chunks_abuseN)	r   r   r   r#   rd   rf   rh   rm   rn   r   r   r   r   ra   Ï   s   ra   c               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestCreateFillvaluez>
        Feature: Datasets can be created with fill value
    c             C   s6   | j jdddd�}| j|d dƒ | j|d dƒ dS )	z- Fill value is reflected in dataset contents r   r-   g      @)Ú	fillvaluer   é   N)r-   )r   r   r%   )r   r'   r   r   r   Útest_create_fillvalö   s    z'TestCreateFillvalue.test_create_fillvalc             C   s4   | j jdddd�}| j|jdƒ | j|jtjƒ dS )z( Fill value is recoverable via property r   r-   g      @)rp   N)r-   )r   r   r%   rp   ZassertNotIsInstancer2   Úndarray)r   r'   r   r   r   Útest_propertyü   s    z!TestCreateFillvalue.test_propertyc             C   s    | j jddƒ}| j|jdƒ dS )z0 .fillvalue property works correctly if not set r   r-   r   N)r-   )r   r   r%   rp   )r   r'   r   r   r   Útest_property_none  s    z&TestCreateFillvalue.test_property_nonec             C   sV   t jddgƒ}t jd|d�d }| jjdd||d
�}| j|j|ƒ | j|d |ƒ dS )z& Fill value works with compound types ÚaÚf4ÚbÚi8r   )r1   r   r   r-   )r1   rp   r   N)rv   rw   )rx   ry   )r   )r-   )r2   r1   rB   r   r   r%   rp   ZassertAlmostEqual)r   ÚdtÚvr'   r   r   r   Útest_compound  s
    z!TestCreateFillvalue.test_compoundc             C   s2   | j tƒ� | jjdd
ddgdd�}W d	Q R X d	S )z# Bogus fill value raises TypeError r   r-   rv   Úirx   r   é*   )r1   rp   N)r-   )rv   r}   )rx   r   )r4   rM   r   r   )r   r'   r   r   r   Útest_exc  s    
zTestCreateFillvalue.test_excN)	r   r   r   r#   rr   rt   ru   r|   r   r   r   r   r   ro   ð   s   ro   c               @   s   e Zd ZdZdd„ ZdS )ÚTestCreateNamedTypezC
        Feature: Datasets created from an existing named type
    c             C   sn   t jdƒ| jd< | jjdd| jd d�}| j|jt jdƒƒ | j|jjƒ | jd jƒ | j|jjƒ jƒ ƒ dS )z7 Named type object works and links the dataset to type Úf8ÚtypeÚxrb   )r1   N)rb   )	r2   r1   r   r   r%   rN   Úget_typerD   Z	committed)r   r'   r   r   r   Ú
test_named  s
    zTestCreateNamedType.test_namedN)r   r   r   r#   r…   r   r   r   r   r€     s   r€   ÚgzipzDEFLATE is not installedc               @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )ÚTestCreateGzipz=
        Feature: Datasets created with gzip compression
    c             C   s4   | j jddddd�}| j|jdƒ | j|jdƒ dS )	z# Create with explicit gzip options r   ri   rF   r†   é	   )ÚcompressionÚcompression_optsN)ri   rF   )r   r   r%   r‰   rŠ   )r   r'   r   r   r   Ú	test_gzip,  s    zTestCreateGzip.test_gzipc             C   s2   | j jdddd�}| j|jdƒ | j|jdƒ dS )	z+ Create with implicit gzip level (level 4) r   ri   rF   r†   )r‰   r   N)ri   rF   )r   r   r%   r‰   rŠ   )r   r'   r   r   r   Útest_gzip_implicit3  s    z!TestCreateGzip.test_gzip_implicitc             C   s‚   | j jdddd�}| j|jdƒ | j|jdƒ tjjj}z8t	ƒ tjj_| j
tƒ� | j jdd	dd�}W dQ R X W d|tjj_X dS )
z. Create with gzip level by specifying integer r   ri   rF   rq   )r‰   r†   N)ri   rF   )ri   rF   )r   r   r%   r‰   rŠ   rC   Ú_hlÚdatasetÚ_LEGACY_GZIP_COMPRESSION_VALSrk   r4   rM   )r   r'   Úoriginal_compression_valsr   r   r   Útest_gzip_number9  s    
 zTestCreateGzip.test_gzip_numberc             C   s‚   | j ttfƒ� | jjdd
dd� W dQ R X | j tƒ� | jjdddd� W dQ R X | j tƒ� | jjddddd	� W dQ R X dS )z= Illegal gzip level (explicit or implicit) raises ValueError r   ri   rF   é   )r‰   Nr   r†   )r‰   rŠ   )ri   rF   )ri   rF   éüÿÿÿ)ri   rF   )r4   rM   ÚRuntimeErrorr   r   )r   r   r   r   Útest_gzip_excG  s    zTestCreateGzip.test_gzip_excN)r   r   r   r#   r‹   rŒ   r‘   r•   r   r   r   r   r‡   %  s
   r‡   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestCreateCompressionNumberz?
        Feature: Datasets created with a compression code
    c             C   s`   t jjj}z(tƒ t jj_| jjddt jjd	d�}W d|t jj_X | j	|j
dƒ | j	|jdƒ dS )
z^ Create with compression number of gzip (h5py.h5z.FILTER_DEFLATE) and a compression level of 7r   ri   rF   rq   )r‰   rŠ   Nr†   )ri   rF   )rq   )rC   r�   rŽ   r�   rk   r   r   Úh5zÚFILTER_DEFLATEr%   r‰   rŠ   )r   r�   r'   r   r   r   Útest_compression_numberY  s    
z3TestCreateCompressionNumber.test_compression_numberc              C   sÌ   | j tƒ�}| jjdd
dd� W dQ R X | jdt|jƒƒ | j tƒ�}| jjdddd� W dQ R X | jd	t|jƒƒ tjj	j
}z<tƒ tjj	_
| j tƒ� | jjddtjjd� W dQ R X W d|tjj	_
X dS )z* Create with invalid compression numbers  r   ri   rF   iç  )r‰   NzInvalid filterrb   zUnknown compression)ri   rF   iüÿÿ)ri   rF   )ri   rF   )r4   rM   r   r   ZassertInÚstrÚ	exceptionrC   r�   rŽ   r�   rk   Ú
IndexErrorr—   r˜   )r   Úer�   r   r   r   Útest_compression_number_invalide  s    
$z;TestCreateCompressionNumber.test_compression_number_invalidN)r   r   r   r#   r™   rž   r   r   r   r   r–   R  s   r–   ÚlzfzLZF is not installedc               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestCreateLZFz<
        Feature: Datasets created with LZF compression
    c             C   s2   | j jdddd�}| j|jdƒ | j|jdƒ dS )z Create with explicit lzf r   ri   rF   rŸ   )r‰   N)ri   rF   )r   r   r%   r‰   rŠ   )r   r'   r   r   r   Útest_lzf�  s    zTestCreateLZF.test_lzfc             C   s.   | j tƒ� | jjddddd� W dQ R X dS )	z& Giving lzf options raises ValueError r   ri   rF   rŸ   r   )r‰   rŠ   N)ri   rF   )r4   rM   r   r   )r   r   r   r   Útest_lzf_exc‡  s    zTestCreateLZF.test_lzf_excN)r   r   r   r#   r¡   r¢   r   r   r   r   r    z  s   r    ÚszipzSZIP is not installedc               @   s   e Zd ZdZdd„ ZdS )ÚTestCreateSZIPz<
        Feature: Datasets created with LZF compression
    c             C   s   | j jdd	dd
d�}dS )z Create with explicit szip r   ri   rF   r£   Úecé   )r‰   rŠ   N)ri   rF   )r¥   r¦   )r   r   )r   r'   r   r   r   Ú	test_szip•  s    zTestCreateSZIP.test_szipN)r   r   r   r#   r§   r   r   r   r   r¤   Ž  s   r¤   ÚshufflezSHUFFLE is not installedc               @   s   e Zd ZdZdd„ ZdS )ÚTestCreateShufflez8
        Feature: Datasets can use shuffling filter
    c             C   s"   | j jdddd�}| j|jƒ dS )z Enable shuffle filter r   ri   rF   T)r¨   N)ri   rF   )r   r   rD   r¨   )r   r'   r   r   r   Útest_shuffle¢  s    zTestCreateShuffle.test_shuffleN)r   r   r   r#   rª   r   r   r   r   r©   ›  s   r©   Ú
fletcher32zFLETCHER32 is not installedc               @   s   e Zd ZdZdd„ ZdS )ÚTestCreateFletcher32z=
        Feature: Datasets can use the fletcher32 filter
    c             C   s"   | j jdddd�}| j|jƒ dS )z Enable fletcher32 filter r   ri   rF   T)r«   N)ri   rF   )r   r   rD   r«   )r   r'   r   r   r   Útest_fletcher32®  s    z$TestCreateFletcher32.test_fletcher32N)r   r   r   r#   r­   r   r   r   r   r¬   ¨  s   r¬   ÚscaleoffsetzSCALEOFFSET is not installedc               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestCreateScaleOffsetz?
        Feature: Datasets can use the scale/offset filter
    c             C   s.   | j tƒ� | jjddtdd�}W dQ R X dS )z[ Ensure that a scale factor is required for scaleoffset compression of floating point data r   ri   rF   T)r1   r®   N)ri   rF   )r4   rM   r   r   Úfloat)r   r'   r   r   r   Ú test_float_fails_without_optionsº  s    z6TestCreateScaleOffset.test_float_fails_without_optionsc             C   s¬   d}d}dd|  }t jj|Ž d | }| jjd|t|d�}|jd	k	sJt‚||d
< | jj}| jj	ƒ  t
j|dƒ| _| jd d
 }| j||d|  d� ||kjƒ  s¨t‚d	S )z2 Scaleoffset filter works for floating point data r   rb   é,  ri   r-   g      à?r   )r1   r®   N.Úr)Z	precision)rb   r²   )r2   ÚrandomZrandr   r   r°   r®   ÚAssertionErrorÚfilenamer   rC   r   rI   Úall)r   Zscalefacr&   ÚrangeÚtestdatar'   r¶   Úreaddatar   r   r   Ú
test_floatÀ  s    
z TestCreateScaleOffset.test_floatc             C   sŠ   d}d}t jjdd| d |d�}| jjd|td	d
�}|jdk	sDt‚||d< | jj}| jj	ƒ  t
j|dƒ| _| jd d }| j||ƒ dS )zB Scaleoffset filter works for integer data with default precision é   rb   é,  r   rj   r   )r/   r   T)r1   r®   N.r³   )rb   r½   )r2   r´   Úrandintr   r   Úintr®   rµ   r¶   r   rC   r   rI   )r   Únbitsr&   r¹   r'   r¶   rº   r   r   r   Útest_intÚ  s    
zTestCreateScaleOffset.test_intc             C   sˆ   d}d}t jjdd| |d�}| jjd|t|d�}| j|jdkƒ ||d	< | jj}| jj	ƒ  t
j|d
ƒ| _| jd d	 }| j||ƒ dS )zD Scaleoffset filter works for integer data with specified precision r¼   rb   é,  r   rj   )r/   r   )r1   r®   .r³   N)rb   rÂ   )r2   r´   r¾   r   r   r¿   rD   r®   r¶   r   rC   r   rI   )r   rÀ   r&   r¹   r'   r¶   rº   r   r   r   Útest_int_with_minbitsï  s    
z+TestCreateScaleOffset.test_int_with_minbitsc             C   s–   d}d}t jjdd|d  d |d�}| jjd|t|d	�}| j|jdkƒ ||d
< | jj}| jj	ƒ  t
j|dƒ| _| jd d
 }||kjƒ  s’t‚dS )zD Scaleoffset filter works for integer data with specified precision r¼   rb   é,  r   rj   r   )r/   r   )r1   r®   .r³   N)rb   rÄ   )r2   r´   r¾   r   r   r¿   rD   r®   r¶   r   rC   r   r·   rµ   )r   rÀ   r&   r¹   r'   r¶   rº   r   r   r   Útest_int_with_minbits_lossy  s    
z1TestCreateScaleOffset.test_int_with_minbits_lossyN)	r   r   r   r#   r±   r»   rÁ   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 )	ÚTestExternalzB
        Feature: Datasets with the external storage property
    c       
   	   C   s¦   d	}t jj|ƒ}| jƒ }|dtjfg}| jjd||j|d�}||d< |jdk	sRt	‚ddl
}|j|ƒ}|j|jkstt	‚t|dƒ�}|jƒ }	W dQ R X |	|jƒ ks¢t	‚dS )
z' Create and access an external dataset r,   rb   r   r   )r1   Úexternal.NÚrb)r,   rb   )r2   r´   r   r
   Ú	UNLIMITEDr   r   r1   rÇ   rµ   ÚosÚstatÚst_sizeÚnbytesÚopenÚreadÚtostring)
r   r&   r¹   Úext_filerÇ   r'   rÊ   ZstatinfoZfidÚcontentsr   r   r   Útest_external  s    
zTestExternal.test_externalc                s¦   d}| j ƒ ‰ | jjd|ˆ d� | jjd|ˆ gd� | jjd|ˆ dgd� | jjd|ˆ dtjgd� d}‡ fd	d
„td|ƒD ƒ}| jjd||d�}t|jƒ|ks¢t‚dS )z$ Test other forms of external lists r,   rb   r   )rÇ   r+   Zmoor   Zcarc                s"   g | ]}ˆ |d  |d d  f‘qS )iè  r   r   )Ú.0rƒ   )rÑ   r   r   ú
<listcomp>B  s    z4TestExternal.test_external_other.<locals>.<listcomp>ZpooN)r,   rb   )	r   r   r   r
   rÉ   r¸   rl   rÇ   rµ   )r   r&   ÚNrÇ   r'   r   )rÑ   r   Útest_external_other6  s    z TestExternal.test_external_otherc             C   st   d}| j ƒ }| jtƒ�  | jjd||ddfgd� W dQ R X | jtƒ�$ | jjd||dtjdfgd� W dQ R X dS )	z" Test with invalid external lists r,   rb   r   r   zh5f.UNLIMITED)rÇ   N)r,   rb   )r   r4   r5   r   r   r
   rÉ   )r   r&   rÑ   r   r   r   Útest_external_invalidF  s    $z"TestExternal.test_external_invalidN)r   r   r   r#   rÓ   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 )	ÚTestAutoCreatezP
        Feature: Datasets auto-created from data produce the correct types
    c             C   sX   d| j d< | j d }|jjƒ }| jt|ƒtjjƒ | j|j	ƒ ƒ | j|j
ƒ tjjƒ dS )z; Assignment of a byte string produces a vlen ascii dataset s   Hello thererƒ   N)r   rN   r„   r%   r‚   rC   r   ÚTypeStringIDrD   Úis_variable_strÚget_csetÚ
CSET_ASCII)r   r!   Útidr   r   r   Útest_vlen_bytesX  s    


zTestAutoCreate.test_vlen_bytesc             C   sb   dt jdƒ | jd< | jd }|jjƒ }| jt|ƒtjj	ƒ | j
|jƒ ƒ | j|jƒ tjjƒ dS )z@ Assignment of a unicode string produces a vlen unicode dataset zHello therei4   rƒ   N)r   Úunichrr   rN   r„   r%   r‚   rC   r   rÚ   rD   rÛ   rÜ   Ú	CSET_UTF8)r   r!   rÞ   r   r   r   Útest_vlen_unicodea  s    

z TestAutoCreate.test_vlen_unicodec             C   s`   t jdƒ| jd< | jd }|jjƒ }| jt|ƒtjj	ƒ | j|j
ƒ dƒ | j|jƒ tjjƒ dS )zV Assignment of fixed-length byte string produces a fixed-length
        ascii dataset zHello thererƒ   é   N)r2   Ústring_r   rN   r„   r%   r‚   rC   r   rÚ   Úget_sizerÜ   rÝ   )r   r!   rÞ   r   r   r   Útest_string_fixedj  s    

z TestAutoCreate.test_string_fixedN)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d„ ZdS )ÚTestCreateLikec             C   sV   t jdƒjddƒ| jd< | jjd| jd ƒ | jd }| j|jdƒ | j|jd ƒ d S )Né   é   ZlolZlike_lol)ré   ré   )	r2   rH   rJ   r   Úcreate_dataset_liker%   r&   ZassertIsrc   )r   Zdsliker   r   r   Útest_no_chunksv  s
    
zTestCreateLike.test_no_chunksc             C   s°   | j jdtjdƒdd�}| jdtjj|jƒj	ƒ | j j
d|ƒ}| jdtjj|jƒj	ƒ | j jdtjdƒdd�}| jdtjj|jƒj	ƒ | j j
d	|ƒ}| jdtjj|jƒj	ƒ d S )
NZhondar¼   T)rA   Útrack_timesr   ZhyundaiZibmFZlenovo)r   r   r2   rH   ZassertNotEqualrC   Úh5gÚget_objinfoÚ_idÚmtimerê   r%   )r   ÚorigZsimilarr   r   r   Útest_track_times}  s    zTestCreateLike.test_track_timesN)r   r   r   rë   rò   r   r   r   r   rç   u  s   rç   c               @   sH   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S )Ú
TestResizezF
        Feature: Datasets created with "maxshape" may be resized
    c             C   s2   | j jdddd�}| j|jdƒ | j|jd	ƒ dS )
z  Create dataset with "maxshape" r   ri   rF   r.   )ÚmaxshapeN)ri   rF   )ri   r.   )ri   r.   )r   r   ZassertIsNotrc   r%   rô   )r   r'   r   r   r   rW   ‘  s    zTestResize.test_createc             C   sT   | j jddd	d�}| j|jd
ƒ |jdƒ | j|jdƒ |jdƒ | j|jdƒ dS )z( Datasets may be resized up to maxshape r   ri   rF   r.   )rô   rg   N)ri   rF   )ri   r.   )ri   rF   )ri   rg   )ri   rg   )ri   r.   )ri   r.   )r   r   r%   r&   Úresize)r   r'   r   r   r   Útest_resize—  s    

zTestResize.test_resizec          
   C   s6   | j jddd	d�}| jtƒ� |jd
ƒ W dQ R X dS )z, Resizing past maxshape triggers ValueError r   ri   rF   r.   )rô   éF   N)ri   rF   )ri   r.   )ri   r÷   )r   r   r4   rM   rõ   )r   r'   r   r   r   Útest_resize_over   s    zTestResize.test_resize_overc          
   C   s2   | j jddƒ}| jtƒ� |jdƒ W dQ R X dS )z/ Resizing non-chunked dataset raises TypeError r   ri   rF   r.   N)ri   rF   )ri   r.   )r   r   r4   r5   rõ   )r   r'   r   r   r   Útest_resize_nonchunked¦  s    z!TestResize.test_resize_nonchunkedc             C   s2   | j jdd
dd�}|jddd� | j|jdƒ d	S )z Resize specified axis r   ri   rF   r.   )rô   rg   r   )ÚaxisN)ri   rF   )ri   r.   )ri   rg   )r   r   rõ   r%   r&   )r   r'   r   r   r   Útest_resize_axis¬  s    zTestResize.test_resize_axisc             C   s:   | j jdd
dd�}| jtƒ� |jddd� W d	Q R X d	S )z  Illegal axis raises ValueError r   ri   rF   r.   )rô   rg   rj   )rú   N)ri   rF   )ri   r.   )r   r   r4   rM   rõ   )r   r'   r   r   r   Útest_axis_exc²  s    zTestResize.test_axis_excc             C   s2   | j jdddd�}| j|jdƒ | j|jd	ƒ dS )
z? Allow zero-length initial dims for unlimited axes (issue 111) r   é   r   N)rô   )rý   r   )rý   N)rý   r   )rý   N)r   r   r%   r&   rô   )r   r'   r   r   r   Útest_zero_dim¸  s    zTestResize.test_zero_dimN)r   r   r   r#   rW   rö   rø   rù   rû   rü   rþ   r   r   r   r   ró   ‹  s   	ró   c               @   s   e Zd ZdZdd„ ZdS )Ú	TestDtypezD
        Feature: Dataset dtype is available as .dtype property
    c             C   s(   | j jdddƒ}| j|jtjdƒƒ dS )z Retrieve dtype from dataset r   ré   z|S10N)ré   )r   r   r%   r1   r2   )r   r'   r   r   r   Ú
test_dtypeÅ  s    zTestDtype.test_dtypeN)r   r   r   r#   r   r   r   r   r   rÿ   ¿  s   rÿ   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestLenzG
        Feature: Size of first axis is available via Python's len
    c             C   s"   | j jddƒ}| jt|ƒdƒ dS )z Python len() (under 32 bits) r   é8  rý   N)r  rý   )r   r   r%   rl   )r   r'   r   r   r   Útest_lenÑ  s    zTestLen.test_lenc             C   sj   | j jdd	ƒ}| j|jdƒ tjdkrF| jtƒ� t|ƒ W dQ R X n| jt|ƒdƒ | j|jƒ dƒ dS )z Python len() vs Dataset.len() r   rj   é!   rý   é   r   Nì        )r  rý   ì        )r  rý   l        iÿÿÿl        l        )	r   r   r%   r&   ÚsysÚmaxsizer4   ÚOverflowErrorrl   )r   r'   r   r   r   Útest_len_bigÖ  s    
zTestLen.test_len_bigN)r   r   r   r#   r  r  r   r   r   r   r  Ë  s   r  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestIterz;
        Feature: Iterating over a dataset yields rows
    c             C   s\   t jddd�jd	ƒ}| jjd|d�}x2t||ƒD ]$\}}| jt|ƒdƒ | j||ƒ q0W dS )
z& Iterating over a dataset yields rows rF   r   )r1   r-   rG   r   )rA   N)r-   rG   )	r2   rH   rJ   r   r   Úzipr%   rl   rI   )r   rA   r'   rƒ   Úyr   r   r   Ú	test_iterè  s
    zTestIter.test_iterc          	   C   s8   | j jdf d�}| jtƒ� dd„ |D ƒ W dQ R X dS )z0 Iterating over scalar dataset raises TypeError r   )r&   c             S   s   g | ]}|‘qS r   r   )rÔ   rƒ   r   r   r   rÕ   ô  s    z-TestIter.test_iter_scalar.<locals>.<listcomp>N)r   r   r4   r5   )r   r'   r   r   r   Útest_iter_scalarð  s    zTestIter.test_iter_scalarN)r   r   r   r#   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d	„ Zd
d„ Zdd„ Z	dd„ Z
ejdd„ ƒZdd„ ZdS )ÚTestStringszr
        Feature: Datasets created with vlen and fixed datatypes correctly
        translate to and from HDF5
    c             C   sn   t jdd�}| jjdd|d�}|jjƒ }| jt|ƒt jj	ƒ | j|j
ƒ t jjƒ t j|jƒ}| j|jdƒ dS )z3 Vlen bytes dataset maps to vlen ascii in the file Úascii)Úencodingrƒ   rb   )r1   N)rb   )rC   Ústring_dtyper   r   rN   r„   r%   r‚   r   rÚ   rÜ   rÝ   Úcheck_string_dtyper1   r  )r   rz   r!   rÞ   Ústring_infor   r   r   rß   þ  s    
zTestStrings.test_vlen_bytesc             C   sj   t jƒ }| jjdd|d�}|jjƒ }| jt|ƒt jj	ƒ | j|j
ƒ t jjƒ t j|jƒ}| j|jdƒ dS )z5 Vlen unicode dataset maps to vlen utf-8 in the file rƒ   rb   )r1   zutf-8N)rb   )rC   r  r   r   rN   r„   r%   r‚   r   rÚ   rÜ   rá   r  r1   r  )r   rz   r!   rÞ   r  r   r   r   râ     s    
zTestStrings.test_vlen_unicodec             C   s˜   t jdƒ}| jjdd|d�}|jjƒ }| jt|ƒtj	j
ƒ | j|jƒ ƒ | j|jƒ dƒ | j|jƒ tj	jƒ tj|jƒ}| j|jdƒ | j|jdƒ dS )	zK Fixed-length bytes dataset maps to fixed-length ascii in the file
        z|S10rƒ   rb   )r1   r-   r  N)rb   )r2   r1   r   r   rN   r„   r%   r‚   rC   r   rÚ   ZassertFalserÛ   rå   rÜ   rÝ   r  r  Úlength)r   rz   r!   rÞ   r  r   r   r   Útest_fixed_bytes  s    

zTestStrings.test_fixed_bytesc             C   s6   t jdƒ}| jtƒ� | jjdd|d�}W dQ R X dS )zA Fixed-length unicode datasets are unsupported (raise TypeError) z|U10rƒ   rb   )r1   N)rb   )r2   r1   r4   r5   r   r   )r   rz   r!   r   r   r   Útest_fixed_unicode   s    
zTestStrings.test_fixed_unicodec             C   sR   t jdd�}| jjdd	|d�}d}||d< |d }| jt|ƒtƒ | j||ƒ dS )
zN writing and reading to vlen bytes dataset preserves type and content
        r  )r  rƒ   rb   )r1   s   Helloïr   N)rb   )rC   r  r   r   r%   r‚   Úbytes)r   rz   r!   rA   Úoutr   r   r   Útest_roundtrip_vlen_bytes&  s    z%TestStrings.test_roundtrip_vlen_bytesc             C   sZ   t jƒ }| jjdd|d�}dtjdƒ }||d< |d }| jt|ƒtjƒ | j||ƒ dS )	zK Writing and reading to unicode dataset preserves type and content
        rƒ   rb   )r1   ZHelloi4   r   N)rb   )	rC   r  r   r   r   rà   r%   r‚   Ú	text_type)r   rz   r!   rA   r  r   r   r   Útest_roundtrip_vlen_unicode1  s    z'TestStrings.test_roundtrip_vlen_unicodec             C   sR   t jdƒ}| jjdd|d�}d}||d< |d }| jt|ƒt jƒ | j||ƒ dS )	z[ Writing to and reading from fixed-length bytes dataset preserves
        type and content z|S10rƒ   rb   )r1   s   Helloïr   N)rb   )r2   r1   r   r   r%   r‚   rä   )r   rz   r!   rA   r  r   r   r   Útest_roundtrip_fixed_bytes<  s    
z&TestStrings.test_roundtrip_fixed_bytesc          
   C   s@   t jƒ }| jjdd|d�}d}| jtƒ� ||d< W dQ R X dS )zT Writing a non-utf8 byte string to a unicode vlen dataset raises
        ValueError rƒ   rb   )r1   u   HelloÃ¯r   N)rb   )rC   r  r   r   r4   rM   )r   rz   r!   rA   r   r   r   Útest_unicode_write_errorG  s
    z$TestStrings.test_unicode_write_errorc             C   s`   t jƒ }| jjdd	|d�}dtjdƒ }|jdƒ|d< |d }| jt|ƒtj	ƒ | j||ƒ dS )
zJ Writing valid utf-8 byte strings to a unicode vlen dataset is OK
        rƒ   rb   )r1   zHello therei4   Úutf8r   N)rb   )
rC   r  r   r   r   rà   Úencoder%   r‚   r  )r   rz   r!   rA   r  r   r   r   Útest_unicode_write_bytesQ  s    z$TestStrings.test_unicode_write_bytesN)r   r   r   r#   rß   râ   r  r  r  r  r  r   rT   r   r#  r   r   r   r   r  ÷  s   


r  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestCompoundz:
        Feature: Compound types correctly round-trip
    c          	   C   s´   t jdt jfdt jfdt jfdt jfdt jfdt jfdt jfgƒ}t jd|d	�}x"|jD ]}t jjdƒd
 ||< qXW || jd< | jd d }| j	t j
||kƒƒ | j|j|jƒ dS )z: Compound types are read back in correct order (issue 236)ÚweightZcputimeZwalltimeZparents_offsetZ	n_parentsÚstatusÚendpoint_typer¦   )r1   rb   Útest.N)r¦   )r¦   )r2   r1   Úfloat64Zuint32Úuint8rs   Úfieldsr´   r   rD   r·   r%   )r   rz   r¹   ÚkeyÚoutdatar   r   r   Útest_rtc  s    
zTestCompound.test_rtc             C   s¼   t jdt jdffdt jfgƒ}t jd
|d�}x*|jD ] }t jj|| jd�d ||< q4W | jj	dd|d�}x|jD ]}|| ||< qrW | jd d	 }| j
t j||kƒƒ | j|j|jƒ d S )Nr%  rG   r'  r¦   )r1   )r/   rb   r(  .)r¦   )r¦   )r2   r1   r)  r*  rs   r+  r´   r&   r   r   rD   r·   r%   )r   rz   r¹   r,  r!   r-  r   r   r   Útest_assignw  s     zTestCompound.test_assignN)r   r   r   r#   r.  r/  r   r   r   r   r$  ]  s   r$  c               @   s,   e Zd ZdZddddœZdd„ Zdd	„ Zd
S )ÚTestEnumzM
        Feature: Enum datatype info is preserved, read/write as integer
    r   r   r~   )ÚREDÚGREENÚBLUEc             C   sD   t j| jdd�}| jjdd|d�}|j}t j|ƒ}| j|| jƒ dS )z= Enum datasets can be created and type correctly round-trips r}   )Úbasetyperƒ   rb   )r1   N)rb   rb   )rC   Ú
enum_dtypeÚEDICTr   r   r1   Zcheck_enum_dtyper%   )r   rz   r!   Zdt2Zdict2r   r   r   rW   ‘  s
    
zTestEnum.test_createc             C   st   t j| jdd�}| jjdd|d�}d|d< d	|d	d
d
…f< | j|d dƒ | j|d	d
d
…f tjdd dd�ƒ d
S )z/ Enum datasets can be read/written as integers r]   )r4  rƒ   rb   )r1   r~   é#   é%   r   N)rb   rb   )r7  r8  )r7  r8  )r   )	rC   r5  r6  r   r   r%   rI   r2   Úarray)r   rz   r!   r   r   r   Útest_readwrite™  s    zTestEnum.test_readwriteN)r   r   r   r#   r6  rW   r:  r   r   r   r   r0  ‰  s   r0  c               @   s:   e Zd ZdZdd„ Zejeedƒdƒdd„ ƒZ	dd	„ Z
d
S )Ú
TestFloatszA
        Test support for mini and extended-precision floats
    c             C   sJ   | j jdd|d�}| j|j|ƒ tjd|d�}||d< | j|d |ƒ d S )Nrƒ   rb   )r1   .)rb   )rb   )r   r   r%   r1   r2   rB   rI   )r   rz   r'   rA   r   r   r   Ú	_exectest©  s
    zTestFloats._exectestÚfloat16zNumPy float16 support requiredc             C   s   | j tjdƒƒ dS )z Mini-floats round trip r=  N)r<  r2   r1   )r   r   r   r   Ú	test_mini°  s    zTestFloats.test_minic             C   s<   t tdƒr"| jtjjtjdƒƒ n| jtjjtjdƒƒ dS )z Test mapping for float16 r=  z<f2z<f4N)r?   r2   r%   r   Z
IEEE_F16LEr1   )r   r   r   r   Útest_mini_mapping¶  s    
zTestFloats.test_mini_mappingN)r   r   r   r#   r<  r   Z
skipUnlessr?   r2   r>  r?  r   r   r   r   r;  £  s   r;  c               @   s   e Zd ZdZdd„ ZdS )ÚTestTrackTimesz"
        Feature: track_times
    c             C   s2   | j jdddd�}tjj|jƒj}| jd|ƒ dS )zC check that when track_times=False, the time stamp=0 (Jan 1, 1970) r   r   F)rì   r   N)r   )r   r   rC   rí   rî   rï   rð   r%   )r   r!   Zds_mtimer   r   r   Útest_disable_track_timesÄ  s    z'TestTrackTimes.test_disable_track_timesN)r   r   r   r#   rA  r   r   r   r   r@  ¾  s   r@  c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚTestZeroShapez7
        Features of datasets with (0,)-shape axes
    c             C   sT   | j jdddd�}| j|jtj|ƒjƒ | j jddd	d�}| j|jtj|ƒjƒ dS )
z1 Empty datasets can be converted to NumPy arrays rƒ   r   N)rô   r  )r   )N)r   r   )NN)r   r   r%   r&   r2   r9  )r   r!   r   r   r   Útest_array_conversionÑ  s    z#TestZeroShape.test_array_conversionc             C   s~   ddg}| j jdd|dd�}tjd|d	�}| j|d
 j|jƒ | j|d
 j|jƒ | j|f  j|jƒ | j|f  j|jƒ dS )z- Slicing into empty datasets works correctly rv   r   rx   r}   rƒ   r   N)r1   rô   )r1   .)rv   r   )rx   r}   )r   )N)r   )r   r   r2   Úemptyr%   r&   r1   )r   rz   r!   Zarrr   r   r   Útest_readingÙ  s    zTestZeroShape.test_readingN)r   r   r   r#   rC  rE  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 )	ÚTestRegionRefsz3
        Various features of region references
    c             C   s@   t j| ƒ tjdƒjdƒ| _| jjd| jd�| _| j| jd< d S )Nrb   rƒ   )rA   .i'  )rb   rb   )	r   r   r2   rH   rJ   rA   r   r   r'   )r   r   r   r   r   ë  s    
zTestRegionRefs.setUpc             C   s@   t jdd…ddd…f }| jj| }| j| j| | j| ƒ dS )z4 Region references can be used as slicing arguments rè   r7  r-   rb   ré   N)r2   Ús_r'   Ú	regionrefrI   rA   )r   ÚslicÚrefr   r   r   Útest_create_refñ  s    zTestRegionRefs.test_create_refc             C   sX   t jdd…ddd…f }| jj| }| j| jjj|ƒ| jjƒ | j| jjj|ƒdƒ dS )	z, Region reference shape and selection shape rè   r7  r-   rb   ré   é   N)r-   rL  )r2   rG  r'   rH  r%   r&   Z	selection)r   rI  rJ  r   r   r   Útest_ref_shape÷  s    zTestRegionRefs.test_ref_shapeN)r   r   r   r#   r   rK  rM  r   r   r   r   rF  å  s   rF  c               @   s   e Zd ZdZdd„ ZdS )Ú
TestAstypez%
        .astype context manager
    c             C   sp   | j jdddd�}tjdƒ|d< |jdƒ�< | j|d jtjdƒƒ | jtj|d tjdƒkƒƒ W d Q R X d S )Nrƒ   rb   r^   )r1   .r�   )rb   )	r   r   r2   rH   Úastyper%   r1   rD   r·   )r   r'   r   r   r   Útest_astype  s
    zTestAstype.test_astypeN)r   r   r   r#   rP  r   r   r   r   rN  ÿ  s   rN  c               @   s   e Zd ZdZdd„ ZdS )ÚTestScalarCompoundzl
        Retrieval of a single field from a scalar compound dataset should
        strip the field info
    c             C   s:   t jdgƒ}| jjdf |d�}| j|d jt jdƒƒ d S )Nrv   r}   rƒ   )r1   )rv   r}   )r2   r1   r   r   r%   )r   rz   r'   r   r   r   Útest_scalar_compound  s    z'TestScalarCompound.test_scalar_compoundN)r   r   r   r#   rR  r   r   r   r   rQ    s   rQ  c               @   s^   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zddd„Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚTestVlenc             C   sR  t jtƒ}| jjdd	|d�}tjdƒ|d< tjdƒ|d< dddg|d< tjdƒ|d< | j|d tjdƒƒ | j|d tjdƒƒ | j|d tjdddgƒƒ | j|d tjdƒƒ tjtjdƒtjdƒgƒ|dd…< | j|d tjdƒƒ | j|d tjdƒƒ tjtjdƒtjdƒgƒ|dd…< | j|d tjdƒƒ | j|d tjdƒƒ d S )
NÚvlenr   )r1   rG   r   r   rj   ré   )r   )	rC   Ú
vlen_dtyper¿   r   r   r2   rH   rI   r9  )r   rz   r!   r   r   r   rÁ     s     
""zTestVlen.test_intc             C   s6   t jtƒ}| jjdd|d�}| jjdd|f  jƒ d S )NrT  r   )r1   Úvlen2)r   )r   )rC   rU  r¿   r   r   r1   )r   rz   r!   r   r   r   Útest_reuse_from_other/  s    
zTestVlen.test_reuse_from_otherc             C   sl   dt fdtjt ƒfg}| jjdd|d�}| jj}| jjƒ  tj|dƒ| _| jjdd| jd d f  jƒ d S )	Nrv   rx   rT  r   )r1   rV  )r   )r   )	r¿   rC   rU  r   r   r¶   r   r   r1   )r   rz   r!   Úfnamer   r   r   Útest_reuse_struct_from_other4  s    
z%TestVlen.test_reuse_struct_from_otherc             C   sJ  t jtƒ}| jjdd|d�}tjddgƒ|d< tjdgƒ|d< dddg|d< | j|d tjddgƒƒ | j|d tjdgƒƒ | j|d tjdddgƒƒ tjd	d
dddgtjdƒgƒ|dd…< | j|d tjdƒƒ | j|d tjdƒƒ tjtjd	ddgƒtjdddgƒgƒ|dd…< | j|d tjdƒƒ | j|d tjdƒƒ d S )NrT  rG   )r1   gffffffö?g333333ó?r   r   rj   gš™™™™™¹?gš™™™™™ñ?gÍÌÌÌÌÌ @gÍÌÌÌÌÌ@r   ré   gš™™™™™@gš™™™™™É?)rG   )	rC   rU  r¿   r   r   r2   r9  rI   rH   )r   rz   r!   r   r   r   Útest_convert<  s    
&zTestVlen.test_convertc             C   sª   t jtƒ}| jjdd|d�}tjdƒ|d< tjtjdƒtjdƒgtjdƒtjdƒggƒ|d d …d d …f< tjtjdƒtjdƒgtjdƒtjdƒggƒ|d d …d d …f< d S )	NrT  rj   )r1   r   r   rG   )rj   rj   )r   r   )rC   rU  r¿   r   r   r2   rH   r9  )r   rz   r!   r   r   r   Útest_multidimM  s    
(zTestVlen.test_multidimrT  c             C   sh  t j|ƒ}| jj|d|d�}tjdddg|d�}tjdddddg|d�}tjdddgtjdƒd�}|j|ƒ}dddddg}	tj|	|d�}
dd ddddg}tj||d�}||d< ||d< ||d< |	|d< ||d< | j||d ƒ | j||d ƒ | j||d ƒ | j|
|d ƒ | j||d ƒ tjddg|d�}
|
dd… |d< | j|
|d ƒ | jj	ƒ  | jj
ƒ  dS )!z¿
        Helper for testing various vlen numpy data types.
        :param np_dt: Numpy datatype to test
        :param dataset_name: String name of the dataset to create for testing.
        ré   )r1   g      ð?g       @g      >@g33333Y@gÍÌÌÌÌi@gfffff†X@g      %@g     Àr@r   rj   é   Zint32g      Œ@g        g      à?rb   r   i'  r÷   rG   r   g333333Ó?gš™™™™™@N)ré   g      %Àg     ÀrÀg      à¿éÿÿÿÿiœÿÿÿ)rC   rU  r   r   r2   r9  r1   rO  rI   Úflushr   )r   Únp_dtZdataset_namerz   r!   Zarray_0Zarray_1Zarray_2Zcasted_array_2Zlist_3Zlist_array_3Zlist_4Zlist_array_4r   r   r   Ú_help_float_testingV  s2    


zTestVlen._help_float_testingc             C   s   t jdƒ}| j|ƒ d S )Nr=  )r2   r1   r`  )r   r_  r   r   r   Útest_numpy_float16†  s    
zTestVlen.test_numpy_float16c             C   s   t jdƒ}| j|ƒ d S )NZfloat32)r2   r1   r`  )r   r_  r   r   r   Útest_numpy_float32Š  s    
zTestVlen.test_numpy_float32c             C   s   t jdƒ}| j|ƒ d S )Nr)  )r2   r1   r`  )r   r_  r   r   r   Útest_numpy_float64_from_dtypeŽ  s    
z&TestVlen.test_numpy_float64_from_dtypec             C   s   t j}| j|ƒ d S )N)r2   r)  r`  )r   r_  r   r   r   Útest_numpy_float64_2’  s    zTestVlen.test_numpy_float64_2N)rT  )r   r   r   rÁ   rW  rY  rZ  r[  r`  ra  rb  rc  rd  r   r   r   r   rS    s   	
0rS  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestLowOpenc             C   s   | j jddƒ}|jjƒ }dS )z Test H5Dget_access_plist r   r   N)r   )r   r   rN   Zget_access_plist)r   r!   Zp_listr   r   r   Útest_get_access_list™  s    z TestLowOpen.test_get_access_listc             C   sH   t jjt jjƒ}| jjddƒ}~t jj| jjd|ƒ}| j	|t jj
ƒ dS )z# Test the dapl keyword to h5d.open rƒ   rb   ó   xN)rb   )rC   Zh5pÚcreateZDATASET_ACCESSr   r   Zh5drÎ   rN   r   Z	DatasetID)r   Zdaplr'   Zdsidr   r   r   Ú	test_daplž  s
    zTestLowOpen.test_daplN)r   r   r   rf  ri  r   r   r   r   re  —  s   re  )8r#   Ú
__future__r   r  r   Znumpyr2   r8   r:   Úcommonr   r   rC   r   r   r   Zh5py._hl.baser	   r
   r   r   r   r$   r@   rU   ra   ro   r€   r>   Úfiltersr"  r‡   r–   r    r¤   r©   r¬   r¯   rÆ   rÙ   rç   ró   rÿ   r  r  r  r$  r0  r;  r@  rB  rF  rN  rQ  rS  re  r   r   r   r   Ú<module>   sf   	23.!&,'e8#4f,{