Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
from pathlib import Path
|
|
|
|
from docx import Document
|
|
|
|
from bidmaster.nodes.content.init_config import InitConfigNode
|
|
|
|
|
|
def _create_deep_heading_doc(path: Path) -> None:
|
|
doc = Document()
|
|
doc.add_heading("8 服务方案", level=1)
|
|
doc.add_heading("8.1 大南湖七矿VR智能培训系统及智能体感设备设计方案", level=2)
|
|
doc.add_heading("8.1.1 VR智能培训中心", level=3)
|
|
doc.add_heading("8.1.1.1 煤矿典型事故案例VR教学系统", level=4)
|
|
doc.add_heading("煤矿重大灾害VR虚拟体验与逃生系统", level=5)
|
|
doc.save(path)
|
|
|
|
|
|
def test_load_from_word_document_handles_deep_headings(tmp_path) -> None:
|
|
doc_path = tmp_path / "deep.docx"
|
|
_create_deep_heading_doc(doc_path)
|
|
|
|
node = InitConfigNode()
|
|
chapters = node._load_from_word_document(str(doc_path))
|
|
|
|
assert len(chapters) == 5
|
|
assert chapters[0]["id"] == "chapter_8"
|
|
assert chapters[1]["id"] == "chapter_8_1"
|
|
assert chapters[2]["parent_id"] == chapters[1]["id"]
|
|
|
|
deepest = chapters[-1]
|
|
assert deepest["level"] == 5
|
|
assert deepest["heading_number"] is None
|
|
assert deepest["id"] == "chapter_8_1_1_1_a"
|
|
assert deepest["parent_id"] == chapters[-2]["id"]
|
|
|
|
|
|
def test_apply_metadata_to_chapters_enriches_requirements() -> None:
|
|
node = InitConfigNode()
|
|
title = "1.1 技术方案-基本要求 (3.0分)"
|
|
normalized = node._normalize_heading_text(title)
|
|
chapters = [
|
|
{
|
|
"id": "chapter_1_1",
|
|
"title": title,
|
|
"raw_heading": title,
|
|
"normalized_title": normalized,
|
|
"requirements": "",
|
|
"score": 0,
|
|
}
|
|
]
|
|
|
|
metadata_lookup = {
|
|
normalized: {
|
|
"title": title,
|
|
"score": 3.0,
|
|
"category": "technical_solution",
|
|
"requirements": "需覆盖总体架构、性能指标与技术栈选择。",
|
|
"rubric_points": ["总体架构完整", "性能指标可量化"],
|
|
"source": "analysis_result",
|
|
"chapter_id_source": "tech_solution_01_01",
|
|
}
|
|
}
|
|
|
|
enriched = node._apply_metadata_to_chapters(chapters, metadata_lookup)
|
|
|
|
assert chapters[0]["requirements"].startswith("需覆盖")
|
|
assert chapters[0]["score"] == 3.0
|
|
assert enriched["chapter_1_1"]["rubric_points"][0] == "总体架构完整"
|