Skip to content

Commit 5e478cf

Browse files
Confirm less than 17 labels provided during mbbi/mbbo record creation (#33)
Raise an AssertionError when more than the maximum of 16 labels are provided during mbbi/mbbo record creation.
1 parent 30f5e0d commit 5e478cf

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

softioc/builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def process_value(prefix, value, option, severity=None):
7070
fields[prefix + 'VL'] = value
7171
if severity:
7272
fields[prefix + 'SV'] = severity
73+
# zip() silently ignores extra values in options, so explicitly check length
74+
assert len(options) <= 16, "May not specify more than 16 enum values"
7375
for prefix, (value, option) in zip(_mbbPrefixes, enumerate(options)):
7476
if isinstance(option, tuple):
7577
# The option is tuple consisting of the option name and an optional

tests/test_records.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import pytest
23

34
from softioc import builder
45

@@ -10,3 +11,10 @@ def test_records(tmp_path):
1011
builder.WriteRecords(path)
1112
expected = os.path.join(os.path.dirname(__file__), "expected_records.db")
1213
assert open(path).readlines()[4:] == open(expected).readlines()[4:]
14+
15+
def test_enum_length_restriction():
16+
with pytest.raises(AssertionError):
17+
builder.mbbIn(
18+
"ManyLabels", "one", "two", "three", "four", "five", "six",
19+
"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
20+
"fourteen", "fifteen", "sixteen", "seventeen")

0 commit comments

Comments
 (0)