Skip to content

Commit

Permalink
TST: add Client.record test
Browse files Browse the repository at this point in the history
  • Loading branch information
shilorigins committed Jul 16, 2024
1 parent 0643f96 commit 5a55536
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
19 changes: 19 additions & 0 deletions superscore/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,25 @@ def sample_database() -> Root:
return root


@pytest.fixture(scope='function')
def parameter_with_readback() -> Parameter:
"""
A simple setpoint-readback parameter pair
"""
readback = Parameter(
uuid="64772c61-c117-445b-b0c8-4c17fd1625d9",
pv_name="RBCK",
description="A readback PV",
)
setpoint = Parameter(
uuid="b508344d-1fe9-473b-8d43-9499d0e8e23f",
pv_name="SET",
description="A setpoint PV",
readback=readback,
)
return setpoint


@pytest.fixture(scope='function')
def filestore_backend(tmp_path: Path) -> FilestoreBackend:
fp = Path(__file__).parent / 'db' / 'filestore.json'
Expand Down
17 changes: 16 additions & 1 deletion superscore/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from superscore.backends.filestore import FilestoreBackend
from superscore.client import Client
from superscore.model import Root
from superscore.model import Readback, Root, Setpoint

from .conftest import MockTaskStatus

Expand Down Expand Up @@ -54,6 +54,21 @@ def test_apply(put_mock, mock_client: Client, sample_database: Root):
assert put_mock.call_count == 3


@patch('superscore.control_layers.core.ControlLayer.get')
def test_record(get_mock, mock_client, sample_database: Root, parameter_with_readback):
col = sample_database.entries[2]
col.children.append(parameter_with_readback)

get_mock.side_effect = range(5)
snapshot = mock_client.record(col)
assert get_mock.call_count == 5
assert all([snapshot.children[i].data == i for i in range(4)]) # children saved in order
setpoint = snapshot.children[-1]
assert isinstance(setpoint, Setpoint)
assert isinstance(setpoint.readback, Readback)
assert setpoint.readback.data == 4 # readback saved after setpoint


def test_from_cfg(sscore_cfg: str):
client = Client.from_config()
assert isinstance(client.backend, FilestoreBackend)
Expand Down

0 comments on commit 5a55536

Please sign in to comment.