repo-manager/tests/test_time.py

18 lines
579 B
Python
Raw Normal View History

from datetime import UTC, datetime, timedelta, timezone
import pytest
from repo_manager.time import format_utc
def test_format_utc_normalizes_offsets_and_uses_z() -> None:
local = datetime(2026, 8, 21, 22, 30, tzinfo=timezone(timedelta(hours=2)))
assert format_utc(local) == "2026-08-21T20:30:00Z"
assert format_utc(local.astimezone(UTC)).endswith("Z")
def test_format_utc_rejects_naive_datetime() -> None:
with pytest.raises(ValueError, match="timezone-aware"):
format_utc(datetime(2026, 8, 21, 20, 30)) # noqa: DTZ001 - deliberate invalid input