test: 覆盖率提升至 100%(fail_under 90→99,13 个防御/边界用例)

This commit is contained in:
lhl
2026-08-09 04:49:29 +08:00
parent 737911cf25
commit 2fbff07d3f
10 changed files with 180 additions and 46 deletions
+37
View File
@@ -4,6 +4,43 @@ from genesis.parsers.excel_parser import ExcelParseResult, ExcelParser
from tests.excel_helpers import new_workbook, save_workbook
def test_parse_skips_empty_sheet(tmp_path):
# 空 sheet → skipped 不进入(L skips 分支)
wb = new_workbook({"空白": [[]]})
path = save_workbook(tmp_path, wb)
result = ExcelParser().parse(path)
assert "空白" in result.skipped
assert result.tables == []
def test_parse_mixed_formatting_outside_table_segment(tmp_path):
# 碎片段(free_text 段)存在取消线格式 → seg_fmt_map 构建时该行不在表格段 [s,e] 内,被跳过(66-65 分支)
from copy import copy
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.title = "混合"
data = [
["機能ID", "機能名"], ["F101", "社員登録"],
[],
["・改述ポイント"],
]
for r, row in enumerate(data, start=1):
for c, v in enumerate(row, start=1):
if v:
ws.cell(row=r, column=c, value=v)
font = copy(ws.cell(row=4, column=1).font) # 碎片段行(物理行 4
font.strike = True
ws.cell(row=4, column=1).font = font
path = save_workbook(tmp_path, wb)
result = ExcelParser().parse(path)
ms = result.mixed[0]
tbl = [p.table for p in ms.paragraphs if p.kind == "table"][0]
# 表格段数据行不应带上碎片段的取消线格式
assert tbl.rows[0]["機能ID"].formatting is None
assert len(tbl.rows) == 1
def test_parse_table_sheets(tmp_path):
wb = new_workbook({
"機能一覧": [["機能ID", "機能名"], ["A001", "社員登録"]],