diff --git a/tests/tango/test_base_device.py b/tests/tango/test_base_device.py index 0d78e68e22..c0b79d425e 100644 --- a/tests/tango/test_base_device.py +++ b/tests/tango/test_base_device.py @@ -321,6 +321,27 @@ async def test_connect(tango_test_device): compare_values(values, await test_device.read()) +# -------------------------------------------------------------------- +@pytest.mark.asyncio +async def test_set_trl(tango_test_device): + values, description = await describe_class(tango_test_device) + + # async with DeviceCollector(): + # test_device = TestTangoReadable(trl=tango_test_device) + test_device = TestTangoReadable(name="test_device") + + with pytest.raises(ValueError) as excinfo: + test_device.set_trl(0) + assert "TRL must be a string." in str(excinfo.value) + + test_device.set_trl(tango_test_device) + await test_device.connect() + + assert test_device.name == "test_device" + assert description == await test_device.describe() + compare_values(values, await test_device.read()) + + # -------------------------------------------------------------------- @pytest.mark.asyncio @pytest.mark.parametrize("proxy", [True, False, None]) @@ -362,6 +383,8 @@ async def test_tango_demo(demo_test_context): counter_trls=["demo/counter/1", "demo/counter/2"], ) await detector.connect() + await detector.trigger() + await detector.mover.velocity.set(0.5) RE = RunEngine() diff --git a/tests/tango/test_tango_transport.py b/tests/tango/test_tango_transport.py index 05b4be26a0..4e951ba80e 100644 --- a/tests/tango/test_tango_transport.py +++ b/tests/tango/test_tango_transport.py @@ -11,6 +11,9 @@ prepare_device, ) +from ophyd_async.core import ( + NotConnected, +) from ophyd_async.tango import ( AttributeProxy, CommandProxy, @@ -593,13 +596,35 @@ async def test_tango_transport_source(echo_device): assert transport_source == source +# -------------------------------------------------------------------- +@pytest.mark.asyncio +async def test_tango_transport_datatype_allowed(echo_device): + await prepare_device(echo_device, "float_scalar_attr", 1.0) + source = echo_device + "/" + "float_scalar_attr" + backend = await make_backend(float, source) + + assert backend.datatype_allowed(int) + assert backend.datatype_allowed(float) + assert backend.datatype_allowed(str) + assert backend.datatype_allowed(bool) + assert backend.datatype_allowed(np.ndarray) + assert backend.datatype_allowed(Enum) + assert backend.datatype_allowed(DevState) + assert not backend.datatype_allowed(list) + + # -------------------------------------------------------------------- @pytest.mark.asyncio async def test_tango_transport_connect(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" - backend = await make_backend(float, source, connect=True) + backend = await make_backend(float, source, connect=False) assert backend is not None + await backend.connect() + backend.read_trl = "" + with pytest.raises(RuntimeError) as exc_info: + await backend.connect() + assert "trl not set" in str(exc_info.value) # -------------------------------------------------------------------- @@ -611,13 +636,23 @@ async def test_tango_transport_connect_and_store_config(echo_device): await transport._connect_and_store_config(source) assert transport.trl_configs[source] is not None + with pytest.raises(RuntimeError) as exc_info: + await transport._connect_and_store_config("") + assert "trl not set" in str(exc_info.value) + # -------------------------------------------------------------------- @pytest.mark.asyncio async def test_tango_transport_put(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" - transport = await make_backend(float, source, connect=True) + transport = await make_backend(float, source, connect=False) + + with pytest.raises(NotConnected) as exc_info: + await transport.put(1.0) + assert "Not connected" in str(exc_info.value) + + await transport.connect() source = transport.source("") await transport.put(2.0) val = await transport.proxies[source].get_w_value() @@ -643,6 +678,11 @@ async def test_tango_transport_get_reading(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" transport = await make_backend(float, source, connect=False) + + with pytest.raises(NotConnected) as exc_info: + await transport.put(1.0) + assert "Not connected" in str(exc_info.value) + await transport.connect() reading = await transport.get_reading() assert reading["value"] == 1.0 @@ -654,6 +694,11 @@ async def test_tango_transport_get_value(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" transport = await make_backend(float, source, connect=False) + + with pytest.raises(NotConnected) as exc_info: + await transport.put(1.0) + assert "Not connected" in str(exc_info.value) + await transport.connect() value = await transport.get_value() assert value == 1.0 @@ -665,6 +710,11 @@ async def test_tango_transport_get_setpoint(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" transport = await make_backend(float, source, connect=False) + + with pytest.raises(NotConnected) as exc_info: + await transport.put(1.0) + assert "Not connected" in str(exc_info.value) + await transport.connect() new_setpoint = 2.0 await transport.put(new_setpoint) @@ -678,6 +728,11 @@ async def test_set_callback(echo_device): await prepare_device(echo_device, "float_scalar_attr", 1.0) source = echo_device + "/" + "float_scalar_attr" transport = await make_backend(float, source, connect=False) + + with pytest.raises(NotConnected) as exc_info: + await transport.put(1.0) + assert "Not connected" in str(exc_info.value) + await transport.connect() val = None