MCPcopy
hub / github.com/nonebot/nonebot2 / test_template_message

Function test_template_message

tests/test_adapters/test_template.py:13–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def test_template_message():
14 template = FakeMessage.template("{a:custom}{b:text}{c:image}/{d}")
15
16 @template.add_format_spec
17 def custom(input: str) -> str:
18 return f"{input}-custom!"
19
20 with pytest.raises(ValueError, match="already exists"):
21 template.add_format_spec(custom)
22
23 format_args = {
24 "a": "custom",
25 "b": "text",
26 "c": "https://example.com/test",
27 "d": 114,
28 }
29 formatted = template.format(**format_args)
30
31 assert template.format_map(format_args) == formatted
32 assert formatted.extract_plain_text() == "custom-custom!text/114"
33 assert str(formatted) == "custom-custom!text[fake:image]/114"
34
35
36def test_rich_template_message():

Callers

nothing calls this directly

Calls 5

templateMethod · 0.80
add_format_specMethod · 0.80
formatMethod · 0.80
format_mapMethod · 0.80
extract_plain_textMethod · 0.80

Tested by

no test coverage detected