Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update core and tango tests to match structure of epics tests #723

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jsouter
Copy link
Contributor

@jsouter jsouter commented Jan 8, 2025

Closing #715
very WIP, I should rework the tango version of OneOfEverythingDevice to create signals for each type as scalar, spectrum and image, so I can combine test_tango_signals and test_tango_one_of_everything.

Also trying to rework MonitorQueue to use the existing assert_value/assert_reading methods

@@ -30,6 +31,7 @@
| Array1D[np.float32]
| Array1D[np.float64]
| np.ndarray
| IntEnum
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my brief skim of the docs, PyTango enumerations look like:

class MyEnum(IntEnum):
    ENUM_STRING1 = 0
    ENUM_STRING2 = 1

I guess this means that Tango enum string values can't contain spaces. The value is superfluous to us as we can set value by string like in EPICS.

I would prefer that we don't support this as a signal type, but instead may our own Enum to request, using the tango name as the value:

class MyEnum(StrictEnum):  # or SubsetEnum
    WHATEVER1 = "ENUM_STRING1"
    WHATEVER2 = "ENUM_STRING2"

We should then convert in the signal converter between the Tango IntEnum and the requested ophyd StrictEnum

Copy link
Contributor Author

@jsouter jsouter Jan 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, have figured out one way of doing converters for scalar/spectrum/image enum attributes. For the sake of working with assert_value etc it may be easiest if the converters return strs (or numpy arrays of strs), can create an Enum class in place in the converter but not sure if that provides much benefit.

The shift away from using IntEnums means we can currently use a StrictEnum with assert_value etc but we can't test those same values with the pytango provided assert_close.

will probably refactor soon, haven't tested puts via the converter yet.

src/ophyd_async/testing/_assert.py Outdated Show resolved Hide resolved
src/ophyd_async/testing/_assert.py Outdated Show resolved Hide resolved
Comment on lines 66 to 105
def get_every_signal_data():
# list containing necessary info to construct a signal of each type for multiple
# transports e.g. soft/epics/tango
return [
EverythingSignal("int", int, 1),
EverythingSignal("float", float, 1.234),
EverythingSignal("str", str, "test_string"),
EverythingSignal("bool", bool, True),
EverythingSignal("enum", ExampleEnum, ExampleEnum.B),
EverythingSignal("int8a", Array1D[np.int8], int_array_value(np.int8)),
EverythingSignal("uint8a", Array1D[np.uint8], int_array_value(np.uint8)),
EverythingSignal("int16a", Array1D[np.int16], int_array_value(np.int16)),
EverythingSignal("uint16a", Array1D[np.uint16], int_array_value(np.uint16)),
EverythingSignal("int32a", Array1D[np.int32], int_array_value(np.int32)),
EverythingSignal("uint32a", Array1D[np.uint32], int_array_value(np.uint32)),
EverythingSignal("int64a", Array1D[np.int64], int_array_value(np.int64)),
EverythingSignal("uint64a", Array1D[np.uint64], int_array_value(np.uint64)),
EverythingSignal(
"float32a", Array1D[np.float32], float_array_value(np.float32)
),
EverythingSignal(
"float64a", Array1D[np.float64], float_array_value(np.float64)
),
EverythingSignal("stra", Sequence[str], ["one", "two", "three"]),
EverythingSignal(
"enuma", Sequence[ExampleEnum], [ExampleEnum.A, ExampleEnum.C]
),
EverythingSignal(
"table",
ExampleTable,
ExampleTable(
bool=np.array([False, False, True, True], np.bool_),
int=np.array([1, 8, -9, 32], np.int32),
float=np.array([1.8, 8.2, -6, 32.9887], np.float64),
str=["Hello", "World", "Foo", "Bar"],
enum=[ExampleEnum.A, ExampleEnum.B, ExampleEnum.A, ExampleEnum.C],
),
),
EverythingSignal("ndarray", np.ndarray, np.array(([1, 2, 3], [4, 5, 6]))),
]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this saves typing, it's actually pretty useful to see how you would make the Tango Device and it's associated ophyd device (and the same for EPICS and sim). Rather than try to be clever here I think I'd prefer to just see the test data written out longhand, with this file not being imported from Tango...

Comment on lines 112 to 66
_array_vals = {
"int8a": np.array([-128, 127, 0, 1, 2, 3, 4], dtype=np.int8),
"uint8a": np.array([0, 255, 0, 1, 2, 3, 4], dtype=np.uint8),
"int16a": np.array([-32768, 32767, 0, 1, 2, 3, 4], dtype=np.int16),
"uint16a": np.array([0, 65535, 0, 1, 2, 3, 4], dtype=np.uint16),
"int32a": np.array([-2147483648, 2147483647, 0, 1, 2, 3, 4], dtype=np.int32),
"uint32a": np.array([0, 4294967295, 0, 1, 2, 3, 4], dtype=np.uint32),
"int64a": np.array(
[-9223372036854775808, 9223372036854775807, 0, 1, 2, 3, 4],
dtype=np.int64,
),
"uint64a": np.array([0, 18446744073709551615, 0, 1, 2, 3, 4], dtype=np.uint64),
"float32a": np.array(
[
-3.4028235e38,
3.4028235e38,
1.1754944e-38,
1.4012985e-45,
0.0000000e00,
1.2340000e00,
2.3400000e05,
3.4499999e-06,
],
dtype=np.float32,
),
"float64a": np.array(
[
-1.79769313e308,
1.79769313e308,
2.22507386e-308,
4.94065646e-324,
0.00000000e000,
1.23400000e000,
2.34000000e005,
3.45000000e-006,
],
dtype=np.float64,
),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it would be fine to put these in a fixture and share these

@jsouter
Copy link
Contributor Author

jsouter commented Jan 29, 2025

Still very WIP, sketching out how to handle tango enums, also probably some debug comments left in.
test_tango_signals.py is a little broken, will probably merge with test_tango_one_of_everything.py when I figure out how everything should work.

test str image in tango

add tests for comparing bool and enum arrays with assert_* methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants