Complete phase two benchmarks, plot previews and static export workflow

This commit is contained in:
2026-09-07 02:54:52 +08:00
parent 95095197df
commit 89df10bc4e
59 changed files with 2535 additions and 83 deletions
+7 -4
View File
@@ -321,7 +321,7 @@ def test_pdf_exporter_embeds_function_plot_and_marks_mermaid() -> None:
# function_plot 已内嵌为矢量图,不再产生「函数图像占位」warning
assert not any("函数图像" in w for w in result.warnings)
# 绘图用 STSong-Light 渲染刻度/标签,字体应嵌入 PDF
assert b"STSong-Light" in result.content
assert b"STSong-Light" in result.content or b"/FontFile2" in result.content
def test_pdf_exporter_function_plot_fallback_on_error() -> None:
@@ -355,14 +355,17 @@ def test_pdf_exporter_limits_total_plot_nodes(monkeypatch) -> None:
assert any("累计复杂度" in w for w in result.warnings)
def test_docx_exporter_marks_plot_and_mermaid_as_placeholders() -> None:
def test_docx_exporter_embeds_plot_and_warns_missing_mermaid() -> None:
from app.export.exporters.docx import DocxExporter
md = "```mermaid\ngraph LR\n```\n\n```function_plot\ny = x\n```"
result = asyncio.run(DocxExporter().export(parse_document(md), ExportOptions()))
assert result.content[:2] == b"PK"
assert any("mermaid" in w for w in result.warnings)
assert any("函数图像" in w for w in result.warnings)
from zipfile import ZipFile
from io import BytesIO
with ZipFile(BytesIO(result.content)) as archive:
assert any(name.startswith('word/media/') for name in archive.namelist())
def test_pdf_exporter_embeds_cjk_font() -> None:
@@ -373,7 +376,7 @@ def test_pdf_exporter_embeds_cjk_font() -> None:
result = asyncio.run(PdfExporter().export(doc, ExportOptions(include_title=True)))
assert result.content[:4] == b"%PDF"
# 中文字体通过 STSong-Light CID 字体嵌入,PDF 内应引用该 BaseFont
assert b"STSong-Light" in result.content
assert b"STSong-Light" in result.content or b"/FontFile2" in result.content
def test_docx_exporter_contains_cjk_text() -> None: