mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-29 13:24:18 +02:00
Group 7: tests — 94 passing in 0.57s (53/53 + 9.4 deferred)
Test infrastructure: - Add `pytest-homeassistant-custom-component` (PHACC) as a `test` dependency group. PHACC ships `hass`, `enable_custom_integrations`, `MockConfigEntry`, and friends without needing to clone HA core as a sibling directory. Modernizes the test setup from upstream's `setup-symlinks` pattern. - conftest.py: add `auto_enable_custom_integrations` autouse fixture so HA discovers the integration under `custom_components/` during tests. Keep the upstream template-deprecation no-op. - Import paths: all tests now import from `custom_components.adaptive_lighting` (not `homeassistant.components.adaptive_lighting`) and from `pytest_homeassistant_custom_component.common` (not `tests.common`). New tests (groups 7.2-7.16): - tests/test_color_and_brightness.py (16 tests): TestBrightnessCurve asserts min-before-sunrise, midpoint-at-event, max-during-day, sunset ramp symmetry. TestColorTempCurve verifies the same shape applies to K. TestSunPosition checks the synthetic +1/-1/0 derivation. TestTanhDayCurveDirect exercises the helper directly. - tests/test_config_flow.py (12 tests): six sections in order, each section contains only its specified fields, conditional visibility of send_split_delay, default sun entities, strict-typed entity selectors, NumberSelector slider/box configs, BooleanSelector for every flag, full user→create-entry flow, YAML-managed entry aborts with `yaml_managed` reason, options flow renders the sectioned schema. - tests/test_init.py (6 tests): successful setup on current version, stale version raises ConfigEntryError via async_migrate_entry, unload is clean, tombstone removes orphan sleep entity + logs INFO, tombstone is idempotent, tombstone respects config_entry ownership. Source modernizations driven by the tests: - __init__.py: add `async_migrate_entry` that surfaces the "incompatible — delete and recreate" message and sets the entry to MIGRATION_ERROR. Removed direct `ConfigEntryError` from `async_setup_entry` (HA routes version mismatches through the migration handler now). - switch.py: removed upstream's YAML-managed-entry auto-remove hack. YAML profiles now load normally and the options flow handles the "you must edit configuration.yaml" message (spec R7). Existing tests updated to PHACC paths: test_adaptation_utils.py (38 tests), test_hass_utils.py (22 tests). Both pass without modification beyond the import fix. Deleted: tests/test_switch.py (2,999 LOC of upstream tests, most covering sleep mode / take-over-control / manual-control state machines that no longer exist; CDiT-specific switch tests deferred to a follow-up change). Result: `uv run --group test pytest tests/` → 94 passed in 0.57s. Deferred from this change: - 4.3: manual UI test that toggling a field and saving reloads cleanly (requires a real HA instance, can't be done from CLI). - 9.4: GitHub repo description / topics update (do via `gh repo edit` outside the change scope). openspec status: 4/4 artifacts complete; strict-validate green.
This commit is contained in:
parent
bb3b8b81f4
commit
03d2748cd4
12 changed files with 1906 additions and 3542 deletions
|
|
@ -1,4 +1,9 @@
|
|||
"""Pytest configuration for adaptive-lighting tests."""
|
||||
"""Pytest configuration for Adaptive Lighting tests (CDiT fork).
|
||||
|
||||
Uses `pytest-homeassistant-custom-component` (PHACC). The
|
||||
`enable_custom_integrations` fixture lets HA discover and load this
|
||||
integration from `custom_components/` during tests.
|
||||
"""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
|
|
@ -6,21 +11,24 @@ import pytest
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_template_deprecation_issue():
|
||||
"""Mock the template deprecation issue creation.
|
||||
def auto_enable_custom_integrations(enable_custom_integrations):
|
||||
"""PHACC requires this fixture to be active for HA to find the
|
||||
integration under custom_components/."""
|
||||
yield
|
||||
|
||||
The template component's legacy platform syntax creates deprecation
|
||||
issues that require translations. Since adaptive-lighting tests use
|
||||
template lights as test fixtures (not testing the template integration
|
||||
itself), we mock the issue creation to avoid translation validation errors.
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def mock_template_deprecation_issue():
|
||||
"""Mock the template helpers' legacy deprecation-issue creation.
|
||||
|
||||
Template lights used as fixtures in upstream tests trigger a
|
||||
deprecation-issue call that requires translation entries we don't ship.
|
||||
No-op the call so tests don't fail on translation validation.
|
||||
"""
|
||||
# Patch the create_legacy_template_issue function in the template helpers
|
||||
# to be a no-op when called for the deprecated_legacy_templates issue
|
||||
try:
|
||||
with patch(
|
||||
"homeassistant.components.template.helpers.create_legacy_template_issue",
|
||||
):
|
||||
yield
|
||||
except (ImportError, ModuleNotFoundError, AttributeError):
|
||||
# Older HA versions don't have this function
|
||||
yield
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue