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

common out-folder and reference folder for tests

parent 795d78e8
No related branches found
No related tags found
1 merge request!610Add a pytest to run a dict of CALLAB test runs before releases
This diff is collapsed.
......@@ -17,13 +17,17 @@ import pathlib
import time
from contextlib import redirect_stdout
from subprocess import PIPE, run
from typing import Any, Dict, List
from typing import Any, Dict, List, Tuple
import pytest
import yaml
import xfel_calibrate.calibrate as calibrate
REFERENCE_FOLDER = "/gpfs/exfel/data/scratch/ahmedk/test/remove/pytest"
OUT_FOLDER = "/gpfs/exfel/data/scratch/ahmedk/test/remove/pytest"
with open("./callab_tests.yaml", "r") as f:
callab_test_dict = yaml.load(f)
......@@ -43,7 +47,7 @@ def validate_h5files(f, reference):
return filemd5(f) == filemd5(reference / f.name), f
def parse_config(cmd: List[str], config: Dict[str, Any]) -> List[str]:
def parse_config(cmd: List[str], config: Dict[str, Any], out_folder: str) -> List[str]:
"""Convert a dictionary to a list of arguments.
Values that are not strings will be cast.
......@@ -52,6 +56,7 @@ def parse_config(cmd: List[str], config: Dict[str, Any]) -> List[str]:
Booleans will be converted to a `--key` flag, where `key` is the
dictionary key.
"""
for key, value in config.items():
if ' ' in key or (isinstance(value, str) and ' ' in value):
raise ValueError('Spaces are not allowed', key, value)
......@@ -65,27 +70,33 @@ def parse_config(cmd: List[str], config: Dict[str, Any]) -> List[str]:
else:
if value in ['""', "''"]:
value = ""
if key == "out-folder":
value = out_folder
cmd += ["--{}".format(key), str(value)]
return cmd
@pytest.mark.manual_run
@pytest.mark.parametrize("calibration_test", list(callab_test_dict.items()))
def test_xfel_calibrate(calibration_test):
test_key, val_dict = calibration_test
cmd = ["xfel-calibrate", val_dict["det_type"], val_dict["cal_type"]]
cal_conf = val_dict["config"]
cal_conf["report-to"] = test_key
report_name = test_key
out_folder = pathlib.Path(cal_conf["out-folder"].format(
OUT_FOLDER, cal_conf["karabo-id"], test_key))
cmd = parse_config(cmd, cal_conf, out_folder)
test_cmd = ["xfel-calibrate", val_dict["det_type"], val_dict["cal_type"]]
conf_dict = val_dict["config"]
out_folder = pathlib.Path(conf_dict["out-folder"])
report_name = conf_dict["report-to"]
expected_dict = val_dict["expected"]
reference_out_folder = pathlib.Path(expected_dict["reference_out_folder"])
parse_config(test_cmd, val_dict["config"])
test_cmd += ["--slurm-name", test_key]
reference_folder = pathlib.Path(val_dict["reference-folder"].format(
REFERENCE_FOLDER, cal_conf["karabo-id"], test_key))
cmd += ["--slurm-name", test_key]
f = io.StringIO()
with redirect_stdout(f):
calibrate.run(test_cmd)
calibrate.run(cmd)
out_str = f.getvalue()
......@@ -120,7 +131,7 @@ def test_xfel_calibrate(calibration_test):
# 3rd Check number of produced h5 files.
h5files = list(out_folder.glob("*.h5"))
expected_h5files = list(reference_out_folder.glob("*.h5"))
expected_h5files = list(reference_folder.glob("*.h5"))
assert len(h5files) == len(expected_h5files), f"{test_key} failure, number of files are not as expected." # noqa
print(f"{test_key}'s calibration h5files numbers are as expected.")
......@@ -128,10 +139,10 @@ def test_xfel_calibrate(calibration_test):
non_valid_files = []
with multiprocessing.Pool() as pool:
result = pool.starmap(validate_h5files, zip(
h5files, len(h5files)*[reference_out_folder]))
h5files, len(h5files)*[reference_folder]))
for i in result:
all_files_validated.append(i[0])
if i[0]:
if not i[0]:
non_valid_files.append(i[1])
assert all(all_files_validated), f"{test_key} failure, while validating {non_valid_files}" # noqa
print(f"{test_key}'s calibration h5files are validated successfully.")
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