Files
voicebox/backend/tests/test_rocm_backends.py
T
Jamie Pine b434db22f6 chore(backend): repair test suite and bring ruff to green
The suite hadn't run green since the routes refactor:
- test_profile_duplicate_names.py imported the pre-refactor module
  layout and broke collection; now imports backend.services.profiles
- tests/conftest.py puts the repo root and backend dir on sys.path so
  files collect standalone instead of depending on run order
- test_cors.py tested a hand-copied mirror of the origin list that had
  drifted from app.py (missing http://tauri.localhost); it now builds
  the app via the real create_app() factory
- test_progress.py simulated a 1KB download, below the tracker's 1MB
  reporting threshold; simulation raised to 5MB
- slow/timeout markers registered in pyproject

Ruff: ~900 violations auto-fixed (typing modernization, import
sorting, unused imports, whitespace). The remaining rules are baselined
in pyproject.toml with per-rule counts to burn down, plus per-file
carve-outs for deliberate env-before-import ordering. ruff check is
now clean; suite is 134 passed, 2 skipped.
2026-07-26 23:16:09 -07:00

64 lines
2.7 KiB
Python

"""
Phase 2.2 Test: Backend ROCm compatibility.
Validates that check_cuda_compatibility() and other backend utilities
behave correctly on ROCm/AMD hardware.
Usage:
python -m pytest backend/tests/test_rocm_backends.py -v
"""
from unittest.mock import patch
class TestCheckCudaCompatibility:
"""Unit tests for check_cuda_compatibility with ROCm awareness."""
def test_no_gpu_returns_compatible(self):
from backend.backends.base import check_cuda_compatibility
with patch("torch.cuda.is_available", return_value=False):
compatible, warning = check_cuda_compatibility()
assert compatible is True
assert warning is None
def test_rocm_skips_compute_check(self):
"""On ROCm, the NVIDIA compute-capability check should be skipped."""
from backend.backends.base import check_cuda_compatibility
with patch("torch.cuda.is_available", return_value=True), patch("torch.version.hip", "6.2.41133"):
compatible, warning = check_cuda_compatibility()
assert compatible is True
assert warning is None
def test_cuda_compatible_arch(self):
from backend.backends.base import check_cuda_compatibility
with patch("torch.cuda.is_available", return_value=True), patch("torch.version.hip", None):
with patch("torch.cuda.get_device_capability", return_value=(8, 6)):
with patch("torch.cuda.get_device_name", return_value="NVIDIA GeForce RTX 3060"):
with patch.object(
__import__("torch").cuda, "_get_arch_list",
return_value=["sm_80", "sm_86", "sm_89"],
create=True,
):
compatible, warning = check_cuda_compatibility()
assert compatible is True
assert warning is None
def test_cuda_incompatible_arch(self):
from backend.backends.base import check_cuda_compatibility
with patch("torch.cuda.is_available", return_value=True), patch("torch.version.hip", None):
with patch("torch.cuda.get_device_capability", return_value=(9, 0)):
with patch("torch.cuda.get_device_name", return_value="NVIDIA GeForce RTX 4090"):
with patch.object(
__import__("torch").cuda, "_get_arch_list",
return_value=["sm_80", "sm_86"],
create=True,
):
compatible, warning = check_cuda_compatibility()
assert compatible is False
assert warning is not None
assert "not supported" in warning