From 63bbebb1093d793a567cce6e52689d92bd37da46 Mon Sep 17 00:00:00 2001 From: Zachary Lentz Date: Mon, 11 Nov 2024 11:39:40 -0800 Subject: [PATCH] TST: include bad eggs and inproc testing for validate artifacts --- beams/tests/artifacts/bad_egg1.txt | 0 beams/tests/artifacts/bad_egg2.yaml | 26 +++++++++++++++++ beams/tests/artifacts/bad_egg3.json | 1 + beams/tests/artifacts/bad_egg4.json | 37 +++++++++++++++++++++++++ beams/tests/test_bin.py | 43 +++++++++++++++++++++-------- 5 files changed, 95 insertions(+), 12 deletions(-) create mode 100644 beams/tests/artifacts/bad_egg1.txt create mode 100644 beams/tests/artifacts/bad_egg2.yaml create mode 100644 beams/tests/artifacts/bad_egg3.json create mode 100644 beams/tests/artifacts/bad_egg4.json diff --git a/beams/tests/artifacts/bad_egg1.txt b/beams/tests/artifacts/bad_egg1.txt new file mode 100644 index 0000000..e69de29 diff --git a/beams/tests/artifacts/bad_egg2.yaml b/beams/tests/artifacts/bad_egg2.yaml new file mode 100644 index 0000000..761836a --- /dev/null +++ b/beams/tests/artifacts/bad_egg2.yaml @@ -0,0 +1,26 @@ +root: + CheckAndDoItem: + name: self_test + description: "" + check: + BinaryConditionItem: + name: self_test_check + description: "" + left_value: + EPICSValue: + pv_name: PERC:COMP + as_string: false + right_value: + FixedValue: + value: 100 + operator: ge + do: + name: self_test_do + description: "" + pv: PERC:COMP + increment: 10 + loop_period_sec: 0.01 + termination_check: + UseCheckConditionItem: + name: self_test_do_termination_check, + description: "Use parent's check node: self_test_check" diff --git a/beams/tests/artifacts/bad_egg3.json b/beams/tests/artifacts/bad_egg3.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/beams/tests/artifacts/bad_egg3.json @@ -0,0 +1 @@ +{} diff --git a/beams/tests/artifacts/bad_egg4.json b/beams/tests/artifacts/bad_egg4.json new file mode 100644 index 0000000..79b01e5 --- /dev/null +++ b/beams/tests/artifacts/bad_egg4.json @@ -0,0 +1,37 @@ +{ + "CheckAndDoItem": { + "name": "self_test", + "description": "", + "check": { + "BinaryConditionItem": { + "name": "self_test_check", + "description": "", + "left_value": { + "EPICSValue": { + "pv_name": "PERC:COMP", + "as_string": false + } + }, + "right_value": { + "FixedValue": { + "value": 100 + } + }, + "operator": "ge" + } + }, + "do": { + "name": "self_test_do", + "description": "", + "pv": "PERC:COMP", + "increment": 10, + "loop_period_sec": 0.01, + "termination_check": { + "UseCheckConditionItem": { + "name": "self_test_do_termination_check", + "description": "Use parent's check node: self_test_check" + } + } + } + } +} diff --git a/beams/tests/test_bin.py b/beams/tests/test_bin.py index 7350fab..0237a58 100644 --- a/beams/tests/test_bin.py +++ b/beams/tests/test_bin.py @@ -94,16 +94,35 @@ def mock_run(*args, **kwargs): assert not run_called -@pytest.mark.parametrize( - "artifact", - [ - "eggs", - "eggs2", - "eternal_guard", - "im2l0_test", - ] -) -def test_validate_artifacts_subproc(artifact: str): - test_cfg = (Path(__file__).parent / "artifacts" / f"{artifact}.json").resolve() +artifact_validation_codes = [ + # Standard test eggs should work + ("eggs.json", 0), + ("eggs2.json", 0), + ("eternal_guard.json", 0), + ("im2l0_test.json", 0), + # File not found error + ("no_egg", 2), + # Not even json, just empty! + ("bad_egg1.txt", 2), + # A yaml file + ("bad_egg2.yaml", 2), + # An empty dict + ("bad_egg3.json", 1), + # Missing root + ("bad_egg4.json", 1), +] + + +@pytest.mark.parametrize("artifact, return_code", artifact_validation_codes) +def test_validate_artifacts_subproc(artifact: str, return_code: int): + test_cfg = (Path(__file__).parent / "artifacts" / artifact).resolve() cproc = subprocess.run(["python3", "-m", "beams", "validate", str(test_cfg)], capture_output=True, universal_newlines=True) - assert cproc.returncode == 0, cproc.stdout + assert cproc.returncode == return_code, cproc.stdout + + +@pytest.mark.parametrize("artifact, return_code", artifact_validation_codes) +def test_validate_artifacts_inproc(artifact: str, return_code: int): + test_cfg = Path(__file__).parent / "artifacts" / artifact + args = ["beams", "validate", str(test_cfg)] + with cli_args(args), restore_logging(): + assert main() == return_code