Skip to content

Commit

Permalink
improving coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
burkeds committed Sep 30, 2024
1 parent c029407 commit 632eccc
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
23 changes: 23 additions & 0 deletions tests/tango/test_base_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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()

Expand Down
59 changes: 57 additions & 2 deletions tests/tango/test_tango_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
prepare_device,
)

from ophyd_async.core import (
NotConnected,
)
from ophyd_async.tango import (
AttributeProxy,
CommandProxy,
Expand Down Expand Up @@ -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)


# --------------------------------------------------------------------
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit 632eccc

Please sign in to comment.