from __future__ import annotations import json import sys from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] if str(REPO_ROOT) not in sys.path: sys.path.insert(0, str(REPO_ROOT)) from scripts.reporting.fonts import resolve_quarto_fonts from scripts.reporting.references import build_references_block def test_build_references_block_uses_only_cited_sources(tmp_path: Path) -> None: sources = tmp_path / "sources.jsonl" rows = [ {"id": "src_001", "authors": ["A"], "year": 2024, "title": "Used", "venue": "NEJM", "url": "https://example.com/1"}, {"id": "src_002", "authors": ["B"], "year": 2023, "title": "Unused", "venue": "Lancet", "url": "https://example.com/2"}, ] sources.write_text("\n".join(json.dumps(row, ensure_ascii=False) for row in rows), encoding="utf-8") block = build_references_block(sources, "正文引用 [src_001]。") assert "Used" in block assert "Unused" not in block def test_resolve_quarto_fonts_returns_stable_defaults_for_missing_dir(tmp_path: Path) -> None: fonts = resolve_quarto_fonts(tmp_path / "missing") assert fonts.main_font == "Source Han Serif CN" assert fonts.sans_font == "Source Han Sans CN" assert fonts.requires_system_fonts is True