test: Add unit test coverage for hardware_detect utility

Abierto Apto para principiantes
#1,786 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
79/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
testing

Línea de trabajo

Lee backend/app/utils/hardware_detect.py y sigue los patrones de prueba existentes en backend/tests. Añade backend/tests/test_hardware_detect.py con llamadas al sistema simuladas para cubrir las cinco funciones públicas mencionadas y los casos límite enumerados. Ejecuta el nuevo archivo de pruebas; el trabajo estará terminado cuando las pruebas pasen en las rutas de detección especificadas sin requerir hardware físico.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

enhancement

What's missing

backend/app/utils/hardware_detect.py has zero test coverage right now. This module is responsible for figuring out what hardware a user's machine has (GPU, Apple Silicon, RAM) and recommending the right AI model tier (nano / small / medium). It's a pretty critical piece — if something breaks here, users silently end up with the wrong model for their hardware.

What I'd like to add

A test file backend/tests/test_hardware_detect.py covering all 5 public functions:

  • detect_physical_gpu() — nvidia-smi not found, single/multiple GPU parsing, error handling (OSError, timeout), blank-line stripping
  • detect_apple_silicon() — non-Mac returns None, non-arm64 returns None, sysctl happy path, sysctl failure fallback chain (processor → generic string)
  • detect_apple_silicon_tier() — base M1/M2 → small, Pro/Max/Ultra/M3+ → medium, non-Apple → None
  • detect_hardware_tier() — Apple Silicon path, GPU-present path, RAM-based tiers, boundary values at exactly 4 GB and 8 GB
  • get_hardware_info() — returned dict has the right keys and values, gpu_detected flag correctness

All system calls (shutil.which, subprocess.run, platform.*, psutil.virtual_memory, ort.get_available_providers) will be mocked so the tests run on any machine without needing actual hardware.

Why it matters

This module quietly drives model selection for the whole app. Having tests here means we catch regressions early — especially around edge cases like timeouts, missing tools, or future chip names.


I'd like to work on this — I've already explored the module and have a good idea of what the test cases should look like. Happy to put up a PR!

Lenguaje dominante
Python
Estrellas
322
Forks
793
Merge medio
6 d 11 h
PR fusionados (30 d)
21

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de AOSSIE-Org/PictoPy

Todos los issues de AOSSIE-Org/PictoPy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.