Skip to content

Commit

Permalink
Confirm less than 17 labels provided during mbbi/mbbo record creation (
Browse files Browse the repository at this point in the history
…#33)

Raise an AssertionError when more than the maximum of 16 labels are provided during mbbi/mbbo record creation.
  • Loading branch information
AlexanderWells-diamond authored Aug 31, 2021
1 parent 30f5e0d commit 5e478cf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def process_value(prefix, value, option, severity=None):
fields[prefix + 'VL'] = value
if severity:
fields[prefix + 'SV'] = severity
# zip() silently ignores extra values in options, so explicitly check length
assert len(options) <= 16, "May not specify more than 16 enum values"
for prefix, (value, option) in zip(_mbbPrefixes, enumerate(options)):
if isinstance(option, tuple):
# The option is tuple consisting of the option name and an optional
Expand Down
8 changes: 8 additions & 0 deletions tests/test_records.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import pytest

from softioc import builder

Expand All @@ -10,3 +11,10 @@ def test_records(tmp_path):
builder.WriteRecords(path)
expected = os.path.join(os.path.dirname(__file__), "expected_records.db")
assert open(path).readlines()[4:] == open(expected).readlines()[4:]

def test_enum_length_restriction():
with pytest.raises(AssertionError):
builder.mbbIn(
"ManyLabels", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen")

0 comments on commit 5e478cf

Please sign in to comment.