Files
ai-agent-book/tests/test_gen_star_history_iso_formats.py
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

45 lines
1.3 KiB
Python

import sys
from datetime import datetime, timezone
from pathlib import Path
import pytest
pytest.importorskip("matplotlib")
sys.path.insert(0, str(Path(__file__).parent.parent / "scripts"))
from gen_star_history import build_series, parse_iso_timestamp
def test_parse_iso_timestamp_supports_various_iso_formats():
"""Contract: parse_iso_timestamp parses standard ISO 8601 strings into UTC datetimes."""
timestamps = [
"2026-07-15T12:34:56Z",
"2026-07-15T12:34:56.789Z",
"2026-07-15T12:34:56.123456Z",
"2026-07-15T12:34:56+02:00",
"2026-07-15T12:34:56-05:00",
"2026-07-15T12:34:56",
"2026-07-15",
]
for ts in timestamps:
dt = parse_iso_timestamp(ts)
assert isinstance(dt, datetime)
assert dt.tzinfo == timezone.utc
def test_build_series_handles_fractional_and_timezone_iso_strings():
"""Contract: build_series parses stargazers with fractional seconds and explicit tz offsets without ValueError."""
starred = [
"2026-07-15T10:00:00.123Z",
"2026-07-15T14:00:00+02:00",
"2026-07-16T08:00:00Z",
]
start = datetime(2026, 7, 15, 0, 0, 0, tzinfo=timezone.utc)
x, y = build_series(starred, start)
assert len(x) == 4 # anchor + 3 points
assert len(y) == 4
assert y[0] == 0
assert y[-1] == 3