e3c8979e8d
- cmd/fn/doctor.go - cmd/fn/main.go - cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt - cpp/apps/primitives_gallery/playground/tables/data_table.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.h - cpp/apps/primitives_gallery/playground/tables/self_test.cpp - cpp/apps/primitives_gallery/playground/tables/tql.cpp - cpp/apps/primitives_gallery/playground/tables/viz.cpp - cpp/apps/primitives_gallery/playground/tables/viz.h - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Tests para gpu_info."""
|
|
|
|
import sys
|
|
import unittest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
sys.path.insert(0, "python/functions")
|
|
|
|
from ml.gpu_info import gpu_info
|
|
|
|
|
|
class TestGpuInfo(unittest.TestCase):
|
|
|
|
def test_sin_nvidia_smi_devuelve_lista_vacia(self):
|
|
"""sin nvidia-smi devuelve lista vacia"""
|
|
with patch("subprocess.run", side_effect=FileNotFoundError()):
|
|
result = gpu_info()
|
|
self.assertEqual(result, [])
|
|
|
|
def test_formato_CSV_correcto_devuelve_lista_con_un_dict_por_GPU(self):
|
|
"""formato CSV correcto devuelve lista con un dict por GPU"""
|
|
csv_output = " 0, NVIDIA RTX 4090, 24564, 22000, 535.183.01, 8.9\n"
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 0
|
|
mock_result.stdout = csv_output
|
|
with patch("subprocess.run", return_value=mock_result):
|
|
result = gpu_info()
|
|
self.assertEqual(len(result), 1)
|
|
self.assertEqual(result[0]["index"], 0)
|
|
self.assertEqual(result[0]["name"], "NVIDIA RTX 4090")
|
|
self.assertEqual(result[0]["vram_total_mb"], 24564)
|
|
self.assertEqual(result[0]["vram_free_mb"], 22000)
|
|
self.assertEqual(result[0]["driver_version"], "535.183.01")
|
|
self.assertEqual(result[0]["cuda_version"], "8.9")
|
|
|
|
def test_fila_malformada_en_CSV_se_ignora_sin_excepcion(self):
|
|
"""fila malformada en CSV se ignora sin excepcion"""
|
|
csv_output = " 0, RTX 4090, NONNUMERIC, 22000, 535.183.01, 8.9\n"
|
|
mock_result = MagicMock()
|
|
mock_result.returncode = 0
|
|
mock_result.stdout = csv_output
|
|
with patch("subprocess.run", return_value=mock_result):
|
|
result = gpu_info()
|
|
self.assertEqual(result, [])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|