test: 真实样本 Word 解析集成测试(模板/规则/说明书画属write)

This commit is contained in:
lhl
2026-08-10 15:17:44 +08:00
parent 7f29cc9cf3
commit 16921ecbb4
2 changed files with 65 additions and 1 deletions
+64 -1
View File
@@ -3,10 +3,17 @@ from pathlib import Path
import pytest
from genesis.parsers.excel_parser import ExcelParser
from genesis.parsers.word_template_parser import WordTemplateParser
from genesis.parsers.rule_doc_parser import RuleDocParser
from genesis.parsers.source_aggregator import SourceParser
SAMPLES = Path(__file__).resolve().parents[1] / "samples"
def _d(name: str) -> Path:
return SAMPLES / name
def _x(name: str) -> Path:
return SAMPLES / name
@@ -57,4 +64,60 @@ def test_mixed_sample_segments_detected():
# 碎片段含 ・ 与 ■ 两行文本
ft = [p for p in mixed.paragraphs if p.kind == "free_text"][0]
assert "改修ポイント" in (ft.text or "")
assert "対象期間" in (ft.text or "")
assert "対象期間" in (ft.text or "")
def test_word_template_sample_chapters_and_placeholders():
p = _d("概要設計書テンプレート.docx")
if not p.exists():
pytest.skip("样本缺失")
result = WordTemplateParser().parse(p)
headings = [s for s in result.sections if s.type == "heading"]
h1 = [h for h in headings if h.level == 1]
assert len(h1) == 7
assert h1[0].name == "1. はじめに"
assert h1[-1].name == "7. バッチ一覧"
assert "section:introduction" in result.placeholders
assert "doc_title" in result.placeholders
bookmarks = [s for s in result.sections if s.type == "bookmark"]
assert len(bookmarks) == 1
assert bookmarks[0].name == "template_start"
def test_rule_doc_sample_markdown_and_category():
p = _d("記入規則.docx")
if not p.exists():
pytest.skip("样本缺失")
result = RuleDocParser().parse(p, category="write")
assert result.category == "write"
assert result.file_type == "word"
assert "# 1. 機能一覧の書き方" in result.markdown_content
assert "- 機能ID は F001 から連番で付与する。" in result.markdown_content
def test_write_instruction_sample_category_write():
p = _d("概要設計做成説明書.docx")
if not p.exists():
pytest.skip("样本缺失")
result = RuleDocParser().parse(p, category="write")
assert result.category == "write"
assert "# 2. 機能一覧" in result.markdown_content
def test_source_parser_full_sample_assembly():
xlsx = _x("要件定義_新規開発.xlsx")
template = _d("概要設計書テンプレート.docx")
rule = _d("記入規則.docx")
instr = _d("概要設計做成説明書.docx")
if not all(p.exists() for p in [xlsx, template, rule, instr]):
pytest.skip("样本缺失")
result = SourceParser().parse(
requirement_paths=[xlsx],
template_path=template,
write_instruction_paths=[instr],
rule_paths=[rule],
)
assert result.tables
assert result.template is not None
assert len(result.rule_docs) == 2
assert all(r.category == "write" for r in result.rule_docs)