Skip to content
Snippets Groups Projects
Commit 48b7b75f authored by Vincent POLLET's avatar Vincent POLLET
Browse files

Test for timestamps writing

parent ec188036
Branches
Tags
1 merge request!19Write timestamps to file as dataset attributes along with data
Pipeline #54324 failed
...@@ -38,19 +38,30 @@ def test_stream_write(): ...@@ -38,19 +38,30 @@ def test_stream_write():
np.arange(12 * 52).astype(np.float64).reshape((12, 52)), np.arange(12 * 52).astype(np.float64).reshape((12, 52)),
] ]
for a_test_data in test_data: test_timestamps = [
np.linspace(0, 20*test_data[0].shape[0], test_data[0].shape[0]),
np.linspace(10, 10*test_data[1].shape[0], test_data[1].shape[0]),
np.linspace(100, 200*test_data[2].shape[0], test_data[2].shape[0]),
np.linspace(5, 6*test_data[3].shape[0], test_data[3].shape[0]),
]
for a_test_data, a_test_timestamps in zip(test_data, test_timestamps):
with StreamFile(resource_path("test/data/save_test.h5"), mode="w") as output_file: with StreamFile(resource_path("test/data/save_test.h5"), mode="w") as output_file:
stream = Stream("test_data") stream = Stream("test_data")
save_filter = stream.save(output_file) save_filter = stream.save(output_file)
for i in range(a_test_data.shape[0]): for i in range(a_test_data.shape[0]):
stream.put(a_test_data[i]) stream.put(a_test_data[i], a_test_timestamps[i])
with StreamFile(resource_path("test/data/save_test.h5"), mode="r") as input_file: with StreamFile(resource_path("test/data/save_test.h5"), mode="r") as input_file:
stream = Stream("test_data", input_file) stream = Stream("test_data", input_file)
data = stream.load() data = stream.load()
timestamps = input_file.get_stream_timestamps("test_data")
if np.isscalar(timestamps): # if there is only 1 frame, timestamps are returned as a scalar
timestamps = np.array([timestamps])
assert np.array_equal(data, a_test_data) assert np.array_equal(data, a_test_data)
assert data.dtype == a_test_data.dtype assert data.dtype == a_test_data.dtype
assert np.array_equal(timestamps, a_test_timestamps)
os.remove(resource_path("test/data/save_test.h5")) os.remove(resource_path("test/data/save_test.h5"))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment