"""How long a monitor has been in its state (#5120). The Status page that first showed it was folded into Monitors (#5270).""" from datetime import datetime, timedelta, timezone from types import SimpleNamespace import pytest from steward.core.status import streak_start T0 = datetime(2026, 10, 6, 18, 0, tzinfo=timezone.utc) def _checks(*ups): return [SimpleNamespace(is_up=up, checked_at=T0 + timedelta(minutes=i)) for i, up in enumerate(ups)] @pytest.mark.parametrize("ups, since, at_least", [ ((), None, False), ((True,), 0, True), ((False, False, False), 0, True), # down for every check we have ((True, True, False, False), 2, False), # went down at the third check ((False, True, True, False), 3, False), ]) def test_streak_start(ups, since, at_least): checks = _checks(*ups) assert streak_start(checks) == ((checks[since].checked_at if since is not None else None), at_least)