|
| 1 | +import pytest |
| 2 | +from ophyd_async.core import DeviceVector, SubsetEnum, init_devices |
| 3 | +from ophyd_async.testing import assert_reading, partial_reading, set_mock_value |
| 4 | + |
| 5 | +from dodal.devices.i19.mapt_configuration import ( |
| 6 | + MAPTConfigurationControl, |
| 7 | + MAPTConfigurationTable, |
| 8 | +) |
| 9 | + |
| 10 | + |
| 11 | +class ConfigEnumTest(SubsetEnum): |
| 12 | + TEN = "10um" |
| 13 | + TWENTY = "20um" |
| 14 | + |
| 15 | + |
| 16 | +@pytest.fixture |
| 17 | +async def mapt_table() -> MAPTConfigurationTable: |
| 18 | + async with init_devices(mock=True): |
| 19 | + mapt = MAPTConfigurationTable("", "FakeMotor", [10, 20], "test_mapt") |
| 20 | + set_mock_value(mapt.in_positions[10], 30) |
| 21 | + set_mock_value(mapt.in_positions[20], 18) |
| 22 | + return mapt |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture |
| 26 | +async def mapt_control() -> MAPTConfigurationControl: |
| 27 | + async with init_devices(mock=True): |
| 28 | + mapt_c = MAPTConfigurationControl("", ConfigEnumTest, "test_control") |
| 29 | + set_mock_value(mapt_c.select_config, ConfigEnumTest.TEN) |
| 30 | + return mapt_c |
| 31 | + |
| 32 | + |
| 33 | +def test_mapt_table_created_without_errors(): |
| 34 | + mapt = MAPTConfigurationTable("", "FakeMotor", [5], "test_mapt") |
| 35 | + assert isinstance(mapt, MAPTConfigurationTable) |
| 36 | + assert isinstance(mapt.in_positions, DeviceVector) |
| 37 | + |
| 38 | + |
| 39 | +async def test_mapt_table_can_be_read(mapt_table: MAPTConfigurationTable): |
| 40 | + await assert_reading( |
| 41 | + mapt_table, |
| 42 | + { |
| 43 | + "test_mapt-in_positions-10": partial_reading(30), |
| 44 | + "test_mapt-in_positions-20": partial_reading(18), |
| 45 | + }, |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +def test_mapt_control_created_without_errors(): |
| 50 | + control = MAPTConfigurationControl("", ConfigEnumTest, "test_control") |
| 51 | + assert isinstance(control, MAPTConfigurationControl) |
| 52 | + |
| 53 | + |
| 54 | +async def test_mapt_control_signal_can_be_read(mapt_control: MAPTConfigurationControl): |
| 55 | + await assert_reading( |
| 56 | + mapt_control, {"test_control-select_config": partial_reading("10um")} |
| 57 | + ) |
| 58 | + |
| 59 | + |
| 60 | +async def test_select_new_config_value(mapt_control: MAPTConfigurationControl): |
| 61 | + await mapt_control.select_config.set(ConfigEnumTest.TWENTY) |
| 62 | + |
| 63 | + assert await mapt_control.select_config.get_value() == "20um" |
0 commit comments