mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-06 20:16:47 +00:00
✅ add message tests
This commit is contained in:
17
tests/test_adapters/test_template.py
Normal file
17
tests/test_adapters/test_template.py
Normal file
@ -0,0 +1,17 @@
|
||||
from utils import make_fake_message
|
||||
|
||||
|
||||
def test_message_template():
|
||||
from nonebot.adapters import MessageTemplate
|
||||
|
||||
Message = make_fake_message()
|
||||
|
||||
template = MessageTemplate("{a:custom}{b:text}{c:image}", Message)
|
||||
|
||||
@template.add_format_spec
|
||||
def custom(input: str) -> str:
|
||||
return input + "-custom!"
|
||||
|
||||
formatted = template.format(a="test", b="test", c="https://example.com/test")
|
||||
assert formatted.extract_plain_text() == "test-custom!test"
|
||||
assert str(formatted) == "test-custom!test[fake:image]"
|
Reference in New Issue
Block a user