
    1Vh                     P    d dl Zd dlZddlmZmZ  G d de      Z G d de      Zy)    N   )utTestCasec                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestDatasetSwmrRead| Testing SWMR functions when reading a dataset.
    Skip this test if the HDF5 library does not have the SWMR features.
    c                    t        j                  |        t        j                  d      j	                  d      | _        | j                  j                  ddd| j
                        | _        | j                  j                  }| j                  j                          t        j                  |dd	      | _        | j                  d   | _        y )
N   fdata)r
   N)chunksmaxshaper   rT)swmr)r   setUpnparangeastyper   r   create_datasetdsetfilenamecloseh5pyFile)selffnames     L/home/dcms/DCMS/lib/python3.12/site-packages/h5py/tests/test_dataset_swmr.pyr   zTestDatasetSwmrRead.setUp   s    tIIbM((-	FF))&W[W`W`)a	5#D1FF6N	    c                 N    | j                  | j                  j                         y)z/ Verify that the file is initially in SWMR modeN)
assertTruer   	swmr_moder   s    r   test_initial_swmr_mode_onz-TestDatasetSwmrRead.test_initial_swmr_mode_on   s    (()r   c                 P    | j                  | j                  | j                         y r   )assertArrayEqualr   r   r#   s    r   test_read_dataz"TestDatasetSwmrRead.test_read_data   s    dii3r   c                 8    | j                   j                          y r   )r   refreshr#   s    r   test_refreshz TestDatasetSwmrRead.test_refresh   s    		r   c                     | j                  t              5  d| j                  _        ddd       | j	                  | j                  j                         y# 1 sw Y   /xY w)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#   s    r   test_force_swmr_mode_on_raisesz2TestDatasetSwmrRead.test_force_swmr_mode_on_raises    sI     y) 	$#DFF	$(()	$ 	$   AAc                     | j                  t              5  d| j                  _        ddd       | j	                  | j                  j                         y# 1 sw Y   /xY w) 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#   s    r   test_force_swmr_mode_off_raisesz3TestDatasetSwmrRead.test_force_swmr_mode_off_raises'   sI     z* 	%$DFF	%(()	% 	%r/   N)
__name__
__module____qualname____doc__r   r$   r'   r*   r.   r3    r   r   r   r      s%    #*4**r   r   c                   4    e Zd ZdZd Zd Zd Zd Zd Zd Z	y)	TestDatasetSwmrWriter   c                    t        j                  | j                         dd      | _        t	        j
                  d      j                  d      | _        | j                  j                  dd| j                  j                  dd	
      | _
        y)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   rB   r   r#   s    r   r   zTestDatasetSwmrWrite.setUp4   sc     4;;=#h?IIaL'',	FF))&DIIOO\`kr)s	r   c                 N    | j                  | j                  j                         y)z3 Verify that the file is not initially in SWMR modeN)assertFalser   r"   r#   s    r   test_initial_swmr_mode_offz/TestDatasetSwmrWrite.test_initial_swmr_mode_offA   s    ))*r   c                 p    d| j                   _        | j                  | j                   j                         y)z  Switch to SWMR mode and verify TN)r   r"   r!   r#   s    r   test_switch_swmr_mode_onz-TestDatasetSwmrWrite.test_switch_swmr_mode_onE   s$    (()r   c                 0   d| j                   _        | j                  | j                   j                         | j                  t              5  d| j                   _        ddd       | j                  | j                   j                         y# 1 sw Y   /xY w)r1   TFN)r   r"   r!   r,   r2   r#   s    r    test_switch_swmr_mode_off_raisesz5TestDatasetSwmrWrite.test_switch_swmr_mode_off_raisesJ   sk      (()z* 	%$DFF	%(()	% 	%s   BBc                    d| j                   _        | j                  | j                   j                         | j                  j	                  | j
                  j                         | j
                  | j                  dd | j                  j                          | j                  j                          | j                  | j                  | j
                         y)z) Extend and flush a SWMR dataset
        TN)
r   r"   r!   r   resizer   rA   flushr)   r&   r#   s    r   test_extend_dsetz%TestDatasetSwmrWrite.test_extend_dsetT   s      (()		$))//+yy		!		 			dii3r   c                     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
                         y )NT)r?   r   )   r?   rP   )	r   r"   r!   r   rL   r   rM   r)   r&   r#   s    r   test_extend_dset_multiplez.TestDatasetSwmrWrite.test_extend_dset_multipleb   s   (()		$ 				!"		 			dii3		$ 				!"		 			dii!ndii8dii!ndii8r   N)
r4   r5   r6   r7   r   rF   rH   rJ   rN   rQ   r8   r   r   r:   r:   /   s&    
t+*
*49r   r:   )numpyr   r   commonr   r   r   r:   r8   r   r   <module>rT      s)       &*( &*PG98 G9r   