Skip to content

Commit

Permalink
TST: include bad eggs and inproc testing for validate artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
ZLLentz committed Nov 11, 2024
1 parent a9ab9c3 commit 63bbebb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 12 deletions.
Empty file.
26 changes: 26 additions & 0 deletions beams/tests/artifacts/bad_egg2.yaml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions beams/tests/artifacts/bad_egg3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
37 changes: 37 additions & 0 deletions beams/tests/artifacts/bad_egg4.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
43 changes: 31 additions & 12 deletions beams/tests/test_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 63bbebb

Please sign in to comment.