-
Notifications
You must be signed in to change notification settings - Fork 14
Developer Testing
The recommended way to test changes is using the development server:
# Start the development server
./scripts/develop
# In another terminal, make changes to the code
# Then restart Home Assistant from the UI or by restarting the scriptTest Configuration:
The config/configuration.yaml file contains mock entities for testing:
- Mock covers (position-capable and open/close-only)
- Mock temperature sensors
- Mock weather entity
- Mock presence sensors
Edit this file to create the test scenarios you need.
This integration uses pytest for automated testing.
For comprehensive test documentation, see UNIT_TESTS.md which includes:
- Detailed test descriptions for all 751 tests
- Fixture documentation with usage examples
- Testing patterns and best practices
- Coverage goals and future expansion plans
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage report
pytest --cov --cov-report=term-missing
# Run specific test file
pytest tests/test_calculation.py
# Run specific test
pytest tests/test_calculation.py::test_gamma_angle_calculation_sun_directly_in_front
# Run only unit tests (fast)
pytest -m unit
# Run with verbose output
pytest -v
# Use the test script
./scripts/test # Run all tests
./scripts/test unit # Run only unit tests
./scripts/test coverage # Run with detailed coverage-
tests/conftest.py- Shared fixtures (hass mock, logger, configs, cover instances) -
tests/test_calculation.py- Position calculation tests (unit) -
tests/test_helpers.py- Helper function tests (unit) -
tests/test_inverse_state.py- Critical inverse state tests (unit) -
tests/test_managers/- Manager class unit tests -
tests/test_pipeline/- Pipeline handler unit tests -
tests/test_state/- State provider tests -
tests/test_diagnostics/- Diagnostics builder tests -
tests/test_engine/- Engine module tests (SunGeometry, VenetianCoverCalculation)
Total: 751 tests (all passing)
Current test coverage status:
| Module | Coverage | Status |
|---|---|---|
| calculation.py | 87% | β Comprehensive |
| helpers.py | 100% | β Complete |
| const.py | 100% | β Complete |
| inverse_state | 100% | β Complete |
| pipeline/ | ~100% | β Complete |
| managers/ | ~96% | β Mostly complete |
| state/ | ~95% | β Mostly complete |
| diagnostics/ | ~90% | β Mostly complete |
| engine/ | ~90% | β Mostly complete |
| coordinator.py | ~34% | π Future work |
| Overall | 61% | π In progress |
See UNIT_TESTS.md for detailed coverage information and future expansion plans.
Tests use pytest fixtures from conftest.py. Example:
import pytest
from custom_components.adaptive_cover_pro.helpers import get_safe_state
@pytest.mark.unit
def test_get_safe_state_returns_state(hass):
"""Test get_safe_state returns state when available."""
state_obj = MagicMock()
state_obj.state = "25.5"
hass.states.get.return_value = state_obj
result = get_safe_state(hass, "sensor.temperature")
assert result == "25.5"Best Practices:
- Use descriptive test names that explain what is being tested
- Add docstrings explaining the test purpose
- Mark tests with
@pytest.mark.unitfor fast tests - Use fixtures from
conftest.pyfor common setup - Keep tests simple and focused on one behavior
Tests run automatically on:
- Pull requests
- Pushes to main branch
- Pushes to feature branches
- Manual workflow dispatch
See .github/workflows/tests.yml for CI configuration.
CI Matrix:
- Python 3.11
- Python 3.12
CI Steps:
- Checkout code
- Set up Python environment
- Install dependencies
- Run tests with coverage
- Upload coverage to Codecov (Python 3.12 only)
Priority Order:
- Pure functions - Test utilities and helpers first (easiest)
- Critical behaviors - Test inverse_state and documented behaviors
- Core algorithms - Test calculation logic
- Integration - Test coordinator and flows (future)
What We Test:
- Pure utility functions (no I/O)
- Position calculation algorithms
- Sun angle and azimuth calculations
- Blind spot detection logic
- Position clamping and validation
- Critical documented behaviors (inverse state order of operations)
What We Don't Test (Yet):
- Async coordinator logic (complex, lower priority initially)
- Config flow UI (requires Home Assistant test framework)
- Entity registration (lower ROI, can be added later)
The release script supports dry-run mode for safe testing:
# Test beta release (no changes made)
./scripts/release beta --dry-run
# Test with explicit version
./scripts/release 2.5.1-beta.1 --dry-run
# Test production release (requires main branch)
git checkout main
./scripts/release patch --dry-runFor algorithm testing and visualization:
# Install Jupyter dependencies
pip install jupyter matplotlib pvlib
# Start Jupyter
jupyter notebook
# Open notebooks/simulate_cover.ipynbUse cases:
- Test position calculation algorithms
- Visualize cover positions over time
- Simulate different sun positions and configurations
- Generate plots for documentation
The custom_components/adaptive_cover_pro/simulation/ directory contains tools for simulating cover behavior over time.
π Home Β· β¨ Features Β· π° What's New
π Getting Started
- Installation
- Migrating from Custom Repository
- Migrating from Adaptive Cover
- First-Time Setup
- Cover Types
π§ Core Concepts
π Cover Types
βοΈ Configuration
- Sun Tracking
- Position
- Glare Zones
- Automation
- Custom Position
- Force Override
- Weather Safety
- Climate
- Blindspot
- Summary Screen
- Debug & Diagnostics
π Entities & Services
- Entities
- Proxy Cover Entity
- Position Verification
- My Position Support (Somfy RTS)
- Runtime Configuration Services
π οΈ Operations
π§ Advanced Use Cases
- Dynamic Temperature Thresholds
- Dynamic Tracking Window
- Bedroom Sleep Mode
- Handling Variable Cloud Cover
- Venetian Tilt-Only on Overcast Days
π¨ Dashboard
π§ͺ Testing & Simulation
π Reference
π©βπ» For Developers