o
    gi                     @   sV   d dl Zd dlZd dlZddlmZ G dd deZejjddG dd	 d	eZ	dS )
    N   )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   Z/home/ubuntu/SoloSpeech/.venv/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   z#Can't enable global SWMR flag twice)reasonc                   @   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   8   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_offE   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_onI   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_raisesN   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_dsetX   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_multiplef   s   



z.TestDatasetSwmrWrite.test_extend_dset_multipleN)
r.   r/   r0   r1   r   r=   r>   r?   rB   rD   r   r   r   r   r3   2   s    
r3   )
numpyr   pytestr   commonr   r   markthread_unsafer3   r   r   r   r   <module>   s    )