mirror of
https://github.com/jpawlowski/hass.tibber_prices.git
synced 2026-03-29 21:03:40 +00:00
test(period): document period calculation testing strategy
Added documentation file explaining why period calculation functions are tested via integration tests rather than unit tests. Rationale: - Period building requires full coordinator context (TimeService, price_context) - Complex enriched price data with multiple calculated fields - Helper functions (split_intervals_by_day, calculate_reference_prices) are simple transformations that can't fail independently - Integration tests provide better coverage than mocked unit tests Testing strategy: - test_midnight_periods.py: Period calculation across day boundaries - test_midnight_turnover.py: Cache invalidation and recalculation - docs/development/period-calculation-theory.md: Algorithm documentation Impact: Clarifies testing approach for future contributors. Prevents wasted effort on low-value unit tests for complex integrated functions.
This commit is contained in:
parent
a85c37e5ca
commit
f128d00c99
1 changed files with 25 additions and 0 deletions
25
tests/test_period_calculation.py
Normal file
25
tests/test_period_calculation.py
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
"""
|
||||||
|
Tests for Period Calculation - Integration tests only.
|
||||||
|
|
||||||
|
NOTE: Period building functions (build_periods, split_intervals_by_day, etc.) are too
|
||||||
|
complex for effective unit testing. They require:
|
||||||
|
|
||||||
|
1. TibberPricesTimeService instance with full coordinator context
|
||||||
|
2. Complex price_context dict with ref_prices, avg_prices, flex, min_distance
|
||||||
|
3. Enriched price data with rating_level, _original_price, trailing_avg_24h, etc.
|
||||||
|
|
||||||
|
These functions are comprehensively tested via integration tests:
|
||||||
|
- tests/test_midnight_periods.py: Period calculation across day boundaries
|
||||||
|
- tests/test_midnight_turnover.py: Midnight cache invalidation and period recalculation
|
||||||
|
|
||||||
|
Unit testing individual helper functions (split_intervals_by_day, calculate_reference_prices)
|
||||||
|
provides minimal value since they're simple data transformations that can't fail independently
|
||||||
|
from the overall period building logic.
|
||||||
|
|
||||||
|
If you need to debug period calculation issues, run the integration tests with -v flag:
|
||||||
|
./scripts/test tests/test_midnight_periods.py -v
|
||||||
|
./scripts/test tests/test_midnight_turnover.py -v
|
||||||
|
|
||||||
|
For period calculation theory and algorithm documentation, see:
|
||||||
|
docs/development/period-calculation-theory.md
|
||||||
|
"""
|
||||||
Loading…
Reference in a new issue