o
    bi                     @   sD   d dl Zd dlZddlmZmZ G dd deZG dd deZdS )    N   )utTestCasec                   @   @   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 )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 )
N   fdata)r   N)chunksmaxshaper
   rT)swmr)r   setUpnparangeastyper
   r	   create_datasetdsetfilenamecloseh5pyFile)selffname r   P/home/ubuntu/.local/lib/python3.10/site-packages/h5py/tests/test_dataset_swmr.pyr      s   

zTestDatasetSwmrRead.setUpc                 C      |  | jj dS )z/ Verify that the file is initially in SWMR modeN)
assertTruer	   	swmr_moder   r   r   r   test_initial_swmr_mode_on      z-TestDatasetSwmrRead.test_initial_swmr_mode_onc                 C   s   |  | j| j d S r   )assertArrayEqualr   r
   r!   r   r   r   test_read_data   s   z"TestDatasetSwmrRead.test_read_datac                 C   s   | j   d S r   )r   refreshr!   r   r   r   test_refresh   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)assertRaises	Exceptionr	   r    r   r!   r   r   r   test_force_swmr_mode_on_raises    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)   
ValueErrorr	   r    r   r!   r   r   r   test_force_swmr_mode_off_raises'   s   
z3TestDatasetSwmrRead.test_force_swmr_mode_off_raisesN)
__name__
__module____qualname____doc__r   r"   r%   r'   r+   r.   r   r   r   r   r      s    
r   c                   @   r   )TestDatasetSwmrWriter   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   r:   r   r!   r   r   r   r   4   s    zTestDatasetSwmrWrite.setUpc                 C   r   )z3 Verify that the file is not initially in SWMR modeN)assertFalser	   r    r!   r   r   r   test_initial_swmr_mode_offA   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    r   r!   r   r   r   test_switch_swmr_mode_onE   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 )r,   TFN)r	   r    r   r)   r-   r!   r   r   r    test_switch_swmr_mode_off_raisesJ   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    r   r   resizer
   r9   flushr&   r$   r!   r   r   r   test_extend_dsetT   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)r7   r   )   r7   rC   )	r	   r    r   r   r@   r
   rA   r&   r$   r!   r   r   r   test_extend_dset_multipleb   s   



z.TestDatasetSwmrWrite.test_extend_dset_multipleN)
r/   r0   r1   r2   r   r=   r>   r?   rB   rD   r   r   r   r   r3   /   s    
r3   )numpyr   r   commonr   r   r   r3   r   r   r   r   <module>   s
    (