"""HTML → 专业 Word(.docx) 转换器测试。 覆盖:表格转 Word 表格、标题分级、Markdown/AI 噪声剥离、style/svg 丢弃、 中文与产物可被 python-docx 重新打开(结构有效)。 """ from __future__ import annotations from io import BytesIO import pytest from services.docx_export import html_to_docx, docx_available pytestmark = pytest.mark.skipif(not docx_available(), reason="python-docx 未安装") _SAMPLE_HTML = """
溶化时限符合限度。**这段含粗体**和 *斜体* 应被清理。
* 这是一个伪列表行
| 规格 | AV | 判定 |
|---|---|---|
| 20μg | 5.074 | 符合 |
| 40μg | 3.418 | 符合 |
正文内容
| 单位 | 值 |
|---|---|
| 1 | 99.19 |
前
后
" data = html_to_docx(html) assert data and data[:2] == b"PK" # 不崩溃,仍产出有效 docx doc = _open(data) texts = "\n".join(p.text for p in doc.paragraphs) assert "前" in texts and "后" in texts