feat(ppclock): 命令层/传输层/CLI/本地模板渲染,90 测试全绿
This commit is contained in:
1 parent
6f5b0c60be
commit
2b01e5f589
60 files changed
+16869
No files matched your search
@@ -0,0 +1,34 @@
|
||||
"""模板渲染测试。"""
|
||||
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", {})
|
||||
Reference in new issue
Block a user