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

use deepDiff to find difference in dictionaries

parent d269d58c
No related branches found
No related tags found
1 merge request!942[Tests] Validate metadata for retrieved constants before validating the corrected files
......@@ -153,6 +153,7 @@ setup(
],
"test": [
"coverage",
"deepdiff==6.7.1",
"nbval",
"pytest-asyncio",
"pytest-cov",
......@@ -163,6 +164,7 @@ setup(
],
"automated_test": [
"coverage",
"deepdiff==6.7.1",
"nbval",
"pytest-asyncio",
"pytest-cov",
......
......@@ -14,6 +14,7 @@ import h5py
import numpy as np
import pytest
import yaml
from deepdiff import DeepDiff
import xfel_calibrate.calibrate as calibrate
......@@ -258,21 +259,10 @@ 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)
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(
......@@ -379,11 +369,13 @@ def test_xfel_calibrate(
if cal_type.lower() == "correct":
# For corrections validate calibration constants
metadata_file = f"calibration_metadata_{cal_conf['karabo-id']}.yml"
assert compare_metadata_ccvs(
out_folder / metadata_file,
reference_folder / metadata_file,
"retrieved-constants",
), "Found difference in the metadata for the retrieved Constants."
# Load the relevant section from both files
ccvs_test = load_yaml(
out_folder / metadata_file)["retrieved-constants"]
ccvs_reference = load_yaml(
reference_folder / metadata_file)["retrieved-constants"]
ccvs_diff = DeepDiff(ccvs_test, ccvs_reference, ignore_order=True)
assert ccvs_diff == {}, "Found difference in the metadata for the retrieved Constants." # noqa
LOGGER.info("Retrieved CCVs validated.")
# Stop tests at this point, if desired.
......
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