Skip to content

Commit e01b03b

Browse files
authored
fix(ci): release 测试装 WeasyPrint 系统库 + PDF 测试容错(修 0.9.3 发布) (#66)
CI 测试步骤补 WeasyPrint 系统库 + fonts-noto-cjk;PDF 测试对回退后端容错。
1 parent d9f9c0e commit e01b03b

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
with:
4343
python-version: '3.11'
4444

45+
- name: Install system libs for WeasyPrint (PDF export tests)
46+
run: |
47+
sudo apt-get update
48+
sudo apt-get install -y --no-install-recommends \
49+
libpango-1.0-0 libpangocairo-1.0-0 libpangoft2-1.0-0 \
50+
libcairo2 libcairo-gobject2 libgdk-pixbuf-2.0-0 \
51+
libffi-dev libfontconfig1 fonts-noto-cjk
52+
4553
- name: Install dependencies
4654
run: pip install -r requirements.txt
4755

tests/test_pdf_export.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
import io
66

77

8+
def _weasyprint_renders() -> bool:
9+
"""WeasyPrint 能否真正渲染(需 pango 等系统库)。不可用时回退 xhtml2pdf,中文走 CID 字体不进文本层。"""
10+
try:
11+
from weasyprint import HTML
12+
13+
HTML(string="<p>测试</p>").write_pdf()
14+
return True
15+
except Exception:
16+
return False
17+
18+
19+
_WEASY = _weasyprint_renders()
20+
21+
822
def test_render_pdf_returns_valid_bytes_with_chinese():
923
"""markdown→PDF:返回合法 PDF 字节,且中文进入文本层(非豆腐块、可复制)。"""
1024
from src.core.pdf_export import render_analysis_pdf
@@ -15,6 +29,9 @@ def test_render_pdf_returns_valid_bytes_with_chinese():
1529
assert bytes(data[:4]) == b"%PDF"
1630
assert len(data) > 1500
1731

32+
if not _WEASY:
33+
return # xhtml2pdf 回退:中文走 STSong-Light CID,不进文本层;仅 WeasyPrint 路径保证可复制中文
34+
1835
from pypdf import PdfReader
1936

2037
txt = PdfReader(io.BytesIO(bytes(data))).pages[0].extract_text() or ""
@@ -94,6 +111,9 @@ def test_pdf_endpoint_returns_full_detail_content():
94111
assert bytes(resp.body[:4]) == b"%PDF"
95112
assert "attachment" in resp.headers["content-disposition"]
96113

114+
if not _WEASY:
115+
return # 中文文本层仅 WeasyPrint 路径可提取;content 组装由 test_assemble_* 覆盖
116+
97117
from pypdf import PdfReader
98118

99119
reader = PdfReader(io.BytesIO(bytes(resp.body)))

0 commit comments

Comments
 (0)