mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-11-25 15:06:20 +01:00
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 <noreply@anthropic.com> Assisted-by: Claude Code (claude-opus-5-5)
This commit is contained in:
committed by
Bobby Noelte
co-authored by
Claude Opus 5.5
parent
bf8939a8b7
commit
7785e09c59
+32
-10
@@ -184,10 +184,31 @@ class TestPredictionProvider:
|
|||||||
"Keep datetime is not calculated correctly."
|
"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(
|
async def test_update_method_with_defaults(
|
||||||
self, provider, sample_start_datetime, config_eos, monkeypatch
|
self,
|
||||||
):
|
provider,
|
||||||
"""Test the `update` method with default parameters."""
|
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
|
# EOS config supersedes
|
||||||
ems_eos = get_ems()
|
ems_eos = get_ems()
|
||||||
# The following values are currently not set in EOS config, we can override
|
# 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"
|
assert os.getenv("EOS_PREDICTION__HISTORIC_HOURS") == "2"
|
||||||
provider.config.reset_settings()
|
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()
|
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.config.prediction.historic_hours == 2
|
||||||
assert provider.ems_start_datetime == sample_start_datetime
|
assert provider.ems_start_datetime == start
|
||||||
assert provider.end_datetime == sample_start_datetime + to_duration(
|
assert provider.end_datetime == to_datetime(end, in_timezone=timezone)
|
||||||
f"{provider.config.prediction.hours} hours"
|
assert provider.total_hours == total_hours
|
||||||
)
|
assert provider.keep_datetime == start - to_duration("2 hours")
|
||||||
assert provider.keep_datetime == sample_start_datetime - to_duration("2 hours")
|
|
||||||
|
|
||||||
async def test_update_method_force_enable(self, provider, monkeypatch):
|
async def test_update_method_force_enable(self, provider, monkeypatch):
|
||||||
"""Test that `update` executes when `force_enable` is True, even if `enabled` is False."""
|
"""Test that `update` executes when `force_enable` is True, even if `enabled` is False."""
|
||||||
|
|||||||
Reference in New Issue
Block a user