Skip to content

Commit

Permalink
clean up after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
jsouter committed Feb 12, 2025
1 parent df0af09 commit d3606ba
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 169 deletions.
8 changes: 6 additions & 2 deletions src/ophyd_async/tango/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from ._one_of_everything import ExampleStrEnum, OneOfEverythingTangoDevice
from ._one_of_everything import (
ExampleStrEnum,
OneOfEverythingTangoDevice,
everything_signal_info,
)

__all__ = ["ExampleStrEnum", "OneOfEverythingTangoDevice"]
__all__ = ["ExampleStrEnum", "OneOfEverythingTangoDevice", "everything_signal_info"]
112 changes: 21 additions & 91 deletions src/ophyd_async/tango/testing/_one_of_everything.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import textwrap
from dataclasses import dataclass
from random import choice
from typing import Any, Generic
from typing import Any, Generic, TypeVar

import numpy as np

from ophyd_async.core import (
Array1D,
DTypeScalar_co,
StrictEnum,
T,
)
from ophyd_async.testing import float_array_value, int_array_value
from tango import AttrDataFormat, AttrWriteType, DevState
from tango.server import Device, attribute, command

T = TypeVar("T")


class ExampleStrEnum(StrictEnum):
A = "AAA"
Expand Down Expand Up @@ -73,25 +74,26 @@ def random_value(self):
return array


attribute_datas = []
everything_signal_info = []


def add_ads(
my_list: list[AttributeData],
name: str,
tango_type: str,
py_type: type,
initial_scalar,
initial_spectrum,
choices,
):
my_list.append(AttributeData(name, tango_type, py_type, initial_scalar, choices))
my_list.append(
everything_signal_info.append(
AttributeData(name, tango_type, py_type, initial_scalar, choices)
)
everything_signal_info.append(
SpectrumData(
f"{name}_spectrum", tango_type, Array1D[py_type], initial_spectrum, choices
)
)
my_list.append(
everything_signal_info.append(
ImageData(
f"{name}_image",
tango_type,
Expand All @@ -103,7 +105,6 @@ def add_ads(


add_ads(
attribute_datas,
"str",
"DevString",
str,
Expand All @@ -112,91 +113,23 @@ def add_ads(
("four", "five", "six"),
)
add_ads(
attribute_datas,
"bool",
"DevBoolean",
bool,
True,
np.array([False, True], dtype=bool),
(False, True),
)
add_ads("strenum", "DevEnum", StrictEnum, 1, np.array([0, 1, 2]), (0, 1, 2))
add_ads("int8", "DevShort", int, 1, int_array_value(np.int8), (1, 2, 3, 4, 5))
add_ads("uint8", "DevUChar", int, 1, int_array_value(np.uint8), (1, 2, 3, 4, 5))
add_ads("int16", "DevShort", int, 1, int_array_value(np.int16), (1, 2, 3, 4, 5))
add_ads("uint16", "DevUShort", int, 1, int_array_value(np.uint16), (1, 2, 3, 4, 5))
add_ads("int32", "DevLong", int, 1, int_array_value(np.int32), (1, 2, 3, 4, 5))
add_ads("uint32", "DevULong", int, 1, int_array_value(np.uint32), (1, 2, 3, 4, 5))
add_ads("int64", "DevLong64", int, 1, int_array_value(np.int64), (1, 2, 3, 4, 5))
add_ads("uint64", "DevULong64", int, 1, int_array_value(np.uint64), (1, 2, 3, 4, 5))
add_ads(
attribute_datas, "strenum", "DevEnum", StrictEnum, 1, np.array([0, 1, 2]), (0, 1, 2)
) # right py_type?
add_ads(
attribute_datas,
"int8",
"DevShort",
int,
1,
int_array_value(np.int8),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"uint8",
"DevUChar",
int,
1,
int_array_value(np.uint8),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"int16",
"DevShort",
int,
1,
int_array_value(np.int16),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"uint16",
"DevUShort",
int,
1,
int_array_value(np.uint16),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"int32",
"DevLong",
int,
1,
int_array_value(np.int32),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"uint32",
"DevULong",
int,
1,
int_array_value(np.uint32),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"int64",
"DevLong64",
int,
1,
int_array_value(np.int64),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"uint64",
"DevULong64",
int,
1,
int_array_value(np.uint64),
(1, 2, 3, 4, 5),
)
add_ads(
attribute_datas,
"float32",
"DevFloat",
float,
Expand All @@ -205,7 +138,6 @@ def add_ads(
(1.234, 2.345, 3.456),
)
add_ads(
attribute_datas,
"float64",
"DevDouble",
float,
Expand All @@ -214,7 +146,6 @@ def add_ads(
(1.234, 2.345, 3.456),
)
add_ads(
attribute_datas,
"my_state",
"DevState",
DevState,
Expand All @@ -229,7 +160,7 @@ class OneOfEverythingTangoDevice(Device):

def initialize_dynamic_attributes(self):
self.reset_values()
for attr_data in attribute_datas:
for attr_data in everything_signal_info:
attr = attribute(
name=attr_data.name,
dtype=attr_data.tango_type,
Expand All @@ -245,7 +176,6 @@ def initialize_dynamic_attributes(self):
)
self.add_attribute(attr)
self.set_change_event(attr.name, True, False)

if (
attr_data.tango_type == "DevUChar"
or attr_data.dformat == AttrDataFormat.IMAGE
Expand All @@ -269,7 +199,7 @@ def initialize_dynamic_attributes(self):

@command
def reset_values(self):
for attr_data in attribute_datas:
for attr_data in everything_signal_info:
self.attr_values[attr_data.name] = attr_data.initial_value

def read(self, attr):
Expand All @@ -288,6 +218,6 @@ def {}(self, arg):
"""
)

for attr_data in attribute_datas:
for attr_data in everything_signal_info:
if attr_data.dformat != AttrDataFormat.IMAGE:
exec(echo_command_code.format(f"{attr_data.name}_cmd"))
26 changes: 13 additions & 13 deletions tests/core/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,25 +375,25 @@ async def test_assert_reading_optional_fields(
):
# alarm_severity of 0 and timestamp of ANY supplied if none given
await assert_reading(
one_of_everything_device.int, {"everything-device-int": {"value": 1}}
one_of_everything_device.a_int, {"everything-device-a_int": {"value": 1}}
)

with pytest.raises(AssertionError):
await assert_reading(
one_of_everything_device.int,
{"everything-device-int": {"value": 1, "timestamp": -1}},
one_of_everything_device.a_int,
{"everything-device-a_int": {"value": 1, "timestamp": -1}},
)

with pytest.raises(AssertionError):
await assert_reading(
one_of_everything_device.int,
{"everything-device-int": {"value": 1, "alarm_severity": 1}},
one_of_everything_device.a_int,
{"everything-device-a_int": {"value": 1, "alarm_severity": 1}},
)

await assert_reading(
one_of_everything_device.int,
one_of_everything_device.a_int,
{
"everything-device-int": {
"everything-device-a_int": {
"value": 1,
"alarm_severity": 0,
"timestamp": time.monotonic(),
Expand Down Expand Up @@ -428,13 +428,13 @@ async def test_assert_configuration_everything(
"timestamp": ANY,
"alarm_severity": 0,
},
"everything-device-boola": {
"value": _array_vals["boola"],
"everything-device-a_enum": {
"value": "Bbb",
"timestamp": ANY,
"alarm_severity": 0,
},
"everything-device-enum": {
"value": "Bbb",
"everything-device-boola": {
"value": _array_vals["boola"],
"timestamp": ANY,
"alarm_severity": 0,
},
Expand Down Expand Up @@ -573,9 +573,9 @@ async def test_assert_reading_everything(
},
)
await assert_reading(
one_of_everything_device.enum,
one_of_everything_device.a_enum,
{
"everything-device-enum": {
"everything-device-a_enum": {
"value": ExampleEnum.B,
"timestamp": ANY,
"alarm_severity": 0,
Expand Down
Loading

0 comments on commit d3606ba

Please sign in to comment.