45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
from pathlib import Path
|
|
import json
|
|
import pytest
|
|
from scripts.audit.generate_chronology import extract_slug_date, extract_summary
|
|
|
|
|
|
def test_slug_date_extraction() -> None:
|
|
result: str = extract_slug_date("gencpp_python_bindings_20260308")
|
|
assert result == "2026-03-08"
|
|
|
|
|
|
def test_slug_date_extraction_handles_missing_date() -> None:
|
|
result = extract_slug_date("my_folder")
|
|
assert result is None
|
|
|
|
|
|
def test_summary_extraction_from_spec_md(tmp_path: Path) -> None:
|
|
spec_content: str = "# Title\n\n## Overview\n\nFirst sentence here. Second sentence.\n"
|
|
(tmp_path / "spec.md").write_text(spec_content, encoding="utf-8")
|
|
result: str = extract_summary(tmp_path)
|
|
assert result == "First sentence here."
|
|
|
|
|
|
def test_summary_extraction_falls_back_to_metadata(tmp_path: Path) -> None:
|
|
metadata: dict = {"description": "From metadata."}
|
|
(tmp_path / "metadata.json").write_text(json.dumps(metadata), encoding="utf-8")
|
|
result: str = extract_summary(tmp_path)
|
|
assert result == "From metadata."
|
|
|
|
|
|
def test_summary_extraction_truncates_to_25_words(tmp_path: Path) -> None:
|
|
long_line: str = " ".join(["word"] * 50)
|
|
spec_content: str = f"# Title\n\n{long_line}\n"
|
|
(tmp_path / "spec.md").write_text(spec_content, encoding="utf-8")
|
|
result: str = extract_summary(tmp_path)
|
|
expected: str = " ".join(["word"] * 25) + "\u2026"
|
|
assert result == expected
|
|
assert result.endswith("\u2026")
|
|
|
|
|
|
def test_summary_extraction_skips_status_metadata_line(tmp_path: Path) -> None:
|
|
spec_content: str = "# Title\n\n**Status:** Spec approved 2026-06-19\n\nReal description of the work.\n"
|
|
(tmp_path / "spec.md").write_text(spec_content, encoding="utf-8")
|
|
result: str = extract_summary(tmp_path)
|
|
assert result == "Real description of the work." |