Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add enumaration consistency test. #879

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/news/DM-45170.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add enumaration consistency test.
31 changes: 31 additions & 0 deletions tests/test_enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@ def test_enumeration(xmlfile: pathlib.Path, csc: str, topic: str) -> None:
), f"Invalid enumeration in {csc}/{topic}: {enum_value.strip()} :: {sal_enum.text}."


@pytest.mark.parametrize("xmlfile,csc,topic", get_xmlfile_csc_topic())
def test_enumeration_consistency(xmlfile: pathlib.Path, csc: str, topic: str) -> None:
"""Test that the enumeration lines either all declare a value or none do.

Parameters
----------
xmlfile : `pathlib.Path`
Full filepath to the Events XML file for the CSC.
csc : `csc`
Name of the CSC
"""
# Test the topic <EFDB_Name> field.
with open(str(xmlfile), "r", encoding="utf-8") as f:
tree = et.parse(f)
root = tree.getroot()

for sal_enum in root.findall("Enumeration"):
assert sal_enum.text is not None
num_lines_with_explicit_value = 0
num_lines_without_explicit_value = 0
for enum_value in sal_enum.text.split(","):
if "=" in enum_value:
num_lines_with_explicit_value += 1
else:
num_lines_without_explicit_value += 1

assert (
num_lines_with_explicit_value == 0 or num_lines_without_explicit_value == 0
), f"Enumeration in {csc}/{topic} has mixed use cases."


@pytest.mark.parametrize("csc", subsystems)
def test_enum_classes(csc: str) -> None:
_, global_enums = get_field_and_global_enums(csc)
Expand Down
Loading