Files
2026Technology-Competition/tests/test_phase5_e2e.py
T
lhl becd3e1f57 chore(assets): 参赛提交规范红线修复(ASCII 化 + 相对路径)
按《参赛成果物提交规范·赛道一》§6 红线:
- samples/ 目录改名 sample/(git mv,保留历史)
- 10 个中日文样本文件 + docs 参赛手册 PDF 重命名为 ASCII
  (requirements_*/template_*/rules_*/contestant-handbook.pdf)
- tests/test_zh_template.py 硬编码绝对路径 D:\00_project\Genesis 改为相对路径
- 全局更新 21 个活动文件引用;历史日志/审查文档不改(追加说明记录)
全量 pytest 431 passed / 99.15%
2026-08-26 14:15:52 +08:00

56 lines
2.0 KiB
Python

import pytest
from types import SimpleNamespace
from pathlib import Path
from docx import Document
from genesis.data_models import StructuredSource
from genesis.parsers.word_template_parser import WordTemplateParser
from genesis.qa.qa_loop import QALoop
class FakeEngine:
def chat_structured(self, *, session_id, prompt, variables, schema, retry_count=2):
cid = variables.get("title", "x")
# 日文模板章节(标题含假名)→ 返回日文正文,满足语言一致性强制
return SimpleNamespace(
data={
"title": cid,
"blocks": [
{"type": "heading", "level": 2, "text": f"{cid} 小節"},
{"type": "paragraph", "text": "本機能はFakeLLMにより生成された十分な説明内容であり、書込規則を満たす。"},
{"type": "table", "caption": "示例表", "rows": [["列1", "列2"], ["値1", "値2"]]},
],
},
status="ok",
)
def _all_text(doc: Document) -> str:
parts = [p.text for p in doc.paragraphs]
for tbl in doc.tables:
for row in tbl.rows:
for cell in row.cells:
parts.append(cell.text)
return "\n".join(parts)
def test_phase5_e2e_fake_llm(tmp_path):
template = Path("sample/phase5-slice/template.docx")
if not template.exists():
pytest.skip("样本模板缺失,跳过 e2e")
parsed = WordTemplateParser().parse(str(template))
ss = StructuredSource(
template=parsed, tables=[], rule_docs=[], image_analyses=[], existing_system=None, comments=[]
)
out = tmp_path / "e2e_out.docx"
loop = QALoop(max_rounds=2)
report = loop.run(
ss, str(out), samples_dir="nonexistent_dir_xyz", engine=FakeEngine(), template_path=str(template)
)
assert report.passed is True
loaded = Document(str(out))
text = _all_text(loaded)
assert "本機能はFakeLLMにより生成された十分な説明内容" in text
assert "示例表" in text