From 7785e09c59eef70185d5a01069b954a6cc7cd519 Mon Sep 17 00:00:00 2001 From: Christin Date: Fri, 20 Nov 2026 03:42:47 +0100 Subject: [PATCH] test(prediction): run the default update test in a fixed zone test_update_method_with_defaults expected the prediction window to end 48 real hours after the start, given in the local zone of the test run. The window ends at the same wall-clock time, as documented in end_datetime, so the test failed where DST ends within the window, e.g. in America/Los_Angeles on 2024-11-03. The start is now given in a fixed zone, and a second case crosses the end of DST on purpose and checks the 49 hours. Fixes #1570 Co-Authored-By: Claude Opus 5.5 Assisted-by: Claude Code (claude-opus-5-5) --- tests/test_predictionabc.py | 42 ++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/tests/test_predictionabc.py b/tests/test_predictionabc.py index 64815519..8df66a87 100644 --- a/tests/test_predictionabc.py +++ b/tests/test_predictionabc.py @@ -184,10 +184,31 @@ class TestPredictionProvider: "Keep datetime is not calculated correctly." ) + @pytest.mark.parametrize( + "timezone, end, total_hours", + [ + # No DST change within the 48 hours. + ("Europe/Berlin", "2024-11-03 13:00:00", 48), + # DST ends on 2024-11-03: the window ends at the same wall-clock time, + # 49 hours after the start (#1570). + ("America/Los_Angeles", "2024-11-03 05:00:00", 49), + ], + ) async def test_update_method_with_defaults( - self, provider, sample_start_datetime, config_eos, monkeypatch - ): - """Test the `update` method with default parameters.""" + self, + provider, + sample_start_datetime, + config_eos, + monkeypatch, + timezone: str, + end: str, + total_hours: int, + ) -> None: + """Test the `update` method with default parameters. + + The start is given in a fixed zone, so the result does not depend on the local zone + of the test run. + """ # EOS config supersedes ems_eos = get_ems() # The following values are currently not set in EOS config, we can override @@ -195,16 +216,17 @@ class TestPredictionProvider: assert os.getenv("EOS_PREDICTION__HISTORIC_HOURS") == "2" provider.config.reset_settings() - ems_eos.set_start_datetime(sample_start_datetime) + start = to_datetime(sample_start_datetime, in_timezone=timezone) + ems_eos.set_start_datetime(start) await provider.update_data() - assert provider.config.prediction.hours == config_eos.prediction.hours + # Default prediction horizon: 48 hours + assert provider.config.prediction.hours == config_eos.prediction.hours == 48 assert provider.config.prediction.historic_hours == 2 - assert provider.ems_start_datetime == sample_start_datetime - assert provider.end_datetime == sample_start_datetime + to_duration( - f"{provider.config.prediction.hours} hours" - ) - assert provider.keep_datetime == sample_start_datetime - to_duration("2 hours") + assert provider.ems_start_datetime == start + assert provider.end_datetime == to_datetime(end, in_timezone=timezone) + assert provider.total_hours == total_hours + assert provider.keep_datetime == start - to_duration("2 hours") async def test_update_method_force_enable(self, provider, monkeypatch): """Test that `update` executes when `force_enable` is True, even if `enabled` is False."""