From 6ed6861fc0ec785b335a409344cce9c65eb99f1f Mon Sep 17 00:00:00 2001 From: Cryptopoly <31970407+cryptopoly@users.noreply.github.com> Date: Fri, 1 May 2026 18:17:16 +0100 Subject: [PATCH] Allow None for vram_total_gb in GPUMonitor snapshot contract test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #22 (Fix Windows CUDA detection) replaced the system-RAM-as-VRAM fallback in _snapshot_nvidia with a no-GPU response that returns {'vram_total_gb': None, 'vram_used_gb': None}. The pre-existing test_snapshot_vram_values_are_numeric still required (int, float), which breaks on the Linux CI runner where neither torch.cuda nor nvidia-smi is available. This fix originally landed in branch fix/test-host-platform-mock (commit 3b147a9) but was pushed after PR #24 had already merged. It was added to PR #25 too late again — same pattern. Land it directly this time before any other CI run picks up the broken contract. Loosen the type check to (int, float, type(None)) so the no-GPU path is accepted, and rename the test to ..._numeric_or_none to make the intent loud at the call site. --- tests/test_gpu.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_gpu.py b/tests/test_gpu.py index d030c61..34ef405 100644 --- a/tests/test_gpu.py +++ b/tests/test_gpu.py @@ -29,11 +29,15 @@ def test_snapshot_gpu_name_is_string(self): snapshot = monitor.snapshot() self.assertIsInstance(snapshot["gpu_name"], str) - def test_snapshot_vram_values_are_numeric(self): + def test_snapshot_vram_values_are_numeric_or_none(self): + # ``None`` is a valid response when neither torch.cuda nor + # nvidia-smi can answer — we deliberately don't fall back to + # system RAM via psutil any more (would mislead the safety + # estimator). Numeric otherwise. monitor = GPUMonitor() snapshot = monitor.snapshot() - self.assertIsInstance(snapshot["vram_total_gb"], (int, float)) - self.assertIsInstance(snapshot["vram_used_gb"], (int, float)) + self.assertIsInstance(snapshot["vram_total_gb"], (int, float, type(None))) + self.assertIsInstance(snapshot["vram_used_gb"], (int, float, type(None))) class GPUMonitorNvidiaTests(unittest.TestCase):