From 5e478cf2ac91804f19866a4331edf06b336ec3d3 Mon Sep 17 00:00:00 2001 From: AlexanderWells-diamond <79699091+AlexanderWells-diamond@users.noreply.github.com> Date: Tue, 31 Aug 2021 09:25:36 +0100 Subject: [PATCH] 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. --- softioc/builder.py | 2 ++ tests/test_records.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/softioc/builder.py b/softioc/builder.py index 964d651e..3e639d21 100644 --- a/softioc/builder.py +++ b/softioc/builder.py @@ -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 diff --git a/tests/test_records.py b/tests/test_records.py index a3778a5b..2d50973b 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -1,4 +1,5 @@ import os +import pytest from softioc import builder @@ -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")