From e372952e71899489f20dd158cfceb8135dd5ce20 Mon Sep 17 00:00:00 2001 From: Devan Agrawal Date: Thu, 18 Jul 2024 09:54:11 -0700 Subject: [PATCH] TST: include Readback in test_client.py::test_apply The test didn't consider Readback handling because sample_database doesn't include any Readbacks. Rather than modify sample_database and possibly affect other tests, I've added a minimal fixture for considering a single Setpoint-Readback pair. --- superscore/tests/conftest.py | 21 +++++++++++++++++++++ superscore/tests/test_client.py | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/superscore/tests/conftest.py b/superscore/tests/conftest.py index 6458f96..b465838 100644 --- a/superscore/tests/conftest.py +++ b/superscore/tests/conftest.py @@ -680,6 +680,27 @@ def parameter_with_readback() -> Parameter: return setpoint +@pytest.fixture(scope='function') +def setpoint_with_readback() -> Setpoint: + """ + A simple setpoint-readback value pair + """ + readback = Readback( + uuid="7b30ddba-9fae-4691-988c-07384c29fe22", + pv_name="RBV", + description="A readback PV", + data=False, + ) + setpoint = Setpoint( + uuid="418ed1ab-f1cf-4188-8f4c-ae7cbaf00e6c", + pv_name="SET", + description="A setpoint PV", + data=True, + 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 8d3a6d6..0c60f2c 100644 --- a/superscore/tests/test_client.py +++ b/superscore/tests/test_client.py @@ -56,7 +56,7 @@ def test_gather_data(mock_client, sample_database): @patch('superscore.control_layers.core.ControlLayer.put') -def test_apply(put_mock, mock_client: Client, sample_database: Root): +def test_apply(put_mock, mock_client: Client, sample_database: Root, setpoint_with_readback): put_mock.return_value = MockTaskStatus() snap = sample_database.entries[3] mock_client.apply(snap) @@ -69,6 +69,10 @@ def test_apply(put_mock, mock_client: Client, sample_database: Root): mock_client.apply(snap, sequential=True) assert put_mock.call_count == 3 + put_mock.reset_mock() + mock_client.apply(setpoint_with_readback, sequential=True) + assert put_mock.call_count == 1 + @patch('superscore.control_layers.core.ControlLayer._get_one') def test_snap(