♻️ refactor(tsl-api): tighten docs and retire stale tests

This commit is contained in:
csh
2026-08-21 10:11:48 +08:00
parent 2e8c46e152
commit 5484fc7519
24 changed files with 505 additions and 2700 deletions
+43
View File
@@ -1,3 +1,4 @@
import importlib.util
import json
import subprocess
import sys
@@ -11,6 +12,8 @@ try:
except ImportError:
yaml = None
BS4_AVAILABLE = importlib.util.find_spec("bs4") is not None
TOOL_ROOT = Path(__file__).resolve().parents[1]
REPO_ROOT = TOOL_ROOT.parents[1]
@@ -18,6 +21,7 @@ CONVERT = TOOL_ROOT / "scripts" / "convert_tsf.py"
GENERATE = TOOL_ROOT / "scripts" / "generate.py"
LINT = TOOL_ROOT / "scripts" / "lint.py"
BUILD_INDEX = TOOL_ROOT / "scripts" / "build_index.py"
BUILD_DICTIONARY = TOOL_ROOT / "scripts" / "build_dictionary.py"
LOOKUP = REPO_ROOT / "skills" / "tsl-api-reference" / "scripts" / "lookup.py"
STANDARD = TOOL_ROOT / "STANDARD.md"
README = TOOL_ROOT / "README.md"
@@ -29,6 +33,18 @@ API_WORKFLOW = (
)
def load_build_dictionary():
spec = importlib.util.spec_from_file_location(
"tsl_codegen_build_dictionary", BUILD_DICTIONARY
)
if spec is None or spec.loader is None:
raise RuntimeError(f"cannot load {BUILD_DICTIONARY}")
module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
return module
class UnifiedPipelineTest(unittest.TestCase):
def setUp(self):
self.temp_dir = tempfile.TemporaryDirectory()
@@ -38,6 +54,33 @@ class UnifiedPipelineTest(unittest.TestCase):
def tearDown(self):
self.temp_dir.cleanup()
@unittest.skipUnless(BS4_AVAILABLE, "beautifulsoup4 is not installed")
def test_dictionary_notes_escape_source_numbering(self):
module = load_build_dictionary()
page = module.DictionaryPage(
kind="table",
scope="macro",
title="示例",
source_path=("宏观",),
source_file="example.html",
table=module.DictionaryTable(
name="示例",
table_id="1",
extract_method="",
access_code="",
update_info=("1、更新频率:月度",),
),
fields=(),
notes=("1. 第一条说明", "2. 第二条说明"),
examples=(),
)
rendered = module.render_dictionary_page(page)
self.assertIn("- 1\\. 第一条说明", rendered)
self.assertIn("- 2\\. 第二条说明", rendered)
self.assertIn("- 1、更新频率:月度", rendered)
def run_command(self, *args, cwd=None):
return subprocess.run(
[sys.executable, *map(str, args)],