Skip to content

Commit

Permalink
Merge branch 'develop' into tickets/CAP-1047
Browse files Browse the repository at this point in the history
  • Loading branch information
rbovill authored Jul 10, 2024
2 parents dde8d17 + 71d48bc commit d618584
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
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.
1 change: 1 addition & 0 deletions doc/news/interface_changes/DM-45062.linearstage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ErrorCode enum.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
<?xml-stylesheet type="text/xsl" href="http://lsst-sal.tuc.noao.edu/schema/SALEventSet.xsl"?>
<SALEventSet xmlns:xsi="http://lsst-sal.tuc.noao.edu/schema/SALEventSet.xsd">
<Enumeration>DetailedState_NotMovingState, DetailedState_MovingState</Enumeration>
<Enumeration>
ErrorCode_ConnectionFailed=1,
ErrorCode_DisableMotor=2,
ErrorCode_EnableMotor=3,
ErrorCode_Home=4,
ErrorCode_MoveAbsolute=5,
ErrorCode_MoveRelative=6,
ErrorCode_Position=7,
ErrorCode_Telemetry=8,
ErrorCode_Stop=9
</Enumeration>
<SALEvent>
<Subsystem>LinearStage</Subsystem>
<EFDB_Topic>LinearStage_logevent_detailedState</EFDB_Topic>
Expand Down
24 changes: 23 additions & 1 deletion python/lsst/ts/xml/enums/LinearStage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
__all__ = ["DetailedState"]
__all__ = ["DetailedState", "ErrorCode"]

import enum


class DetailedState(enum.IntEnum):
NOTMOVINGSTATE = 1
MOVINGSTATE = 2


class ErrorCode(enum.IntEnum):
"""Error codes that indicate why the CSC went to fault state."""

CONNECTION_FAILED = 1
"""Connection to the device failed."""
DISABLE_MOTOR = 2
"""Disabling the motor failed."""
ENABLE_MOTOR = 3
"""Enabling the motor failed."""
HOME = 4
"""Homing the stage failed."""
MOVE_ABSOLUTE = 5
"""The absolute move failed."""
MOVE_RELATIVE = 6
"""The relative move failed."""
POSITION = 7
"""Failed to get the position."""
TELEMETRY = 8
"""The telemetry loop failed."""
STOP = 9
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

0 comments on commit d618584

Please sign in to comment.