Skip to content

Commit 421068e

Browse files
Disallow specifying both our and EPICS keywords
This stops us from accidentally overriding a "STAT" value if there's also "status" defined, for example
1 parent 4edf6bd commit 421068e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

softioc/builder.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ def _set_out_defaults(fields):
3131
fields.setdefault('OMSL', 'supervisory')
3232

3333
def _set_alarm(fields):
34-
if "status" in fields:
34+
if 'status' in fields:
35+
assert 'STAT' not in fields, 'Can\'t specify both status and STAT'
3536
fields['STAT'] = _statStrings[fields.pop('status')]
36-
if "severity" in fields:
37+
if 'severity' in fields:
38+
assert 'SEVR' not in fields, 'Can\'t specify both severity and SEVR'
3739
fields['SEVR'] = _severityStrings[fields.pop('severity')]
3840

3941
# For longout and ao we want DRV{L,H} to match {L,H}OPR by default

tests/test_records.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,36 @@ def test_setting_alarm_in_records(creation_func):
197197
assert record.STAT.Value() == "LOLO"
198198
assert record.SEVR.Value() == "MINOR"
199199

200+
@pytest.mark.parametrize("creation_func", in_records)
201+
def test_setting_alarm_invalid_keywords(creation_func):
202+
"""Test that In records correctly block specifying both STAT and status,
203+
and SEVR and severity"""
204+
205+
kwargs = {}
206+
if creation_func == builder.WaveformIn:
207+
kwargs["length"] = 1
208+
209+
with pytest.raises(AssertionError) as e:
210+
creation_func(
211+
"NEW_RECORD",
212+
severity=alarm.MINOR_ALARM,
213+
SEVR="MINOR",
214+
status=alarm.LOLO_ALARM,
215+
**kwargs
216+
)
217+
218+
assert e.value.args[0] == 'Can\'t specify both severity and SEVR'
219+
220+
with pytest.raises(AssertionError) as e:
221+
creation_func(
222+
"NEW_RECORD",
223+
severity=alarm.MINOR_ALARM,
224+
status=alarm.LOLO_ALARM,
225+
STAT="LOLO",
226+
**kwargs
227+
)
228+
229+
assert e.value.args[0] == 'Can\'t specify both status and STAT'
200230

201231

202232
def validate_fixture_names(params):

0 commit comments

Comments
 (0)