Add initial device mapping tests #57

Merged
JackFrostbyte merged 2 commits from test/issue-48-device-mapping-tests into develop 2026-05-15 18:01:12 -04:00
Collaborator

Summary

  • Adds tests/conftest.py with make_device and make_zone mock factories built on types.SimpleNamespace. The validator uses getattr to read OpenRGB SDK objects, so these mocks expose the same attribute surface (.name, .type, .zones, .leds_count) without needing the real SDK or any hardware.
  • Adds tests/test_device_mapping.py with 17 tests covering the public API of rgb_aura.device_mapping.
  • Tests run with zero hardware dependencies. Total runtime ~30 ms.

Coverage

load_mapping_config — 7 tests

  • Happy path: valid JSON returns the parsed config.
  • Refusal: file does not exist.
  • Refusal: malformed JSON.
  • Refusal: root is not a JSON object.
  • Refusal: wrong schema_version.
  • Refusal: missing devices key.
  • Refusal: devices is not a JSON object.

validate_device_mapping — 8 tests

  • Happy path: single device + single zone returns a fully populated LogicalZoneMapping.
  • Refusal: expected device not detected.
  • Refusal: duplicate device names (refuses unsafe ambiguous mapping).
  • Refusal: device type mismatch.
  • Refusal: zone index out of range.
  • Refusal: zone name mismatch.
  • Refusal: zone LED count mismatch.
  • Refusal: usable LED indexes out of range.

Edge cases — 2 tests

  • Reserved-style zone with empty usable_led_indexes validates cleanly (reserved zone protection lives at the runtime layer, not in the validator).
  • Multi-zone single-device mapping (two logical mappings to the same physical device on different zone indexes).

Verification

  • python -m pytest tests/ — 18 passed (17 new + the existing test_run_combined_runtime_returns_mapping_error_when_validation_fails regression test from #45).
  • ruff format src tests scripts — 31 files left unchanged.
  • ruff check src tests scripts — all checks passed.
  • python -m rgb_aura.main --dry-run --dry-run-events 3 — clean run, all 14 animations registered, scheduler preview produces events normally.

Hardware verification

Not required. Tests run against mock OpenRGB device objects; no real SDK, no hardware, no LED write path touched.

Linked issue

Closes #48.

Branch workflow

  • Base branch: develop
  • Work branch: test/issue-48-device-mapping-tests
  • Pull request target: develop
  • Not merged directly into main.

Notes for future work

  • tests/conftest.py mock factories are reusable for upcoming test work, especially #49 (animation frame integrity tests). No duplication needed.
  • These tests cover the current validator behavior. If the validator's safety contract is intentionally changed (e.g., relaxed device-name matching for portable Avenue 2 hardware), the relevant tests must be updated in the same PR that changes the validator — they should not be removed silently.
## Summary - Adds `tests/conftest.py` with `make_device` and `make_zone` mock factories built on `types.SimpleNamespace`. The validator uses `getattr` to read OpenRGB SDK objects, so these mocks expose the same attribute surface (`.name`, `.type`, `.zones`, `.leds_count`) without needing the real SDK or any hardware. - Adds `tests/test_device_mapping.py` with 17 tests covering the public API of `rgb_aura.device_mapping`. - Tests run with zero hardware dependencies. Total runtime ~30 ms. ## Coverage ### `load_mapping_config` — 7 tests - Happy path: valid JSON returns the parsed config. - Refusal: file does not exist. - Refusal: malformed JSON. - Refusal: root is not a JSON object. - Refusal: wrong `schema_version`. - Refusal: missing `devices` key. - Refusal: `devices` is not a JSON object. ### `validate_device_mapping` — 8 tests - Happy path: single device + single zone returns a fully populated `LogicalZoneMapping`. - Refusal: expected device not detected. - Refusal: duplicate device names (refuses unsafe ambiguous mapping). - Refusal: device type mismatch. - Refusal: zone index out of range. - Refusal: zone name mismatch. - Refusal: zone LED count mismatch. - Refusal: usable LED indexes out of range. ### Edge cases — 2 tests - Reserved-style zone with empty `usable_led_indexes` validates cleanly (reserved zone protection lives at the runtime layer, not in the validator). - Multi-zone single-device mapping (two logical mappings to the same physical device on different zone indexes). ## Verification - [x] `python -m pytest tests/` — 18 passed (17 new + the existing `test_run_combined_runtime_returns_mapping_error_when_validation_fails` regression test from #45). - [x] `ruff format src tests scripts` — 31 files left unchanged. - [x] `ruff check src tests scripts` — all checks passed. - [x] `python -m rgb_aura.main --dry-run --dry-run-events 3` — clean run, all 14 animations registered, scheduler preview produces events normally. ## Hardware verification Not required. Tests run against mock OpenRGB device objects; no real SDK, no hardware, no LED write path touched. ## Linked issue Closes #48. ## Branch workflow - Base branch: `develop` - Work branch: `test/issue-48-device-mapping-tests` - Pull request target: `develop` - Not merged directly into `main`. ## Notes for future work - `tests/conftest.py` mock factories are reusable for upcoming test work, especially #49 (animation frame integrity tests). No duplication needed. - These tests cover the *current* validator behavior. If the validator's safety contract is intentionally changed (e.g., relaxed device-name matching for portable Avenue 2 hardware), the relevant tests must be updated in the same PR that changes the validator — they should not be removed silently.
JackFrostbyte deleted branch test/issue-48-device-mapping-tests 2026-05-15 18:01:12 -04:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
JackFrostbyte/rgb-aura!57
No description provided.