Skip to content

Commit

Permalink
TST: Update annunciate test to check for bell character in stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolan Stelter committed Oct 2, 2023
1 parent 59512d9 commit 527a781
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions slam/alarm_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ def update_item(self, name: str, path: str, severity: AlarmSeverity, status: str
item_to_update.filtered = True
elif item_to_update.filtered:
item_to_update.filtered = False
print ('Status: ', status)
print ('Annunicating: ', item_to_update.annunciating)
if (status != "OK" and status != "Disabled" ) and item_to_update.annunciating:
print ("!!!alarm tripped for: ", name, ", is annunciating: ", item_to_update.annunciating)
# prints bell character, cross platform way to generate "beep" noise,
# could be replaced with call to audio library for more sound options
print ('\a')

self.layoutChanged.emit()

def update_model(self, item_path: str, values: dict) -> None:
Expand Down
21 changes: 11 additions & 10 deletions slam/tests/test_alarm_tree_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,23 @@ def test_annunciation(tree_model):
tree_model.nodes.append(alarm_item)
tree_model.added_paths['TEST:PV'] = ['/path/to/TEST:PV']

# Create a StringIO object to capture stdout
stdout_capture = StringIO()
stdout_buffer = StringIO()
# redirect stdout to buffer
sys.stdout = stdout_buffer

tree_model.update_item('TEST:PV', '/path/to/TEST:PV', AlarmSeverity.MINOR, 'STATE_ALARM', None, 'FAULT',
AlarmSeverity.MINOR, 'alarm_status')

captured_output = stdout_capture.getvalue()
print ("!!captured output: ", captured_output)
# or test that noise was played somehow?
assert 0 == 1
# restore original stdout stream
sys.stdout = sys.__stdout__

captured_output = stdout_buffer.getvalue()
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'
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'
Expand All @@ -166,6 +169,4 @@ def test_annunciation(tree_model):
# 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

stdout_capture.close()
assert not tree_model.nodes[0].filtered

0 comments on commit 527a781

Please sign in to comment.