3
½ìœ]¼  ã               @   sœ   d dl mZ d dlZd dlZddlmZmZ ejej	j
dk dƒG dd	„ d	eƒƒZejej	j
dkd
ƒG dd„ deƒƒZejej	j
dkd
ƒG dd„ deƒƒZdS )é    )Úabsolute_importNé   )ÚutÚTestCaseé	   é²   z6SWMR is available. Skipping backwards compatible testsc               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestSwmrNotAvailablezÝ Test backwards compatibility behaviour when using SWMR functions with
    an older version of HDF5 which does not have this feature available.
    Skip this test if SWMR features *are* available in the HDF5 library.
    c             C   s8   t j| ƒ tjdƒjdƒ| _| jjddd| jd�| _d S )Né   ÚfÚdata)ÚchunksÚmaxshaper   )r	   )N)	r   ÚsetUpÚnpÚarangeÚastyper   r
   Úcreate_datasetÚdset)Úself© r   ú</tmp/pip-build-pcqn41bp/h5py/h5py/tests/test_dataset_swmr.pyr      s    
zTestSwmrNotAvailable.setUpc             C   s>   | j j}| j jƒ  | jtƒ� tj|ddd�| _ W d Q R X d S )NÚrT)Úswmr)r
   ÚfilenameÚcloseÚassertRaisesÚ
ValueErrorÚh5pyÚFile)r   Úfnamer   r   r   Útest_open_swmr_raises   s    
z*TestSwmrNotAvailable.test_open_swmr_raisesc          	   C   s$   | j tƒ� | jjƒ  W dQ R X dS )zd If the SWMR feature is not available then Dataset.refresh() should throw an AttributeError
        N)r   ÚAttributeErrorr   Úrefresh)r   r   r   r   Útest_refresh_raises   s    z(TestSwmrNotAvailable.test_refresh_raisesc          	   C   s$   | j tƒ� | jjƒ  W dQ R X dS )zi If the SWMR feature is not available the Dataset.flush() should
        throw an AttributeError
        N)r   r!   r   Úflush)r   r   r   r   Útest_flush_raises"   s    z&TestSwmrNotAvailable.test_flush_raisesc          	   C   s"   | j tƒ� | jj W d Q R X d S )N)r   r!   r
   Ú	swmr_mode)r   r   r   r   Útest_swmr_mode_raises)   s    z*TestSwmrNotAvailable.test_swmr_mode_raisesN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r#   r%   r'   r   r   r   r   r   	   s   r   zSWMR requires HDF5 >= 1.9.178c               @   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 )ÚTestDatasetSwmrReadz| Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c             C   sh   t j| ƒ tjdƒjdƒ| _| jjddd	| jd�| _| jj	}| jj
ƒ  tj|ddd�| _| jd | _d S )
Nr	   r
   r   )r   r   r   r   T)r   )r	   )N)r   r   r   r   r   r   r
   r   r   r   r   r   r   )r   r   r   r   r   r   3   s    

zTestDatasetSwmrRead.setUpc             C   s   | j | jjƒ dS )z/ Verify that the file is initially in SWMR modeN)Ú
assertTruer
   r&   )r   r   r   r   Útest_initial_swmr_mode_on=   s    z-TestDatasetSwmrRead.test_initial_swmr_mode_onc             C   s   | j | j| jƒ d S )N)ÚassertArrayEqualr   r   )r   r   r   r   Útest_read_dataA   s    z"TestDatasetSwmrRead.test_read_datac             C   s   | j jƒ  d S )N)r   r"   )r   r   r   r   Útest_refreshD   s    z TestDatasetSwmrRead.test_refreshc          	   C   s0   | j tƒ� d| j_W dQ R X | j| jjƒ dS )zŒ Verify when reading a file cannot be forcibly switched to swmr mode.
        When reading with SWMR the file must be opened with swmr=True.TN)r   r   r
   r&   r-   )r   r   r   r   Útest_force_swmr_mode_on_raisesG   s    z2TestDatasetSwmrRead.test_force_swmr_mode_on_raisesc          	   C   s0   | j tƒ� d| j_W dQ R X | j| jjƒ dS )zž Switching SWMR write mode off is only possible by closing the file.
        Attempts to forcibly switch off the SWMR mode should raise a ValueError.
        FN)r   r   r
   r&   r-   )r   r   r   r   Útest_force_swmr_mode_off_raisesN   s    z3TestDatasetSwmrRead.test_force_swmr_mode_off_raisesN)
r(   r)   r*   r+   r   r.   r0   r1   r2   r3   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S )ÚTestDatasetSwmrWritez| Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c             C   sH   t j| jƒ ddd�| _tjdƒjdƒ| _| jjdd| jj	ddd
�| _
d	S )za First setup a file with a small chunked and empty dataset.
        No data written yet.
        ÚwÚlatest)Zlibveré   r
   r   r   é   N)ÚshapeÚdtyper   r   )r   )r8   )N)r   r   Úmktempr
   r   r   r   r   r   r:   r   )r   r   r   r   r   \   s    zTestDatasetSwmrWrite.setUpc             C   s   | j | jjƒ dS )z3 Verify that the file is not initially in SWMR modeN)ZassertFalser
   r&   )r   r   r   r   Útest_initial_swmr_mode_offi   s    z/TestDatasetSwmrWrite.test_initial_swmr_mode_offc             C   s   d| j _| j| j jƒ dS )z  Switch to SWMR mode and verify TN)r
   r&   r-   )r   r   r   r   Útest_switch_swmr_mode_onm   s    z-TestDatasetSwmrWrite.test_switch_swmr_mode_onc          	   C   sF   d| j _| j| j jƒ | jtƒ� d| j _W dQ R X | j| j jƒ dS )zž Switching SWMR write mode off is only possible by closing the file.
        Attempts to forcibly switch off the SWMR mode should raise a ValueError.
        TFN)r
   r&   r-   r   r   )r   r   r   r   Ú test_switch_swmr_mode_off_raisesr   s
    z5TestDatasetSwmrWrite.test_switch_swmr_mode_off_raisesc             C   s^   d| j _| j| j jƒ | jj| jjƒ | j| jdd…< | jjƒ  | jjƒ  | j	| j| jƒ dS )z) Extend and flush a SWMR dataset
        TN)
r
   r&   r-   r   Úresizer   r9   r$   r"   r/   )r   r   r   r   Útest_extend_dset|   s    

z%TestDatasetSwmrWrite.test_extend_dsetc             C   sº   d| j _| j| j jƒ | jjdƒ | j| jdd …< | jjƒ  | jjƒ  | j| j| jƒ | jjdƒ | j| jdd …< | jjƒ  | jjƒ  | j| jdd… | jƒ | j| jdd… | jƒ d S )NTr7   r   é   )r7   )rA   )	r
   r&   r-   r   r?   r   r$   r"   r/   )r   r   r   r   Útest_extend_dset_multipleŠ   s    



z.TestDatasetSwmrWrite.test_extend_dset_multipleN)
r(   r)   r*   r+   r   r<   r=   r>   r@   rB   r   r   r   r   r4   V   s   
r4   )r   r   r   )r   r   r   )r   r   r   )Ú
__future__r   Znumpyr   r   Úcommonr   r   Z
skipUnlessÚversionZhdf5_version_tupler   r,   r4   r   r   r   r   Ú<module>   s   #(