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 6 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

k: dict(
v,
value=approx_value(expected[k]["value"]),
timestamp=approx_value(expected[k]["timestamp"]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be nice to support not having to put timestamps in the dictionary

Suggested change
timestamp=approx_value(expected[k]["timestamp"]),
timestamp=pytest.approx(expected[k].get("timestamp", ANY)),

Maybe alarm severity too?

self.signal.name: {
"value": expected_value,
"timestamp": pytest.approx(time.time(), rel=0.1),
"timestamp": self._timestamp_provider(), # type: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this just so we can use time.monotonic? If so, I think it's fine to change that just in that function without introducing a timestamp provider...

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 +149
_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

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