Skip to content
Snippets Groups Projects
Commit 2d34e7d3 authored by Karim Ahmed's avatar Karim Ahmed
Browse files

Initial commit for testing constants metadata

parent c5ebd75a
No related branches found
No related tags found
1 merge request!942[Tests] Validate metadata for retrieved constants before validating the corrected files
...@@ -13,6 +13,7 @@ from typing import Any, Dict, List, Tuple ...@@ -13,6 +13,7 @@ from typing import Any, Dict, List, Tuple
import h5py import h5py
import numpy as np import numpy as np
import pytest import pytest
import yaml
import xfel_calibrate.calibrate as calibrate import xfel_calibrate.calibrate as calibrate
...@@ -164,9 +165,9 @@ def validate_hdf5_files( ...@@ -164,9 +165,9 @@ def validate_hdf5_files(
test_key (str): The test name. test_key (str): The test name.
out_folder (pathlib.Path): The OUT folder for the tested data. out_folder (pathlib.Path): The OUT folder for the tested data.
reference_folder (pathlib.Path): The Reference folder for reference_folder (pathlib.Path): The Reference folder for
the reference data to validate against the reference data to validate against
cal_type (str): The type of calibration processing. cal_type (str): The type of calibration processing.
e.g. dark or correct. e.g. dark or correct.
""" """
print("\n--- Compare HDF5 files ----") print("\n--- Compare HDF5 files ----")
print("REF:", reference_folder) print("REF:", reference_folder)
...@@ -257,6 +258,22 @@ def slurm_watcher(test_key: str, std_out: str): ...@@ -257,6 +258,22 @@ def slurm_watcher(test_key: str, std_out: str):
LOGGER.info(f"{test_key}'s jobs were COMPLETED") LOGGER.info(f"{test_key}'s jobs were COMPLETED")
def compare_metadata_ccvs(test, reference, tested_key):
def load_yaml(file_path):
with open(file_path, 'r') as file:
return yaml.safe_load(file)
# Load the relevant section from both files
ccvs_test = load_yaml(test).get(tested_key, {})
ccvs_reference = load_yaml(reference).get(tested_key, {})
# Compare the content directly
if ccvs_test == ccvs_reference:
return True
else:
return False
@pytest.mark.manual_run @pytest.mark.manual_run
@pytest.mark.parametrize( @pytest.mark.parametrize(
"test_key, val_dict", "test_key, val_dict",
...@@ -317,10 +334,9 @@ def test_xfel_calibrate( ...@@ -317,10 +334,9 @@ def test_xfel_calibrate(
) )
report_name = out_folder / f"{test_key}_{datetime.now():%y%m%d_%H%M%S}" report_name = out_folder / f"{test_key}_{datetime.now():%y%m%d_%H%M%S}"
cal_conf["report-to"] = str(report_name) cal_conf["report-to"] = str(report_name)
cmd = parse_config(cmd, cal_conf, out_folder) cmd = parse_config(cmd, cal_conf, str(out_folder))
if only_validate: if only_validate:
assert validate_hdf5_files( assert validate_hdf5_files(
...@@ -359,6 +375,14 @@ def test_xfel_calibrate( ...@@ -359,6 +375,14 @@ def test_xfel_calibrate(
if time_counter > time_to_wait: if time_counter > time_to_wait:
assert False, f"{test_key} failure, report doesn't exists." assert False, f"{test_key} failure, report doesn't exists."
LOGGER.info("Report found.") LOGGER.info("Report found.")
# For corrections validate same calibration constants were retrieved.
metadata_file = f"calibration_metadata_{cal_conf['karabo-id']}"
assert compare_metadata_ccvs(
out_folder / metadata_file,
reference_folder / metadata_file,
"retrieved-constants",
), "Found difference in the metadata for the retrieved Constants."
# Stop tests at this point, if desired. # Stop tests at this point, if desired.
if not skip_numerical_validation: if not skip_numerical_validation:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment