provozni zaloha

This commit is contained in:
lachtan
2026-06-24 08:11:12 +02:00
parent 9295dba19f
commit 1db3ec4756
97 changed files with 7698 additions and 817 deletions

View File

@@ -94,3 +94,69 @@ def test_config_validated_before_date_filter():
# Out-of-range date still surfaces a structural error rather than returning [].
with pytest.raises(ValueError):
compute_fire_times(date(2000, 1, 1), "x", cfg(times_per_day=50, until="1999-01-01"))
# --- Weekly period -----------------------------------------------------------
# Week of Mon 2026-03-23 .. Sun 2026-03-29.
WEEK = [date(2026, 3, d) for d in range(23, 30)]
def weekly_cfg(**overrides) -> dict:
base = {"times_per_day": 2, "window": WINDOW, "period": "week"}
base.update(overrides)
return base
def _week_fires(text: str, cfg_dict: dict) -> list[datetime]:
return [fire for day in WEEK for fire in compute_fire_times(day, text, cfg_dict)]
def test_weekly_count_across_week():
assert len(_week_fires("x", weekly_cfg(times_per_day=2))) == 2
def test_weekly_distinct_days():
fires = _week_fires("x", weekly_cfg(times_per_day=3))
assert len({f.date() for f in fires}) == 3
def test_weekly_deterministic_across_days():
# Every day of the week must agree on the same plan, so summing per-day calls
# over the week yields a stable set regardless of call order.
assert _week_fires("walk", weekly_cfg()) == _week_fires("walk", weekly_cfg())
def test_weekly_within_window():
for fire in _week_fires("x", weekly_cfg(times_per_day=4)):
assert WINDOW_START.time() <= fire.time() <= WINDOW_END.time()
def test_weekly_days_filter_limits_eligible():
fires = _week_fires("x", weekly_cfg(times_per_day=2, days="1-5"))
assert all(f.weekday() < 5 for f in fires)
def test_weekly_count_clamped_to_eligible_days():
# Capacity (7 days) admits 3, but until clips this week to Mon+Tue -> 2 fires, no error.
bounded = weekly_cfg(times_per_day=3, until="2026-03-24")
fires = _week_fires("x", bounded)
assert len(fires) == 2
assert {f.date() for f in fires} == {date(2026, 3, 23), date(2026, 3, 24)}
def test_weekly_from_until_clips_to_partial_week():
bounded = weekly_cfg(times_per_day=2, **{"from": "2026-03-25", "until": "2026-03-27"})
fires = _week_fires("x", bounded)
assert all(date(2026, 3, 25) <= f.date() <= date(2026, 3, 27) for f in fires)
assert len(fires) == 2
def test_weekly_count_exceeds_capacity_raises():
with pytest.raises(ValueError):
compute_fire_times(WEEK[0], "x", weekly_cfg(times_per_day=8))
def test_weekly_count_exceeds_filtered_capacity_raises():
with pytest.raises(ValueError):
compute_fire_times(WEEK[0], "x", weekly_cfg(times_per_day=3, days="1,2"))