iftypeset/tests/test_linting.py
2026-01-03 20:29:35 +00:00

44 lines
1.4 KiB
Python

import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SRC = ROOT / "src"
sys.path.insert(0, str(SRC))
from iftypeset.linting import lint_paths, manual_checklist # noqa: E402
from iftypeset.spec_loader import load_spec # noqa: E402
class LintingTests(unittest.TestCase):
def test_lint_diagnostics_and_fixes(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "doc.md"
path.write_text(
"# Title\n\nLine with trailing spaces \n\nSee [link] ( https://example.com )\n",
encoding="utf-8",
)
result = lint_paths(
[path],
profile_id="web_pdf",
fix=True,
fix_mode="suggest",
degraded_ok=True,
fail_on="warn",
)
codes = {d.get("code") for d in result.report.get("diagnostics", [])}
self.assertIn("WS.TRAILING", codes)
self.assertIn("LINK.SPACING", codes)
self.assertTrue(result.report.get("fixes"))
def test_manual_checklist_emits_rules(self) -> None:
spec = load_spec(ROOT / "spec")
items = manual_checklist(spec)
self.assertTrue(items)
ids = {item.get("id") for item in items}
self.assertIn("CMOS.NUMBERS.SPELLING.ONE_TO_ONE_HUNDRED.DEFAULT", ids)
if __name__ == "__main__":
unittest.main()