31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from datetime import UTC, datetime, timedelta
|
|||
|
|
|
||
|
|
import pytest
|
||
|
|
from pydantic import ValidationError
|
||
|
|
|
||
|
|
from pigway_frame_flow.errors import FlowError
|
||
|
|
from pigway_frame_flow.models import Schedule
|
||
|
|
from pigway_frame_flow.scheduler.engine import next_run
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("minutes", [1, 7, 60, 120, 420, 10080])
|
||
|
|
def test_interval_crosses_calendar_boundaries(minutes):
|
||
|
|
start = datetime(2026, 10, 16, 23, 58, tzinfo=UTC)
|
||
|
|
schedule = Schedule(type="interval", interval_minutes=minutes)
|
||
|
|
first = datetime.fromisoformat(next_run(schedule, start))
|
||
|
|
assert first == start + timedelta(minutes=minutes)
|
||
|
|
assert datetime.fromisoformat(next_run(schedule, first)) == first + timedelta(
|
||
|
|
minutes=minutes
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.mark.parametrize("minutes", [0, -1, 10081])
|
||
|
|
def test_invalid_interval(minutes):
|
||
|
|
with pytest.raises(ValidationError):
|
||
|
|
Schedule(type="interval", interval_minutes=minutes)
|
||
|
|
|
||
|
|
|
||
|
|
def test_missing_interval_fails():
|
||
|
|
with pytest.raises(FlowError):
|
||
|
|
next_run(Schedule(type="interval"))
|