From 5755d3065534547f5aa732334494b8d2fbc1cfc3 Mon Sep 17 00:00:00 2001 From: Eva Lott Date: Tue, 3 Dec 2024 13:56:13 +0000 Subject: [PATCH] adjusted tests to avoid `pytest.approx` `bool` comparison --- tests/core/test_table.py | 6 +++++- tests/epics/signal/test_signals.py | 33 ++++++++++++++++++++++++++---- tests/tango/test_tango_signals.py | 3 +++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/tests/core/test_table.py b/tests/core/test_table.py index 3f7a7a6403..fe48629dbe 100644 --- a/tests/core/test_table.py +++ b/tests/core/test_table.py @@ -44,7 +44,11 @@ def test_table_wrong_types(kwargs, error_msg): "kwargs", [ {"bool": np.array([1], dtype=np.uint8), "uint": [3], "str": ["a"]}, - {"bool": [False], "uint": np.array([1], dtype=np.float64), "str": ["b"]}, + { + "bool": np.array([False], dtype=np.bool_), + "uint": np.array([1], dtype=np.float64), + "str": ["b"], + }, ], ) def test_table_coerces(kwargs): diff --git a/tests/epics/signal/test_signals.py b/tests/epics/signal/test_signals.py index 12295aac99..7dedc96d8b 100644 --- a/tests/epics/signal/test_signals.py +++ b/tests/epics/signal/test_signals.py @@ -123,11 +123,36 @@ async def assert_updates(self, expected_value, expected_type=None): update_reading = await asyncio.wait_for(self.updates.get(), timeout=5) update_value = update_reading["value"] - assert update_value == expected_value == backend_value + # We can't compare arrays of bool easily so we do it as numpy rows + if issubclass(type(update_value), Table): + assert all( + row1 == row2 + for row1, row2 in zip( + expected_value.numpy_table(), + update_value.numpy_table(), + strict=True, + ) + ) + assert all( + row1 == row2 + for row1, row2 in zip( + expected_value.numpy_table(), + backend_value.numpy_table(), + strict=True, + ) + ) + else: + assert update_value == expected_value == backend_value + if expected_type: assert_types_are_equal(type(update_value), expected_type, update_value) assert_types_are_equal(type(backend_value), expected_type, backend_value) - assert update_reading == expected_reading == backend_reading + + for key in expected_reading: + if key == "value": + continue + assert update_reading[key] == expected_reading[key] + assert backend_reading[key] == expected_reading[key] def close(self): self.backend.set_callback(None) @@ -636,9 +661,9 @@ def approx_table(datatype: type[Table], table: Table): new_table = datatype(**table.model_dump()) for k, v in new_table: if datatype is Table: - setattr(new_table, k, pytest.approx(v)) + setattr(new_table, k, v) else: - object.__setattr__(new_table, k, pytest.approx(v)) + object.__setattr__(new_table, k, v) return new_table diff --git a/tests/tango/test_tango_signals.py b/tests/tango/test_tango_signals.py index 4919549e53..63c6c25ee9 100644 --- a/tests/tango/test_tango_signals.py +++ b/tests/tango/test_tango_signals.py @@ -63,6 +63,9 @@ class TestEnum(IntEnum): COMMANDS_SET = [] for type_name, tango_type_name, py_type, values in BASE_TYPES_SET: + # pytango test utils currently fail to handle bool pytest.approx + if type_name == "boolean": + continue ATTRIBUTES_SET.extend( [ (