Files
2026Technology-Competition/tests/test_excel_reader.py
T
lhl d9aa3a3325 fix(writer): 修复概要设计书输出塌缩与章间引用缺失,并补 parser 防灾
- Writer: 表格表头行/Table Grid 边框、列表 List Bullet/Number 样式、行内字符格式不再塌缩(外视 #6 反转)
- Writer: 打通章间引用(WriterState 摘要 → 后章 prompt prior_summaries)
- Writer: 删除 _chunk_source 死代码,章节数据经 DataGate 控 token 预算
- Writer: 章节结果落盘快照,命中即跳过 LLM(录制重拍可续跑,损坏快照自动忽略)
- Parser: 按 body 顺序遍历正文+单元格(含嵌套表、合并单元格去重),修复表格内锚点漏检导致的静默丢章
- Parser/服务层: .xls 显式拒绝(可操作提示),上传即校验扩展名,rules 对齐 docx-only
- 测试: 全量 680 通过,覆盖率 99.37%(红线 99%)
2026-09-15 21:30:55 +08:00

32 lines
1.1 KiB
Python

import pytest
from genesis.parsers.excel_reader import open_workbook, sheet_matrix
from genesis.parsers.provenance import build_source_uri
from tests.excel_helpers import new_workbook, save_workbook
def test_build_source_uri_format():
assert build_source_uri("要求.xlsx", "機能一覧", "A5") == "要求.xlsx#機能一覧!A5"
def test_open_workbook_and_sheet_matrix(tmp_path):
wb = new_workbook({"機能一覧": [["機能ID", "機能名"], ["F001", "社員登録"]]})
path = save_workbook(tmp_path, wb)
ws = open_workbook(path)["機能一覧"]
assert sheet_matrix(ws) == [["機能ID", "機能名"], ["F001", "社員登録"]]
def test_open_workbook_rejects_legacy_xls_actionably(tmp_path):
bad = tmp_path / "old.xls"
bad.write_bytes(b"not really xls")
with pytest.raises(ValueError, match="另存为 .xlsx"):
open_workbook(bad)
def test_open_workbook_rejects_other_extension(tmp_path):
bad = tmp_path / "note.csv"
bad.write_text("a,b", encoding="utf-8")
with pytest.raises(ValueError, match="不支持的 Excel 格式"):
open_workbook(bad)