chore: improve openmeteo test (#974)

Make openmeteo test robust against timing issues.

Also update:
- types-docutils==0.22.3.20260322
- pytest-cov==7.1.0
- ruff-pre-commit v0.15.7
- uvlock

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
This commit is contained in:
Bobby Noelte
2026-03-26 12:32:30 +01:00
committed by GitHub
parent c6ccd0530b
commit 2da724ecf4
8 changed files with 72 additions and 65 deletions

View File

@@ -236,15 +236,28 @@ def test_openmeteo_request_mode_selection(
mock_response.content = str(sample_openmeteo_1_json)
mock_get.return_value = mock_response
# Set deterministic start time
now = to_datetime(in_timezone="Europe/Berlin")
start = now + pd.Timedelta(days=start_offset_days)
# Fixed current time to avoid timing issues
fixed_now = to_datetime("2026-03-26 12:00:00+01:00", in_timezone="Europe/Berlin")
ems_eos = get_ems()
ems_eos.set_start_datetime(start)
# Patch to_datetime to return fixed_now when called without a datetime argument
with patch("akkudoktoreos.prediction.weatheropenmeteo.to_datetime") as mock_to_datetime:
def to_datetime_side_effect(dt=None, in_timezone=None):
if dt is None:
return fixed_now
# Otherwise fall back to the real function
from akkudoktoreos.utils.datetimeutil import to_datetime as real_to_datetime
return real_to_datetime(dt, in_timezone=in_timezone)
# Execute
provider._request_forecast()
mock_to_datetime.side_effect = to_datetime_side_effect
# Set deterministic start time based on fixed_now
start = fixed_now + pd.Timedelta(days=start_offset_days)
ems_eos = get_ems()
ems_eos.set_start_datetime(start)
# Execute
provider._request_forecast()
# Inspect request params
params = mock_get.call_args[1]["params"]