Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use the calculated length if NELM was NOT provided during record creation #38

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't committed any vscode config yet as @Araneidae doesn't use vscode. However as there are now two of us doing this, maybe we should. What do you think @Araneidae ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, if we do go down that route we should probably just bring across all the .vscode settings from the template module, rather than what I've done here and just a small selection to get one particular piece working as I wanted.

"python.testing.pytestArgs": [],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
7 changes: 4 additions & 3 deletions docs/reference/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,10 @@ All functions return a wrapped `ProcessDeviceSupportIn` or

If ``value`` is specified or if an `initial_value` is specified (only one of
these can be used) the value is used to initialise the waveform and to
determine its field type and length. If no initial value is specified then
the keyword argument ``length`` must be used to specify the length of the
waveform.
determine its field type and length (the inferred values may be overridden using
keywords ``datatype`` and ``NELM`` respectively). If no initial value is specified
then the keyword argument ``length`` (or ``NELM``) must be used to specify the
length of the waveform.

The field type can be explicitly specified either by setting the ``datatype``
keyword to a Python type name, or by setting ``FTVL`` to the appropriate EPICS
Expand Down
7 changes: 6 additions & 1 deletion softioc/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def _waveform(value, fields):
'Can\'t specify FTVL and datatype together'
FTVL = NumpyCharCodeToFtvl[numpy.dtype(datatype).char]

fields['NELM'] = length
# If NELM has been explicitly set use that, otherwise use computed length
if 'NELM' not in fields:
fields['NELM'] = length
elif fields['NELM'] < length:
raise ValueError("NELM value shorter than value length")

fields.setdefault('FTVL', FTVL)


Expand Down
12 changes: 11 additions & 1 deletion tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from softioc import builder

import sim_records

import numpy

def test_records(tmp_path):
path = str(tmp_path / "records.db")
Expand All @@ -13,8 +13,18 @@ def test_records(tmp_path):
assert open(path).readlines()[5:] == open(expected).readlines()

def test_enum_length_restriction():
"""Test that supplying too many labels (more than maximum of 16) raises expected
exception"""
with pytest.raises(AssertionError):
builder.mbbIn(
"ManyLabels", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen")


def test__waveform_fields_nelm_used():
"""Test that the waveform construction returns the expected fields - i.e. NELM
is the same as the input value. Test for issue #37"""
fields = {"initial_value": numpy.array([1, 2, 3]), "NELM": 999}
builder._waveform(None, fields)
assert fields["NELM"] == 999