Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pyrecest/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _normalize_expected_backend_names(
not isinstance(name, str) or not name or name.strip() != name for name in names
):
raise ValueError(message)
return names
return tuple(dict.fromkeys(names))


def assert_backend(expected: str | tuple[str, ...]) -> None:
Expand Down
10 changes: 10 additions & 0 deletions tests/test_backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def test_assert_backend_rejects_unexpected_backend():
pyrecest.assert_backend(unexpected)


def test_assert_backend_deduplicates_expected_names_in_error_message():
active = pyrecest.get_backend_name()
unexpected = "jax" if active != "jax" else "numpy"

with pytest.raises(RuntimeError) as excinfo:
pyrecest.assert_backend((unexpected, unexpected))

assert str(excinfo.value).count(unexpected) == 1


@pytest.mark.parametrize(
"expected", [(), ("",), " ", (" numpy",), ("numpy ",), ("numpy", 1), 1]
)
Expand Down
Loading