From e32c2c2db8c224ebe4271782c9ed37a84d8199e5 Mon Sep 17 00:00:00 2001 From: Christian Bespin Date: Mon, 16 Dec 2024 13:57:11 +0100 Subject: [PATCH 1/2] TST: Cleaner interpretation test --- aidatlu/test/software_test.py | 38 ++++++----------------------------- 1 file changed, 6 insertions(+), 32 deletions(-) diff --git a/aidatlu/test/software_test.py b/aidatlu/test/software_test.py index 14b42b6..ee43bc2 100644 --- a/aidatlu/test/software_test.py +++ b/aidatlu/test/software_test.py @@ -4,43 +4,18 @@ from aidatlu.main.config_parser import TLUConfigure -def test_data_parser(): +def test_interpretation(): data_parser = DataParser() data_parser.interpret_data("raw_data_test.h5", "interpreted_data_test.h5") - -def test_interpreted_data(): - features = np.dtype( - [ - ("eventnumber", "u4"), - ("timestamp", "u4"), - ("overflow", "u4"), - ("eventtype", "u4"), - ("input1", "u4"), - ("input2", "u4"), - ("input3", "u4"), - ("input4", "u4"), - ("inpu5", "u4"), - ("input6", "u4"), - ("sc1", "u4"), - ("sc2", "u4"), - ("sc3", "u4"), - ("sc4", "u4"), - ("sc5", "u4"), - ("sc6", "u4"), - ] - ) - interpreted_data_path = "interpreted_data.h5" interpreted_test_data_path = "interpreted_data_test.h5" - with tb.open_file(interpreted_data_path, "r") as file: - table = file.root.interpreted_data - interpreted_data = np.array(table[:], dtype=features) + with tb.open_file(interpreted_data_path, "r") as h5_file: + interpreted_data = h5_file.root.interpreted_data[:] - with tb.open_file(interpreted_test_data_path, "r") as file: - table = file.root.interpreted_data - interpreted_test_data = np.array(table[:], dtype=features) + with tb.open_file(interpreted_test_data_path, "r") as h5_file: + interpreted_test_data = h5_file.root.interpreted_data[:] assert np.array_equal(interpreted_data, interpreted_test_data) @@ -56,6 +31,5 @@ def test_load_config(): if __name__ == "__main__": - test_data_parser() - test_interpreted_data() + test_interpretation() test_load_config() From 055e746a1d4892b9ba9b87fdb6c5a29f7aef25af Mon Sep 17 00:00:00 2001 From: Christian Bespin Date: Mon, 16 Dec 2024 14:22:16 +0100 Subject: [PATCH 2/2] TST: Use absolute file locations --- aidatlu/test/software_test.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/aidatlu/test/software_test.py b/aidatlu/test/software_test.py index ee43bc2..896d963 100644 --- a/aidatlu/test/software_test.py +++ b/aidatlu/test/software_test.py @@ -1,15 +1,24 @@ +from pathlib import Path + import numpy as np import tables as tb -from aidatlu.main.data_parser import DataParser from aidatlu.main.config_parser import TLUConfigure +from aidatlu.main.data_parser import DataParser + +BASE_PATH = Path(__file__).parent def test_interpretation(): + """Test data interpretation and compare to reference file + """ + data_parser = DataParser() - data_parser.interpret_data("raw_data_test.h5", "interpreted_data_test.h5") + data_parser.interpret_data( + BASE_PATH / "raw_data_test.h5", "interpreted_data_test.h5" + ) - interpreted_data_path = "interpreted_data.h5" - interpreted_test_data_path = "interpreted_data_test.h5" + interpreted_data_path = BASE_PATH / "interpreted_data.h5" + interpreted_test_data_path = BASE_PATH / "interpreted_data_test.h5" with tb.open_file(interpreted_data_path, "r") as h5_file: interpreted_data = h5_file.root.interpreted_data[:]