-
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.
- Loading branch information
Showing
6 changed files
with
156 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from pytest_mock import MockerFixture | ||
|
||
from fastcs.backends.epics.ioc import EpicsIOC | ||
from fastcs.mapping import Mapping | ||
|
||
|
||
def test_ioc(mocker: MockerFixture, mapping: Mapping): | ||
builder_mock = mocker.patch("fastcs.backends.epics.ioc.builder") | ||
|
||
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 | ||
) | ||
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_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_mock.longStringIn.assert_called_once_with("StringEnum_RBV") | ||
builder_mock.longStringOut.assert_called_once_with( | ||
"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 | ||
) |
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from functools import partial | ||
|
||
import pytest | ||
|
||
from fastcs.attributes import AttrR, AttrRW | ||
from fastcs.datatypes import Int, String | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_attributes(): | ||
device = {"state": "Idle", "number": 1, "count": False} | ||
ui = {"state": "", "number": 0, "count": False} | ||
|
||
async def update_ui(value, key): | ||
ui[key] = value | ||
|
||
async def send(value, key): | ||
device[key] = value | ||
|
||
async def device_add(): | ||
device["number"] += 1 | ||
|
||
attr_r = AttrR(String()) | ||
attr_r.set_update_callback(partial(update_ui, key="state")) | ||
await attr_r.set(device["state"]) | ||
assert ui["state"] == "Idle" | ||
|
||
attr_rw = AttrRW(Int()) | ||
attr_rw.set_process_callback(partial(send, key="number")) | ||
attr_rw.set_write_display_callback(partial(update_ui, key="number")) | ||
await attr_rw.process(2) | ||
assert device["number"] == 2 | ||
assert ui["number"] == 2 |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from time import sleep | ||
|
||
import pytest | ||
|
||
from fastcs.backend import Backend | ||
|
||
|
||
class DummyBackend(Backend): | ||
def __init__(self, controller): | ||
super().__init__(controller) | ||
|
||
self.init_task_called = False | ||
self._initial_tasks.append(self.init_task) | ||
|
||
async def init_task(self): | ||
self.init_task_called = True | ||
|
||
def _run(self): | ||
pass | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_backend(controller): | ||
backend = DummyBackend(controller) | ||
|
||
# Controller should be initialised by Backend, bit not connected | ||
assert controller.initialised | ||
assert not controller.connected | ||
|
||
# Controller Attributes with a Sender should have a _process_callback created | ||
assert controller.read_write_int.has_process_callback() | ||
|
||
backend.run() | ||
|
||
# Controller should have been connected by Backend | ||
assert controller.connected | ||
|
||
# Initial tasks should be complete | ||
assert backend.init_task_called | ||
|
||
# Scan tasks should be running | ||
for _ in range(3): | ||
count = controller.count | ||
sleep(0.05) | ||
assert controller.count > count |