Skip to content

Commit

Permalink
Disallow specifying both our and EPICS keywords
Browse files Browse the repository at this point in the history
This stops us from accidentally overriding a "STAT" value if there's
also "status" defined, for example
  • Loading branch information
AlexanderWells-diamond committed Oct 14, 2022
1 parent 4edf6bd commit 421068e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 4 additions & 2 deletions softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ def _set_out_defaults(fields):
fields.setdefault('OMSL', 'supervisory')

def _set_alarm(fields):
if "status" in fields:
if 'status' in fields:
assert 'STAT' not in fields, 'Can\'t specify both status and STAT'
fields['STAT'] = _statStrings[fields.pop('status')]
if "severity" in fields:
if 'severity' in fields:
assert 'SEVR' not in fields, 'Can\'t specify both severity and SEVR'
fields['SEVR'] = _severityStrings[fields.pop('severity')]

# For longout and ao we want DRV{L,H} to match {L,H}OPR by default
Expand Down
30 changes: 30 additions & 0 deletions tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,36 @@ def test_setting_alarm_in_records(creation_func):
assert record.STAT.Value() == "LOLO"
assert record.SEVR.Value() == "MINOR"

@pytest.mark.parametrize("creation_func", in_records)
def test_setting_alarm_invalid_keywords(creation_func):
"""Test that In records correctly block specifying both STAT and status,
and SEVR and severity"""

kwargs = {}
if creation_func == builder.WaveformIn:
kwargs["length"] = 1

with pytest.raises(AssertionError) as e:
creation_func(
"NEW_RECORD",
severity=alarm.MINOR_ALARM,
SEVR="MINOR",
status=alarm.LOLO_ALARM,
**kwargs
)

assert e.value.args[0] == 'Can\'t specify both severity and SEVR'

with pytest.raises(AssertionError) as e:
creation_func(
"NEW_RECORD",
severity=alarm.MINOR_ALARM,
status=alarm.LOLO_ALARM,
STAT="LOLO",
**kwargs
)

assert e.value.args[0] == 'Can\'t specify both status and STAT'


def validate_fixture_names(params):
Expand Down

0 comments on commit 421068e

Please sign in to comment.