o
    ªi eÁ  ã                   @   s   d dl Zd dlZddlmZmZ e ejjdk d¡G dd„ deƒƒZ	e ejjdkd¡G d	d
„ d
eƒƒZ
e ejjdkd¡G dd„ deƒƒZdS )é    Né   )ÚutÚTestCase)r   é	   é²   z6SWMR is available. Skipping backwards compatible testsc                   @   ó@   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 )Ú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  | ¡ t d¡ d¡| _| jjddd| jd| _d S )Né   ÚfÚdata©r	   ©N©ÚchunksÚmaxshaper   )	r   ÚsetUpÚnpÚarangeÚastyper   r
   Úcreate_datasetÚdset©Úself© r   úK/var/www/myenv/lib/python3.10/site-packages/h5py/tests/test_dataset_swmr.pyr      s   
zTestSwmrNotAvailable.setUpc                 C   sT   | j j}| j  ¡  |  t¡ tj|ddd| _ W d   ƒ d S 1 s#w   Y  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   ó:   |   t¡ | j ¡  W d  ƒ dS 1 sw   Y  dS )zd If the SWMR feature is not available then Dataset.refresh() should throw an AttributeError
        N)r    ÚAttributeErrorr   Úrefreshr   r   r   r   Útest_refresh_raises   s   "ÿz(TestSwmrNotAvailable.test_refresh_raisesc                 C   r'   )zi If the SWMR feature is not available the Dataset.flush() should
        throw an AttributeError
        N)r    r(   r   Úflushr   r   r   r   Útest_flush_raises    s   "ÿz&TestSwmrNotAvailable.test_flush_raisesc                 C   s   | j jrJ ‚dS )z. The SWMR getter should just be False
        N)r
   Ú	swmr_moder   r   r   r   Útest_swmr_mode_false'   s   z)TestSwmrNotAvailable.test_swmr_mode_falsec                 C   sB   |   t¡ d| j_W d  ƒ n1 sw   Y  | jjrJ ‚dS )zl If the SWMR feature is not available, setting swmr_mode = True
        should raise a RuntimeError
        TN)r    ÚRuntimeErrorr
   r-   r   r   r   r   Útest_set_swmr_mode_raises,   s   
ÿz.TestSwmrNotAvailable.test_set_swmr_mode_raisesN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r*   r,   r.   r0   r   r   r   r   r      s    r   zSWMR requires HDF5 >= 1.9.178c                   @   r   )ÚTestDatasetSwmrReadú| Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c                 C   sh   t  | ¡ t d¡ d¡| _| jjddd| jd| _| jj	}| j 
¡  tj|ddd	| _| jd | _d S )
Nr	   r
   r   r   r   r   r   Tr   )r   r   r   r   r   r   r
   r   r   r   r   r"   r#   r$   r   r   r   r   :   s   

zTestDatasetSwmrRead.setUpc                 C   ó   |   | jj¡ dS )z/ Verify that the file is initially in SWMR modeN)Ú
assertTruer
   r-   r   r   r   r   Útest_initial_swmr_mode_onD   ó   z-TestDatasetSwmrRead.test_initial_swmr_mode_onc                 C   s   |   | j| j¡ d S r   )ÚassertArrayEqualr   r   r   r   r   r   Útest_read_dataH   s   z"TestDatasetSwmrRead.test_read_datac                 C   s   | j  ¡  d S r   )r   r)   r   r   r   r   Útest_refreshK   s   z TestDatasetSwmrRead.test_refreshc                 C   óD   |   t¡ d| j_W d  ƒ n1 sw   Y  |  | 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    Ú	Exceptionr
   r-   r8   r   r   r   r   Útest_force_swmr_mode_on_raisesN   s   
ÿz2TestDatasetSwmrRead.test_force_swmr_mode_on_raisesc                 C   r>   )úž 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-   r8   r   r   r   r   Útest_force_swmr_mode_off_raisesU   s   
ÿz3TestDatasetSwmrRead.test_force_swmr_mode_off_raisesN)
r1   r2   r3   r4   r   r9   r<   r=   r@   rB   r   r   r   r   r5   4   s    
r5   c                   @   r   )ÚTestDatasetSwmrWriter6   c                 C   sH   t j|  ¡ ddd| _t d¡ 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)Úlibveré   r
   r   )r   )é   r   )ÚshapeÚdtyper   r   N)r"   r#   Úmktempr
   r   r   r   r   r   rJ   r   r   r   r   r   r   c   s    zTestDatasetSwmrWrite.setUpc                 C   r7   )z3 Verify that the file is not initially in SWMR modeN)ÚassertFalser
   r-   r   r   r   r   Útest_initial_swmr_mode_offp   r:   z/TestDatasetSwmrWrite.test_initial_swmr_mode_offc                 C   s   d| j _|  | j j¡ dS )z  Switch to SWMR mode and verify TN)r
   r-   r8   r   r   r   r   Útest_switch_swmr_mode_ont   s   z-TestDatasetSwmrWrite.test_switch_swmr_mode_onc                 C   sZ   d| j _|  | j j¡ |  t¡ d| j _W d  ƒ n1 sw   Y  |  | j j¡ dS )rA   TFN)r
   r-   r8   r    r!   r   r   r   r   Ú test_switch_swmr_mode_off_raisesy   s   
ÿz5TestDatasetSwmrWrite.test_switch_swmr_mode_off_raisesc                 C   s^   d| j _|  | j j¡ | j | jj¡ | j| jdd…< | j ¡  | j ¡  |  	| j| j¡ dS )z) Extend and flush a SWMR dataset
        TN)
r
   r-   r8   r   Úresizer   rI   r+   r)   r;   r   r   r   r   Útest_extend_dsetƒ   s   

z%TestDatasetSwmrWrite.test_extend_dsetc                 C   sº   d| j _|  | j j¡ | j d¡ | j| jdd …< | j ¡  | j ¡  |  | j| j¡ | j d¡ | j| jdd …< | j ¡  | j ¡  |  | jdd… | j¡ |  | jdd… | j¡ d S )NT)rG   r   )é   rG   rR   )	r
   r-   r8   r   rP   r   r+   r)   r;   r   r   r   r   Útest_extend_dset_multiple‘   s   



z.TestDatasetSwmrWrite.test_extend_dset_multipleN)
r1   r2   r3   r4   r   rM   rN   rO   rQ   rS   r   r   r   r   rC   ]   s    
rC   )Únumpyr   r"   Úcommonr   r   Ú
skipUnlessÚversionÚhdf5_version_tupler   r5   rC   r   r   r   r   Ú<module>   s    ,(