Skip to content

Commit

Permalink
STY: Improve some comments related to annunciate option
Browse files Browse the repository at this point in the history
Also remove some un-needed annunciate-related test code
  • Loading branch information
Nolan Stelter committed Nov 14, 2023
1 parent cd3deba commit b479fe0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 33 deletions.
3 changes: 2 additions & 1 deletion slam/alarm_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def update_item(
item_to_update.filtered = False
# also ensure annunciate is enabled on application level (self.annunciate) and also for the current item.
if item_to_update.is_in_active_alarm_state() and (self.annunciate and item_to_update.annunciating):
# prints bell character, cross platform way to generate "beep" noise,
# prints bell character, cross platform way to generate "beep" noise
# (assuming the user has the bell-sound option enabled for their terminal),
# could be replaced with call to audio library for more sound options
print("\a")

Expand Down
38 changes: 6 additions & 32 deletions slam/tests/test_alarm_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_remove_item(tree_model):


def test_annunciation(tree_model):
"""Test making an update to an item that has already been placed in the alarm tree"""
"""Test that a beep noise is made when an alarm-item enters an active alarm state"""

tree_model.annunciate = True
alarm_item = AlarmItem(
Expand All @@ -164,9 +164,10 @@ def test_annunciation(tree_model):
tree_model.nodes.append(alarm_item)
tree_model.added_paths["TEST:PV"] = ["/path/to/TEST:PV"]

# To verify beep we check that bell character was printed to stdout,
# which when printed to stdout makes beep sound.
# Could replace with audio library if more sound options are wanted.
# To verify the beep happened we check that bell character was printed to stdout,
# which when printed to stdout makes beep sound
# (assuming the user has the bell-sound option enabled for their terminal).
# Could later replace with audio library if more sound options are wanted.
stdout_buffer = StringIO()
# redirect stdout to buffer
sys.stdout = stdout_buffer
Expand All @@ -187,31 +188,4 @@ def test_annunciation(tree_model):

captured_output = stdout_buffer.getvalue()
# checking for bell character
assert captured_output == "\x07\n"

# Verify the update applied successfully
assert tree_model.nodes[0].name == "TEST:PV"
assert tree_model.nodes[0].alarm_severity == AlarmSeverity.MINOR
assert tree_model.nodes[0].alarm_status == "alarm" or tree_model.nodes[0].alarm_status == "STATE_ALARM"
assert tree_model.nodes[0].alarm_value == "FAULT"
assert tree_model.nodes[0].pv_severity == AlarmSeverity.MINOR
assert tree_model.nodes[0].pv_status == "alarm_status"

# Send a disable update message, verify the alarm gets marked filtered
tree_model.update_item(
"TEST:PV",
"/path/to/TEST:PV",
AlarmSeverity.MINOR,
"Disabled",
None,
"FAULT",
AlarmSeverity.MINOR,
"alarm_status",
)
assert tree_model.nodes[0].filtered

# And then send a message re-enabling the alarm and verify it is marked enabled again
tree_model.update_item(
"TEST:PV", "/path/to/TEST:PV", AlarmSeverity.MINOR, "OK", None, "FAULT", AlarmSeverity.MINOR, "alarm_status"
)
assert not tree_model.nodes[0].filtered
assert captured_output == "\x07\n"

0 comments on commit b479fe0

Please sign in to comment.