Skip to content

Testing: add unit tests for gpu_detection.py #2243

@mrveiss

Description

@mrveiss

Problem

autobot-backend/utils/gpu_optimization/gpu_detection.py has zero test coverage. Recent refactors (#1990, #2222) introduced lru_cache-based vendor caching and a module-level GPU name stash that especially need test coverage.

Discovered During

Code review of PR #2237 (fix for #2222).

Tests Needed

  • _check_nvidia_gpu() returns GPU name string (not bool) or None
  • _check_nvidia_gpu() takes only first line on multi-GPU output
  • _detect_vendor() caches result and stashes NVIDIA GPU name
  • _detect_vendor() returns correct vendor for AMD and Intel
  • _detect_vendor() returns None when no GPU present
  • _reset_detection_state() clears both lru_cache and _nvidia_gpu_name
  • _detect_nvidia_capabilities() uses stashed name and parses two-field output
  • _detect_nvidia_capabilities() takes first line on multi-GPU output
  • check_gpu_availability() and detect_gpu_capabilities() use cached vendor
  • Cache clear + re-detection produces correct state (no stale data)

All subprocess calls should be mocked (unittest.mock.patch).

Impact

Medium — no production risk, but the caching/stashing logic is easy to break without test coverage.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions