Skip to content

Commit

Permalink
adjusted tests to avoid pytest.approx bool comparison (#689)
Browse files Browse the repository at this point in the history
pytango fails in it's internal test utils, so we will have to wait for
that to be fixed before we add `"boolean`" back to the tango signal
tests.
  • Loading branch information
evalott100 authored Dec 3, 2024
1 parent fadd9be commit 666d222
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tests/core/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
33 changes: 29 additions & 4 deletions tests/epics/signal/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions tests/tango/test_tango_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
(
Expand Down

0 comments on commit 666d222

Please sign in to comment.