v0.3.6-pre.001-fix.001

This commit is contained in:
2026-09-01 10:43:09 +02:00
parent 6f2d0a092a
commit ecfc30a94b
25 changed files with 706 additions and 392 deletions

View File

@@ -0,0 +1,67 @@
#!/usr/bin/env python3
# file: scripts/tests/test_audit_markdown_tables.py
# version: 1
"""Regression tests for the KSP Markdown table audit."""
from __future__ import annotations
import pathlib
import sys
import tempfile
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
import audit_markdown_tables
class MarkdownTableAuditTests(unittest.TestCase):
"""Cover table recognition and source alignment semantics."""
def audit(self, contents: str) -> tuple[int, list[str]]:
"""Audit one temporary Markdown fixture."""
with tempfile.TemporaryDirectory() as directory:
path = pathlib.Path(directory) / "fixture.md"
path.write_text(contents, encoding="utf-8")
return audit_markdown_tables._audit_file(path)
def test_accepts_left_and_right_aligned_columns(self) -> None:
"""Canonical left and right padding follows the separator markers."""
table_count, errors = self.audit("| Name | Count |\n|------|------:|\n| A | 2 |\n")
self.assertEqual(table_count, 1)
self.assertEqual(errors, [])
def test_accepts_explicit_left_and_centered_columns(self) -> None:
"""Leading and paired colons select left and centered alignment."""
table_count, errors = self.audit("| Name | State |\n|:-----|:-----:|\n| A | ok |\n")
self.assertEqual(table_count, 1)
self.assertEqual(errors, [])
def test_rejects_spaced_separator_that_was_previously_skipped(self) -> None:
"""A malformed but recognizable separator is audited instead of ignored."""
table_count, errors = self.audit("| Name | Count |\n| --- | ---: |\n| A | 2 |\n")
self.assertEqual(table_count, 1)
self.assertTrue(errors)
def test_rejects_left_padding_in_right_aligned_column(self) -> None:
"""A trailing colon requires right-aligned source cells."""
table_count, errors = self.audit("| Name | Count |\n|------|------:|\n| A | 2 |\n")
self.assertEqual(table_count, 1)
self.assertTrue(any("right-aligned" in error for error in errors))
def test_rejects_right_padding_in_explicit_left_column(self) -> None:
"""A leading colon requires left-aligned source cells."""
table_count, errors = self.audit("| Name | Count |\n|:-----|-------|\n| A | 2 |\n")
self.assertEqual(table_count, 1)
self.assertTrue(any("left-aligned" in error for error in errors))
if __name__ == "__main__":
unittest.main()