35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
"""模板渲染测试。"""
|
|
import pytest
|
|
|
|
from ppclock import templates as T
|
|
|
|
|
|
@pytest.mark.parametrize("name", sorted(T.RENDERERS))
|
|
def test_all_templates_render_400x300(name):
|
|
payloads = {
|
|
"schedule": {"items": [["09:00", "晨会【重要】"]]},
|
|
"businesscard": {"name": "张三", "title": "工程师", "phone": "138"},
|
|
"memo": {"title": "购物", "lines": ["牛奶", "鸡蛋"]},
|
|
"course": {"grid": [["数学"]]},
|
|
"qrcode": {"content": "https://example.com", "caption": "扫码"},
|
|
"custom": {"text": "你好【世界】\n第二行"},
|
|
}
|
|
img = T.render_template(name, payloads[name])
|
|
assert img.size == (400, 300)
|
|
assert img.mode == "RGB"
|
|
|
|
|
|
def test_custom_wraps_long_text():
|
|
img = T.render_template("custom", {"text": "长" * 100})
|
|
assert img.size == (400, 300)
|
|
|
|
|
|
def test_red_segments_rendered_red():
|
|
img = T.render_template("custom", {"text": "【红】"})
|
|
assert (255, 0, 0) in set(img.getdata())
|
|
|
|
|
|
def test_unknown_template_raises():
|
|
with pytest.raises(ValueError):
|
|
T.render_template("nope", {})
|