@@ -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,12 +21,28 @@ 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"
|
||||
EXAMPLE_JSON = TOOL_ROOT / "examples" / "example.json"
|
||||
EXAMPLE_YAML = TOOL_ROOT / "examples" / "example.yaml"
|
||||
SKILL = REPO_ROOT / "skills" / "tsl-api-reference" / "SKILL.md"
|
||||
API_WORKFLOW = (
|
||||
REPO_ROOT / "skills" / "tsl-api-reference" / "workflows" / "api-lookup.md"
|
||||
)
|
||||
|
||||
|
||||
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):
|
||||
@@ -35,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)],
|
||||
@@ -212,6 +258,7 @@ class UnifiedPipelineTest(unittest.TestCase):
|
||||
standard = STANDARD.read_text(encoding="utf-8")
|
||||
readme = README.read_text(encoding="utf-8")
|
||||
skill = SKILL.read_text(encoding="utf-8")
|
||||
api_workflow = API_WORKFLOW.read_text(encoding="utf-8")
|
||||
|
||||
self.assertTrue(standard.startswith("# TSL API 文档标准\n"))
|
||||
self.assertNotIn("根字段 `functions`、`class`、`unit`", standard)
|
||||
@@ -273,8 +320,9 @@ class UnifiedPipelineTest(unittest.TestCase):
|
||||
self.assertNotIn("generate.py tmp/my-api.yaml", readme)
|
||||
self.assertNotIn("generate.py tmp/my-api.json", readme)
|
||||
self.assertNotIn("已废弃,请使用 --file", readme)
|
||||
self.assertIn("混合页面", skill)
|
||||
self.assertIn("page#anchor", skill)
|
||||
self.assertIn("workflows/api-lookup.md", skill)
|
||||
self.assertIn("混合页面", api_workflow)
|
||||
self.assertIn("page#anchor", api_workflow)
|
||||
|
||||
def test_standard_class_methods_reuse_top_level_function_structure(self):
|
||||
standard = STANDARD.read_text(encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user