Skip to content

Commit

Permalink
Merge pull request #74 from dls-controls/add_disp_to_in_records
Browse files Browse the repository at this point in the history
Default DISP to TRUE for all In records
  • Loading branch information
Araneidae committed Dec 14, 2021
2 parents 5034531 + 0cda4cd commit 3866562
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
13 changes: 11 additions & 2 deletions .vscode/launch.json
Expand Up @@ -4,13 +4,22 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
},
{
"name": "Debug Unit Test",
"type": "python",
"request": "launch",
"justMyCode": false,
"program": "${file}",
"purpose": ["debug-test"],
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"env": {
// The default config in setup.cfg's "[tool:pytest]" adds coverage.
Expand All @@ -20,4 +29,4 @@
},
}
]
}
}
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -12,6 +12,7 @@ Unreleased_
Changed:

- `Remove python2 support <../../pull/64>`
- `Default DISP to TRUE for all In records <../../pull/74>`

3.2.1_ - 2021-11-25
-------------------
Expand Down
5 changes: 3 additions & 2 deletions softioc/builder.py
Expand Up @@ -18,12 +18,13 @@


def _in_record(record, name, **fields):
'''For input records we provide some automatic extra features: scanning
and initialisation as appropriate.'''
'''For input records we provide some automatic extra features: scanning,
initialisation as appropriate, and blocking puts from outside the IOC.'''

fields.setdefault('SCAN', 'I/O Intr')
if 'initial_value' in fields:
fields.setdefault('PINI', 'YES')
fields.setdefault('DISP', 1)
return getattr(PythonDevice, record)(name, **fields)


Expand Down
9 changes: 9 additions & 0 deletions tests/expected_records.db
@@ -1,5 +1,6 @@
record(ai, "TS-DI-TEST-01:AI")
{
field(DISP, "1")
field(DTYP, "Python")
field(INP, "@TS-DI-TEST-01:AI")
field(PINI, "YES")
Expand All @@ -14,6 +15,7 @@ record(ao, "TS-DI-TEST-01:AO")

record(bi, "TS-DI-TEST-01:BOOLIN")
{
field(DISP, "1")
field(DTYP, "Python")
field(INP, "@TS-DI-TEST-01:BOOLIN")
field(ONAM, "False")
Expand All @@ -33,6 +35,7 @@ record(bo, "TS-DI-TEST-01:BOOLOUT")

record(longin, "TS-DI-TEST-01:LONGIN")
{
field(DISP, "1")
field(DTYP, "Python")
field(INP, "@TS-DI-TEST-01:LONGIN")
field(MDEL, "-1")
Expand All @@ -49,6 +52,7 @@ record(longout, "TS-DI-TEST-01:LONGOUT")

record(waveform, "TS-DI-TEST-01:LONGSTRING")
{
field(DISP, "1")
field(DTYP, "Python")
field(FTVL, "UCHAR")
field(INP, "@TS-DI-TEST-01:LONGSTRING")
Expand All @@ -58,6 +62,7 @@ record(waveform, "TS-DI-TEST-01:LONGSTRING")

record(mbbi, "TS-DI-TEST-01:MBBI")
{
field(DISP, "1")
field(DTYP, "Python")
field(INP, "@TS-DI-TEST-01:MBBI")
field(ONST, "Two")
Expand Down Expand Up @@ -87,6 +92,7 @@ record(mbbo, "TS-DI-TEST-01:MBBO")

record(waveform, "TS-DI-TEST-01:SIN")
{
field(DISP, "1")
field(DTYP, "Python")
field(FTVL, "DOUBLE")
field(INP, "@TS-DI-TEST-01:SIN")
Expand All @@ -111,6 +117,7 @@ record(ao, "TS-DI-TEST-01:SINP")

record(stringin, "TS-DI-TEST-01:STRINGIN")
{
field(DISP, "1")
field(DTYP, "Python")
field(INP, "@TS-DI-TEST-01:STRINGIN")
field(PINI, "YES")
Expand All @@ -125,6 +132,7 @@ record(stringout, "TS-DI-TEST-01:STRINGOUT")

record(waveform, "TS-DI-TEST-01:WAVEFORM")
{
field(DISP, "1")
field(DTYP, "Python")
field(FTVL, "DOUBLE")
field(INP, "@TS-DI-TEST-01:WAVEFORM")
Expand All @@ -135,6 +143,7 @@ record(waveform, "TS-DI-TEST-01:WAVEFORM")

record(waveform, "TS-DI-TEST-01:WAVEFORM2")
{
field(DISP, "1")
field(DTYP, "Python")
field(FTVL, "FLOAT")
field(INP, "@TS-DI-TEST-01:WAVEFORM2")
Expand Down
33 changes: 33 additions & 0 deletions tests/test_records.py
Expand Up @@ -18,3 +18,36 @@ def test_enum_length_restriction():
"ManyLabels", "one", "two", "three", "four", "five", "six",
"seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen",
"fourteen", "fifteen", "sixteen", "seventeen")

def test_DISP_defaults_on():
"""Test that all IN record types have DISP=1 set by default"""
in_records = [
builder.aIn,
builder.boolIn,
builder.longIn,
builder.mbbIn,
builder.stringIn,
builder.WaveformIn,
]

record_counter = 0

for creation_func in in_records:
kwargs = {}
record_counter += 1
record_name = "DISP" + str(record_counter)

if creation_func == builder.WaveformIn:
kwargs = {"length": 1}

record = creation_func(record_name, **kwargs)

# Note: DISP attribute won't exist if field not specified
assert record.DISP.Value() == 1

def test_DISP_can_be_overridden():
"""Test that DISP can be forced off for In records"""

record = builder.longIn("DISP-OFF", DISP=0)
# Note: DISP attribute won't exist if field not specified
assert record.DISP.Value() == 0

0 comments on commit 3866562

Please sign in to comment.