Files
group_fqcd_jr/tests/unit/service/test_promotion_poster_renderer.py
T

46 lines
1.5 KiB
Python
Raw Normal View History

2026-09-11 16:57:47 +08:00
from pathlib import Path
from PIL import Image
from app.service.promotion_poster_renderer import PromotionPosterRenderer
def _draft(style_code: str) -> dict[str, object]:
return {
"style_code": style_code,
"title": "测试基金产品推介材料",
"chapters": [
{"title": "产品基本信息", "body": "基金类型:混合型\n运作方式:开放式"},
{"title": "投资范围、策略与限制", "body": "股票和债券,长期配置"},
{"title": "管理人及投研团队", "body": "管理人:测试基金管理有限公司"},
{"title": "收益与风险指标", "body": "产品收益 8%,最大回撤 -5%,夏普比率 0.8"},
],
}
def test_poster_renderer_creates_readable_dark_reference_style(tmp_path: Path) -> None:
output = tmp_path / "dark-poster.png"
result = PromotionPosterRenderer().render(
_draft("balanced_allocation"),
output,
)
assert result == str(output)
with Image.open(output) as image:
assert image.size == (1800, 2600)
assert image.getpixel((10, 10)) == (14, 59, 102)
def test_poster_renderer_creates_readable_warm_reference_style(tmp_path: Path) -> None:
output = tmp_path / "warm-poster.png"
PromotionPosterRenderer().render(
_draft("steady_professional"),
output,
)
with Image.open(output) as image:
assert image.size == (1800, 2600)
assert image.getpixel((10, 10)) == (201, 76, 47)