Generate TSL API Markdown from YAML or JSON into a configurable project scope.\nAdd file and directory lint modes, tags-aware indexing, and keyword search across tags and descriptions.\nBundle the toolkit through the playbook build and sync workflows.
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
|
|
SCRIPT = Path(__file__).parents[1] / "scripts" / "lint.py"
|
|
VALID_PAGE = "# 项目 / 示例\n\n## `demo()`\n\n示例函数\n\n返回:nil\n"
|
|
|
|
|
|
class DocLintCliTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.temp_dir = tempfile.TemporaryDirectory()
|
|
self.root = Path(self.temp_dir.name)
|
|
self.page = self.root / "base" / "demo.md"
|
|
self.page.parent.mkdir()
|
|
self.page.write_text(VALID_PAGE, encoding="utf-8")
|
|
|
|
def tearDown(self):
|
|
self.temp_dir.cleanup()
|
|
|
|
def run_cli(self, *args):
|
|
return subprocess.run(
|
|
[sys.executable, str(SCRIPT), *map(str, args)],
|
|
capture_output=True,
|
|
text=True,
|
|
encoding="utf-8",
|
|
)
|
|
|
|
def test_accepts_one_markdown_file(self):
|
|
result = self.run_cli("--file", self.page)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertIn("1 files", result.stderr)
|
|
|
|
def test_accepts_one_directory(self):
|
|
result = self.run_cli("--dir", self.root)
|
|
self.assertEqual(result.returncode, 0, result.stderr)
|
|
self.assertIn("1 files", result.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|