diff --git a/superscore/tests/conftest.py b/superscore/tests/conftest.py index d30ff04..892a635 100644 --- a/superscore/tests/conftest.py +++ b/superscore/tests/conftest.py @@ -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' diff --git a/superscore/tests/test_client.py b/superscore/tests/test_client.py index bcd293a..e5cfb9d 100644 --- a/superscore/tests/test_client.py +++ b/superscore/tests/test_client.py @@ -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 @@ -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)