mirror of
https://github.com/Dasemu/skipredictor.git
synced 2026-11-26 15:26:15 +00:00
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
"""Unit tests for daily prediction horizon helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date
|
|
|
|
import pandas as pd
|
|
|
|
from scripts.collect_daily_data import (
|
|
_available_prediction_dates,
|
|
_select_forecast_row_for_date,
|
|
)
|
|
|
|
|
|
def _forecast_df(start: str = "2026-03-13", periods: int = 7) -> pd.DataFrame:
|
|
"""Build a minimal forecast frame with consecutive daily dates."""
|
|
dates = pd.date_range(start=start, periods=periods, freq="D")
|
|
return pd.DataFrame(
|
|
{
|
|
"date": dates,
|
|
"station_id": ["pajares"] * periods,
|
|
"temperature_2m_max": [1.0] * periods,
|
|
}
|
|
)
|
|
|
|
|
|
def test_available_prediction_dates_match_real_forecast_horizon():
|
|
"""Helpers must not invent an eighth day when the provider returns seven."""
|
|
forecast_dates = _available_prediction_dates(
|
|
{"pajares": _forecast_df()},
|
|
base_date=date(2026, 3, 13),
|
|
include_today=True,
|
|
)
|
|
|
|
assert forecast_dates == [
|
|
date(2026, 3, 13),
|
|
date(2026, 3, 14),
|
|
date(2026, 3, 15),
|
|
date(2026, 3, 16),
|
|
date(2026, 3, 17),
|
|
date(2026, 3, 18),
|
|
date(2026, 3, 19),
|
|
]
|
|
|
|
|
|
def test_available_prediction_dates_can_skip_today():
|
|
"""Afternoon scheduler runs must start from tomorrow when requested."""
|
|
forecast_dates = _available_prediction_dates(
|
|
{"pajares": _forecast_df()},
|
|
base_date=date(2026, 3, 13),
|
|
include_today=False,
|
|
)
|
|
|
|
assert forecast_dates == [
|
|
date(2026, 3, 14),
|
|
date(2026, 3, 15),
|
|
date(2026, 3, 16),
|
|
date(2026, 3, 17),
|
|
date(2026, 3, 18),
|
|
date(2026, 3, 19),
|
|
]
|
|
|
|
|
|
def test_select_forecast_row_returns_none_when_target_date_is_missing():
|
|
"""Out-of-range requests must fail cleanly instead of reusing the last row."""
|
|
row = _select_forecast_row_for_date(
|
|
_forecast_df(),
|
|
station_id="pajares",
|
|
target_date=date(2026, 3, 20),
|
|
)
|
|
|
|
assert row is None
|