Skip to content

Commit 7e6c531

Browse files
committed
test(hardware): use pytest.approx for floating point comparisons
Replace direct == comparisons with pytest.approx() for float values (RAM total/available, max_vram_gb) to avoid floating point precision issues flagged by code review.
1 parent ccf7d69 commit 7e6c531

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

tests/test_hardware.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def test_detect_hardware_windows(self, mock_system: MagicMock) -> None:
4747

4848
result = detect_hardware()
4949
assert result["platform"]["system"] == "Windows"
50-
assert result["ram"]["total_gb"] == 16.0
51-
assert result["ram"]["available_gb"] == 8.0
50+
assert result["ram"]["total_gb"] == pytest.approx(16.0)
51+
assert result["ram"]["available_gb"] == pytest.approx(8.0)
5252
assert len(result["gpus"]) == 1
5353
assert result["gpus"][0]["name"] == "NVIDIA GeForce RTX 3080"
54-
assert result["max_vram_gb"] == 10.0
54+
assert result["max_vram_gb"] == pytest.approx(10.0)
5555

5656
@patch("platform.system")
5757
def test_detect_hardware_linux(self, mock_system: MagicMock) -> None:
@@ -69,8 +69,8 @@ def test_detect_hardware_linux(self, mock_system: MagicMock) -> None:
6969

7070
result = detect_hardware()
7171
assert result["platform"]["system"] == "Linux"
72-
assert result["ram"]["total_gb"] == 32.0
73-
assert result["ram"]["available_gb"] == 16.0
72+
assert result["ram"]["total_gb"] == pytest.approx(32.0)
73+
assert result["ram"]["available_gb"] == pytest.approx(16.0)
7474
assert len(result["gpus"]) == 0
7575
assert result["max_vram_gb"] == 0
7676

@@ -98,9 +98,9 @@ def test_detect_hardware_macos(self, mock_system: MagicMock) -> None:
9898

9999
result = detect_hardware()
100100
assert result["platform"]["system"] == "Darwin"
101-
assert result["ram"]["total_gb"] == 8.0
101+
assert result["ram"]["total_gb"] == pytest.approx(8.0)
102102
assert len(result["gpus"]) == 1
103-
assert result["max_vram_gb"] == 8.0
103+
assert result["max_vram_gb"] == pytest.approx(8.0)
104104

105105
def test_evaluate_model_status(self) -> None:
106106
# 1. GPU VRAM meets recommended specs
@@ -175,7 +175,7 @@ def test_cache_expired_redetects(self) -> None:
175175

176176
result = detect_hardware()
177177
assert mock_ram.call_count == 1
178-
assert result["ram"]["total_gb"] == 32.0
178+
assert result["ram"]["total_gb"] == pytest.approx(32.0)
179179

180180
@patch("platform.system")
181181
def test_unknown_platform_returns_zeros(self, mock_system: MagicMock) -> None:

0 commit comments

Comments
 (0)