Skip to content

Commit 5f36174

Browse files
committed
Various small fixes to utils tests
Signed-off-by: Samuel Monson <[email protected]>
1 parent 5676895 commit 5f36174

File tree

3 files changed

+7
-28
lines changed

3 files changed

+7
-28
lines changed

tests/unit/utils/test_auto_importer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from __future__ import annotations
66

7+
import sys
78
from unittest import mock
89

910
import pytest
@@ -191,9 +192,9 @@ class TestClass(AutoImporterMixin):
191192
mock_import.assert_any_call("test.package.subpackage")
192193

193194
@pytest.mark.sanity
194-
@mock.patch("sys.modules", {"test.package.existing": mock.MagicMock()})
195195
@mock.patch("importlib.import_module")
196196
@mock.patch("pkgutil.walk_packages")
197+
@mock.patch.dict(sys.modules, {"test.package.existing": mock.MagicMock()})
197198
def test_skip_already_imported_modules(self, mock_walk, mock_import):
198199
"""Test that modules already in sys.modules are tracked but not re-imported."""
199200

tests/unit/utils/test_registry.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ def validate_value(value: int) -> bool:
579579
if hasattr(inspect, "get_annotations"):
580580
# Python 3.10+
581581
try:
582-
annotations = inspect.get_annotations(registered_class.__init__)
582+
annotations = inspect.get_annotations(
583+
registered_class.__init__, eval_str=True
584+
)
583585
assert "value" in annotations
584586
assert annotations["value"] is int
585587
return_ann = annotations.get("return")

tests/unit/utils/test_text.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TestFormatValueDisplay:
4242
"expected",
4343
),
4444
[
45-
(42.0, "test", "", None, None, None, "42 [info]test[/info]"),
45+
(42.0, "test", "", None, None, 0, "42 [info]test[/info]"),
4646
(42.5, "test", "ms", None, None, 1, "42.5ms [info]test[/info]"),
4747
(42.123, "test", "", None, 5, 2, " 42.12 [info]test[/info]"),
4848
(
@@ -78,34 +78,10 @@ def test_invocation(
7878
assert label in result
7979
assert units in result
8080
value_check = (
81-
str(int(value))
82-
if decimal_places == 0
83-
else (
84-
f"{value:.{decimal_places}f}"
85-
if decimal_places is not None
86-
else str(value)
87-
)
81+
str(int(value)) if decimal_places == 0 else f"{value:.{decimal_places}f}"
8882
)
8983
assert value_check in result or str(value) in result
9084

91-
@pytest.mark.sanity
92-
@pytest.mark.parametrize(
93-
("value", "label"),
94-
[
95-
(None, "test"),
96-
(42.0, None),
97-
("not_number", "test"),
98-
],
99-
)
100-
def test_invocation_with_none_values(self, value, label):
101-
"""Test format_value_display with None/invalid inputs still works."""
102-
result = format_value_display(value, label)
103-
assert isinstance(result, str)
104-
if label is not None:
105-
assert str(label) in result
106-
if value is not None:
107-
assert str(value) in result
108-
10985

11086
class TestSplitTextListByLength:
11187
"""Test suite for split_text_list_by_length."""

0 commit comments

Comments
 (0)