diff --git a/tests/test_reference_runs/test_pre_deployment.py b/tests/test_reference_runs/test_pre_deployment.py index cdd8a0f015baca42d15d9f3aa123ff992786fbdb..152f0a4b4c20fa9b6a7b03680c692d08f7e8f57b 100644 --- a/tests/test_reference_runs/test_pre_deployment.py +++ b/tests/test_reference_runs/test_pre_deployment.py @@ -13,6 +13,7 @@ from typing import Any, Dict, List, Tuple import h5py import numpy as np import pytest +import yaml import xfel_calibrate.calibrate as calibrate @@ -164,9 +165,9 @@ def validate_hdf5_files( test_key (str): The test name. out_folder (pathlib.Path): The OUT folder for the tested data. 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. - e.g. dark or correct. + e.g. dark or correct. """ print("\n--- Compare HDF5 files ----") print("REF:", reference_folder) @@ -257,6 +258,22 @@ def slurm_watcher(test_key: str, std_out: str): 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.parametrize( "test_key, val_dict", @@ -317,10 +334,9 @@ def test_xfel_calibrate( ) report_name = out_folder / f"{test_key}_{datetime.now():%y%m%d_%H%M%S}" - 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: assert validate_hdf5_files( @@ -359,6 +375,14 @@ def test_xfel_calibrate( if time_counter > time_to_wait: assert False, f"{test_key} failure, report doesn't exists." 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. if not skip_numerical_validation: