-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add info tags to define PVI structure from controllers
Refactor helper functions to preserve PV prefix until later so that PVI PV can use it. Remove call to SetDeviceName and construct full PVs when creating records. Add call to create info tags on all records as they are created to add them to the PVI of the controller. Add call to add sub controller PVI to parent PVI
- Loading branch information
Showing
2 changed files
with
205 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,104 @@ | ||
from pytest_mock import MockerFixture | ||
|
||
from fastcs.backends.epics.ioc import EpicsIOC | ||
from fastcs.backends.epics.ioc import EpicsIOC, _add_pvi_info, _add_pvi_refs | ||
from fastcs.mapping import Mapping | ||
|
||
|
||
def test_ioc(mocker: MockerFixture, mapping: Mapping): | ||
builder_mock = mocker.patch("fastcs.backends.epics.ioc.builder") | ||
builder = mocker.patch("fastcs.backends.epics.ioc.builder") | ||
add_pvi_info = mocker.patch("fastcs.backends.epics.ioc._add_pvi_info") | ||
|
||
EpicsIOC("DEVICE", mapping) | ||
|
||
builder_mock.aIn.assert_called_once_with("ReadWriteFloat_RBV", PREC=2) | ||
builder_mock.aOut.assert_any_call( | ||
"ReadWriteFloat", always_update=True, on_update=mocker.ANY, PREC=2 | ||
# Check records are created | ||
builder.aIn.assert_called_once_with("DEVICE:ReadWriteFloat_RBV", PREC=2) | ||
builder.aOut.assert_any_call( | ||
"DEVICE:ReadWriteFloat", always_update=True, on_update=mocker.ANY, PREC=2 | ||
) | ||
builder_mock.boolIn.assert_called_once_with("ReadBool", ZNAM="OFF", ONAM="ON") | ||
builder_mock.boolOut.assert_called_once_with( | ||
"WriteBool", ZNAM="OFF", ONAM="ON", always_update=True, on_update=mocker.ANY | ||
builder.boolIn.assert_called_once_with("DEVICE:ReadBool", ZNAM="OFF", ONAM="ON") | ||
builder.boolOut.assert_called_once_with( | ||
"DEVICE:WriteBool", | ||
ZNAM="OFF", | ||
ONAM="ON", | ||
always_update=True, | ||
on_update=mocker.ANY, | ||
) | ||
builder_mock.longIn.assert_any_call("ReadInt") | ||
builder_mock.longIn.assert_any_call("ReadWriteInt_RBV") | ||
builder_mock.longOut.assert_called_with( | ||
"ReadWriteInt", always_update=True, on_update=mocker.ANY | ||
builder.longIn.assert_any_call("DEVICE:ReadInt") | ||
builder.longIn.assert_any_call("DEVICE:ReadWriteInt_RBV") | ||
builder.longOut.assert_called_with( | ||
"DEVICE:ReadWriteInt", always_update=True, on_update=mocker.ANY | ||
) | ||
builder_mock.longStringIn.assert_called_once_with("StringEnum_RBV") | ||
builder_mock.longStringOut.assert_called_once_with( | ||
"StringEnum", always_update=True, on_update=mocker.ANY | ||
builder.longStringIn.assert_called_once_with("DEVICE:StringEnum_RBV") | ||
builder.longStringOut.assert_called_once_with( | ||
"DEVICE:StringEnum", always_update=True, on_update=mocker.ANY | ||
) | ||
builder_mock.aOut.assert_any_call( | ||
"Go", initial_value=0, always_update=True, on_update=mocker.ANY | ||
builder.aOut.assert_any_call( | ||
"DEVICE:Go", initial_value=0, always_update=True, on_update=mocker.ANY | ||
) | ||
|
||
# Check info tags are added | ||
add_pvi_info.assert_has_calls( | ||
[ | ||
mocker.call(builder.boolIn.return_value, "DEVICE", "read_bool", "r"), | ||
mocker.call(builder.longIn.return_value, "DEVICE", "read_int", "r"), | ||
mocker.call(builder.aIn.return_value, "DEVICE", "read_write_float", "r"), | ||
mocker.call(builder.aOut.return_value, "DEVICE", "read_write_float", "w"), | ||
mocker.call(builder.longIn.return_value, "DEVICE", "read_write_int", "r"), | ||
mocker.call(builder.longOut.return_value, "DEVICE", "read_write_int", "w"), | ||
mocker.call( | ||
builder.longStringIn.return_value, "DEVICE", "string_enum", "r" | ||
), | ||
mocker.call( | ||
builder.longStringOut.return_value, "DEVICE", "string_enum", "w" | ||
), | ||
mocker.call(builder.boolOut.return_value, "DEVICE", "write_bool", "w"), | ||
mocker.call(builder.aOut.return_value, "DEVICE", "go", "x"), | ||
] | ||
) | ||
|
||
|
||
def test_add_pvi_info(mocker: MockerFixture): | ||
record = mocker.MagicMock() | ||
|
||
_add_pvi_info(record, "DEVICE", "attr", "r") | ||
|
||
record.add_info.assert_called_once_with( | ||
"Q:group", | ||
{ | ||
"DEVICE:PVI": { | ||
"pvi.attr.r": { | ||
"+channel": "NAME", | ||
"+type": "plain", | ||
"+trigger": "pvi.attr.r", | ||
} | ||
} | ||
}, | ||
) | ||
|
||
|
||
def test_add_pvi_refs(mocker: MockerFixture): | ||
builder = mocker.patch("fastcs.backends.epics.ioc.builder") | ||
controller = mocker.MagicMock() | ||
controller.path = [] | ||
child = mocker.MagicMock() | ||
child.path = ["Child"] | ||
controller.get_sub_controllers.return_value = {"d": child} | ||
|
||
_add_pvi_refs("DEVICE", controller) | ||
|
||
builder.longStringIn.assert_called_once_with( | ||
"DEVICE:Child:PVI_PV", initial_value="DEVICE:Child:PVI" | ||
) | ||
record = builder.longStringIn.return_value | ||
record.add_info.assert_called_once_with( | ||
"Q:group", | ||
{ | ||
"DEVICE:PVI": { | ||
"pvi.child.d": { | ||
"+channel": "VAL", | ||
"+type": "plain", | ||
"+trigger": "pvi.child.d", | ||
} | ||
} | ||
}, | ||
) |