11import h5py
22import numpy as np
33import time
4- import os
54import multiprocessing as mp
65from swmr_tools import KeyFollower , DataSource
76from functools import reduce
@@ -31,6 +30,7 @@ def test_multiple_keys(tmp_path):
3130
3231 assert current_key == 5
3332
33+
3434def test_complete_keys (tmp_path ):
3535
3636 f = str (tmp_path / "f.h5" )
@@ -54,6 +54,7 @@ def test_complete_keys(tmp_path):
5454
5555 assert current_key == 10
5656
57+
5758def test_data_read (tmp_path ):
5859
5960 f = str (tmp_path / "f.h5" )
@@ -74,6 +75,7 @@ def test_data_read(tmp_path):
7475 assert np .all (d == base + (20 * count ))
7576 count = count + 1
7677
78+
7779def test_use_case_example (tmp_path ):
7880
7981 f = str (tmp_path / "f.h5" )
@@ -94,32 +96,33 @@ def test_use_case_example(tmp_path):
9496 for dset in df :
9597 d = dset ["/data" ]
9698 d = d .squeeze ()
97- r = d .sum (axis = 1 )
98- assert dset .maxshape == (2 ,3 )
99+ r = d .sum (axis = 1 )
100+ assert dset .maxshape == (2 , 3 )
99101
100102 if output is None :
101- output = df .create_dataset (r ,oh ,output_path )
103+ output = df .create_dataset (r , oh , output_path )
102104 else :
103- df .append_data (r ,dset .slice_metadata ,output )
105+ df .append_data (r , dset .slice_metadata , output )
104106
105107 with h5py .File (o , "r" ) as oh :
106108 out = oh ["/result" ]
107- assert out .shape == (2 ,3 , 4 )
108- assert out .maxshape == (2 ,3 , 4 )
109+ assert out .shape == (2 , 3 , 4 )
110+ assert out .maxshape == (2 , 3 , 4 )
109111 print (out [...])
110- assert 119 + 118 + 117 + 116 + 115 == out [1 ,2 ,3 ]
111- assert out [0 ,1 ,0 ] != 0
112+ assert 119 + 118 + 117 + 116 + 115 == out [1 , 2 , 3 ]
113+ assert out [0 , 1 , 0 ] != 0
114+
112115
113116def test_mock_scan (tmp_path ):
114117 f = str (tmp_path / "scan.h5" )
115118
116- mp .set_start_method (' spawn' )
117- p = mp .Process (target = mock_scan , args = (f ,))
119+ mp .set_start_method (" spawn" )
120+ p = mp .Process (target = mock_scan , args = (f ,))
118121 p .start ()
119122
120- DataSource .check_file_readable (f , ["/data" ,"/key" ], timeout = 5 )
123+ DataSource .check_file_readable (f , ["/data" , "/key" ], timeout = 5 )
121124
122- with h5py .File (f , "r" , libver = "latest" , swmr = True ) as fh :
125+ with h5py .File (f , "r" , libver = "latest" , swmr = True ) as fh :
123126
124127 data_paths = ["/data" ]
125128 key_paths = ["/key" ]
@@ -130,11 +133,12 @@ def test_mock_scan(tmp_path):
130133 assert p .is_alive ()
131134 for dset in df :
132135 d = dset ["/data" ]
133- assert d [0 ,0 , 0 ].item () == count
136+ assert d [0 , 0 , 0 ].item () == count
134137 count = count + 1
135138
136139 p .join ()
137140
141+
138142def create_test_file (path ):
139143
140144 with h5py .File (path , "w" ) as fh :
@@ -149,7 +153,7 @@ def create_test_file(path):
149153
150154def mock_scan (path ):
151155
152- with h5py .File (path , "w" , libver = "latest" ) as fh :
156+ with h5py .File (path , "w" , libver = "latest" ) as fh :
153157 maxn = 10
154158 maxshape = (maxn , 9 , 10 )
155159 shape = (1 , 9 , 10 )
@@ -161,14 +165,13 @@ def mock_scan(path):
161165 ks = fh .create_dataset ("key" , data = k , maxshape = (20 ,))
162166 fh .swmr_mode = True
163167 for i in range (maxn ):
164- s = (i + 1 , 9 , 10 )
168+ s = (i + 1 , 9 , 10 )
165169 if i != 0 :
166170 ds .resize (s )
167- ks .resize ((i + 1 ,))
168- ds [i ,:, :] = np .ones (shape ) + i
171+ ks .resize ((i + 1 ,))
172+ ds [i , :, :] = np .ones (shape ) + i
169173 ds .flush ()
170174 ks [i ] = 1
171175 ks .flush ()
172176 print ("flush " + str (i ))
173177 time .sleep (1 )
174-
0 commit comments