From 3738dafc74f14a248634f6d6f43a008e8cedb981 Mon Sep 17 00:00:00 2001 From: Kurt Biery Date: Mon, 17 Nov 2025 14:41:20 -0600 Subject: [PATCH 1/2] Added the ability to pass in the expected value of the run_was_for_test_purposes HDF5 Attribute in the check_file_attributes function in data_file_checks.py --- src/integrationtest/data_file_checks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/integrationtest/data_file_checks.py b/src/integrationtest/data_file_checks.py index 41f9d22..a525a59 100644 --- a/src/integrationtest/data_file_checks.py +++ b/src/integrationtest/data_file_checks.py @@ -55,7 +55,11 @@ def sanity_check(datafile): print("\N{WHITE HEAVY CHECK MARK} Sanity-check passed") return passed -def check_file_attributes(datafile): +# 17-Nov-2025, KAB: added the 'was_test_run' function argument to allow us +# to validate the run_was_for_test_purposes Attribute value. Valid values +# are the strings "true" and "false", which is easiest given that the values +# in the HDF5 Attribute are lower-case strings. +def check_file_attributes(datafile, was_test_run="true"): "Checking that the expected Attributes exist within the data file" passed=True base_filename = os.path.basename(datafile.h5file.filename) @@ -103,6 +107,12 @@ def check_file_attributes(datafile): passed=False print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({date_string}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") print(f"\N{POLICE CARS REVOLVING LIGHT} Debug information: pattern_low={pattern_low} pattern_high={pattern_high} pattern_exact={pattern_exact} \N{POLICE CARS REVOLVING LIGHT}") + elif expected_attr_name == "run_was_for_test_purposes": + # value from the Attribute + attr_value = datafile.h5file.attrs.get(expected_attr_name) + if attr_value != was_test_run: + passed=False + print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({attr_value}) does not match the expected value ({was_test_run}) \N{POLICE CARS REVOLVING LIGHT}") if passed: print(f"\N{WHITE HEAVY CHECK MARK} All Attribute tests passed for file {base_filename}") return passed From e0521e3eff40b70689d19c836f95043b4e0206fc Mon Sep 17 00:00:00 2001 From: Kurt Biery Date: Mon, 17 Nov 2025 15:22:31 -0600 Subject: [PATCH 2/2] Moved the printout of the HDF5 filename from check_file_attributes to sanity_check in data_file_checks.py --- src/integrationtest/data_file_checks.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/integrationtest/data_file_checks.py b/src/integrationtest/data_file_checks.py index a525a59..ec6acee 100644 --- a/src/integrationtest/data_file_checks.py +++ b/src/integrationtest/data_file_checks.py @@ -33,6 +33,7 @@ def __init__(self, filename): def sanity_check(datafile): "Very basic sanity checks on file" passed=True + base_filename = os.path.basename(datafile.h5file.filename) print("") # Clear potential dot from pytest # execute unit tests for local function(s) @@ -52,7 +53,9 @@ def sanity_check(datafile): print(f"\N{POLICE CARS REVOLVING LIGHT} More than one TriggerRecordHeader in record {event} \N{POLICE CARS REVOLVING LIGHT}") passed=False if passed: - print("\N{WHITE HEAVY CHECK MARK} Sanity-check passed") + print(f"\N{WHITE HEAVY CHECK MARK} Sanity-check passed for file {base_filename}") + else: + print(f"\N{POLICE CARS REVOLVING LIGHT} One or more sanity-checks failed for file {base_filename} \N{POLICE CARS REVOLVING LIGHT}") return passed # 17-Nov-2025, KAB: added the 'was_test_run' function argument to allow us @@ -80,7 +83,7 @@ def check_file_attributes(datafile, was_test_run="true"): filename_value = int(re.sub('run','',re.sub('_','',match_obj.group(0)))) if attr_value != filename_value: passed=False - print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({attr_value}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") + print(f"\N{POLICE CARS REVOLVING LIGHT} The value in HDF5 File Attribute '{expected_attr_name}' ({attr_value}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") elif expected_attr_name == "file_index": # value from the Attribute attr_value = datafile.h5file.attrs.get(expected_attr_name) @@ -91,7 +94,7 @@ def check_file_attributes(datafile, was_test_run="true"): filename_value = int(re.sub('_','',match_obj.group(0))) if attr_value != filename_value: passed=False - print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({attr_value}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") + print(f"\N{POLICE CARS REVOLVING LIGHT} The value in HDF5 File Attribute '{expected_attr_name}' ({attr_value}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") elif expected_attr_name == "creation_timestamp": attr_value = datafile.h5file.attrs.get(expected_attr_name) date_obj = datetime.datetime.fromtimestamp((int(attr_value)/1000)-1, datetime.timezone.utc) @@ -105,16 +108,16 @@ def check_file_attributes(datafile, was_test_run="true"): pattern_exact = f".*{date_string}.*" if not re.match(pattern_exact, base_filename) and not re.match(pattern_low, base_filename) and not re.match(pattern_high, base_filename): passed=False - print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({date_string}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") + print(f"\N{POLICE CARS REVOLVING LIGHT} The value in HDF5 File Attribute '{expected_attr_name}' ({date_string}) does not match the value in the filename ({base_filename}) \N{POLICE CARS REVOLVING LIGHT}") print(f"\N{POLICE CARS REVOLVING LIGHT} Debug information: pattern_low={pattern_low} pattern_high={pattern_high} pattern_exact={pattern_exact} \N{POLICE CARS REVOLVING LIGHT}") elif expected_attr_name == "run_was_for_test_purposes": # value from the Attribute attr_value = datafile.h5file.attrs.get(expected_attr_name) if attr_value != was_test_run: passed=False - print(f"\N{POLICE CARS REVOLVING LIGHT} The value in Attribute '{expected_attr_name}' ({attr_value}) does not match the expected value ({was_test_run}) \N{POLICE CARS REVOLVING LIGHT}") + print(f"\N{POLICE CARS REVOLVING LIGHT} The value in HDF5 File Attribute '{expected_attr_name}' ({attr_value}) does not match the expected value ({was_test_run}) \N{POLICE CARS REVOLVING LIGHT}") if passed: - print(f"\N{WHITE HEAVY CHECK MARK} All Attribute tests passed for file {base_filename}") + print(f"\N{WHITE HEAVY CHECK MARK} All Attribute tests passed") return passed def check_event_count(datafile, expected_value, tolerance):