From 92ff1df419e641706bfde8f6d99693f7f2e58ef0 Mon Sep 17 00:00:00 2001 From: Mix <32300164+mnixry@users.noreply.github.com> Date: Mon, 22 Aug 2022 14:39:00 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=E5=BD=93=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E4=B8=8E=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9A=84=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9B=B8=E5=8A=A0=E6=97=B6=E6=8A=9B=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E7=B1=BB=E5=9E=8B=E9=94=99=E8=AF=AF=20(#1166?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nonebot/internal/adapter/message.py | 2 +- tests/test_adapters/test_template.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nonebot/internal/adapter/message.py b/nonebot/internal/adapter/message.py index d1fb981e..6abb1d48 100644 --- a/nonebot/internal/adapter/message.py +++ b/nonebot/internal/adapter/message.py @@ -186,7 +186,7 @@ class Message(List[TMS], abc.ABC): elif isinstance(other, Iterable): self.extend(other) else: - raise ValueError(f"Unsupported type: {type(other)}") # pragma: no cover + raise TypeError(f"Unsupported type {type(other)!r}") return self @overload diff --git a/tests/test_adapters/test_template.py b/tests/test_adapters/test_template.py index 50a87493..43f29171 100644 --- a/tests/test_adapters/test_template.py +++ b/tests/test_adapters/test_template.py @@ -11,11 +11,11 @@ def test_template_basis(): def test_template_message(): Message = make_fake_message() - template = Message.template("{a:custom}{b:text}{c:image}") + template = Message.template("{a:custom}{b:text}{c:image}/{d}") @template.add_format_spec def custom(input: str) -> str: - return input + "-custom!" + return f"{input}-custom!" try: template.add_format_spec(custom) @@ -24,12 +24,17 @@ def test_template_message(): else: raise AssertionError("Should raise ValueError") - format_args = {"a": "custom", "b": "text", "c": "https://example.com/test"} + format_args = { + "a": "custom", + "b": "text", + "c": "https://example.com/test", + "d": 114, + } formatted = template.format(**format_args) assert template.format_map(format_args) == formatted - assert formatted.extract_plain_text() == "custom-custom!text" - assert str(formatted) == "custom-custom!text[fake:image]" + assert formatted.extract_plain_text() == "custom-custom!text/114" + assert str(formatted) == "custom-custom!text[fake:image]/114" def test_rich_template_message():