From f128d00c99ae7938433bece193efe3e8aa2b4de3 Mon Sep 17 00:00:00 2001 From: Julian Pawlowski Date: Sat, 22 Nov 2025 04:47:09 +0000 Subject: [PATCH] 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. --- tests/test_period_calculation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/test_period_calculation.py diff --git a/tests/test_period_calculation.py b/tests/test_period_calculation.py new file mode 100644 index 0000000..7093d3b --- /dev/null +++ b/tests/test_period_calculation.py @@ -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 +"""