Skip to content

test: add hardware module coverage#25

Merged
pipe1os merged 1 commit into
pipe1os:mainfrom
Kkkakania:test/hardware-coverage-4
Jun 18, 2026
Merged

test: add hardware module coverage#25
pipe1os merged 1 commit into
pipe1os:mainfrom
Kkkakania:test/hardware-coverage-4

Conversation

@Kkkakania

@Kkkakania Kkkakania commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Closes #4.

Summary

  • add tests for GPU name normalization and GPU target resolution
  • mock subprocess.run to cover NVIDIA, ROCm, Apple Silicon, and fallback local GPU detection paths
  • cover auto detection delegation, multi-GPU strings, custom numeric VRAM targets, Apple Silicon shortcuts, and unknown GPU errors

Verification

  • uv run --extra dev pytest tests/test_hardware.py -q --cov=modelinfo.hardware --cov-report=term-missing --cov-fail-under=100 (12 tests, hardware.py 100%)
  • uv run --extra dev pytest -q (32 passed)
  • uv run --extra dev ruff check tests/test_hardware.py
  • git diff --check

Summary by CodeRabbit

  • Tests
    • Added test coverage for GPU hardware detection and configuration. Tests validate GPU identification, memory resolution matching, and automatic detection via multiple system methods across different hardware platforms.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b32d10d-c10f-4fc0-a97f-d72ae5700653

📥 Commits

Reviewing files that changed from the base of the PR and between 126d0fa and 6a057f3.

📒 Files selected for processing (1)
  • tests/test_hardware.py

Walkthrough

Adds tests/test_hardware.py, a new pytest test file for modelinfo.hardware. It introduces a completed() subprocess stub helper and 12 test functions covering normalize_gpu_string, resolve_gpu (known lookup, multi-GPU, numeric VRAM, auto delegation, error rejection), and detect_local_gpu (nvidia-smi parsing, multi-GPU aggregation, rocm-smi fallback, sysctl fallback, and default unknown return).

Changes

Hardware module test suite

Layer / File(s) Summary
Test helper and normalize_gpu_string tests
tests/test_hardware.py
Adds imports and the completed(stdout) stub that fabricates subprocess.CompletedProcess objects; adds normalization assertions for NVIDIA, AMD, and Intel vendor strings.
resolve_gpu tests: known GPU, multi-GPU, VRAM, auto, and error cases
tests/test_hardware.py
Tests resolve_gpu returning canonical name/VRAM/count for a known GPU, parsing 2x ... multi-GPU input, accepting numeric VRAM targets, delegating "auto" to detect_local_gpu via monkeypatch, and raising ValueError for Apple Silicon shortcuts and unknown GPU names.
detect_local_gpu subprocess detection tests
tests/test_hardware.py
Tests detect_local_gpu parsing a single nvidia-smi CSV entry, summing multiple entries into a multi-GPU aggregate, falling back to rocm-smi on FileNotFoundError, falling back to sysctl hw.memsize for Apple unified memory, and returning ("Unknown", 8.0, 1) when all commands fail.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'test: add hardware module coverage' directly describes the main change: adding tests for the hardware module.
Description check ✅ Passed The PR description includes summary, verification steps, and demonstrates testing completion, though it lacks explicit sections matching the template structure.
Linked Issues check ✅ Passed All objectives from issue #4 are fulfilled: tests for normalize_gpu_string, resolve_gpu, and detect_local_gpu with 100% coverage achieved as verified.
Out of Scope Changes check ✅ Passed All changes are limited to tests/test_hardware.py and directly address the requirements of issue #4 with no extraneous modifications.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@pipe1os

pipe1os commented Jun 18, 2026

Copy link
Copy Markdown
Owner

thank you for your contribution, the changes are correct.

@pipe1os pipe1os merged commit 1d03b54 into pipe1os:main Jun 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for hardware.py

2 participants