From 1d6a333b49fc0319f4fad3b686863b10bb2077f2 Mon Sep 17 00:00:00 2001 From: yanyongyu <42488585+yanyongyu@users.noreply.github.com> Date: Thu, 17 Feb 2022 15:35:39 +0800 Subject: [PATCH] :white_check_mark: update dataclass encoder tests --- tests/test_utils.py | 14 +++++++------- tests/utils.py | 10 ++-------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 66f8b1ee..282b2ab7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -6,14 +6,14 @@ from utils import make_fake_message def test_dataclass_encoder(): from nonebot.utils import DataclassEncoder - MessageSegment = make_fake_message().get_segment_class() - ms = MessageSegment.node_custom( - "1234", "testtest", "test" + MessageSegment.image("url") - ) + simple = json.dumps("123", cls=DataclassEncoder) + assert simple == '"123"' + + Message = make_fake_message() + MessageSegment = Message.get_segment_class() + ms = MessageSegment.nested(Message(MessageSegment.text("text"))) s = json.dumps(ms, cls=DataclassEncoder) assert ( s - == '{"type": "node", "data": {"user_id": "1234", "nickname": "testtest", "content": [{"type": "text", "data": {"text": "test"}}, {"type": "image", "data": {"url": "url"}}]}}' + == '{"type": "node", "data": {"content": [{"type": "text", "data": {"text": "text"}}]}}' ) - s1 = json.dumps("123", cls=DataclassEncoder) - assert s1 == '"123"' diff --git a/tests/utils.py b/tests/utils.py index e33ce5be..31939be7 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -33,14 +33,8 @@ def make_fake_message(): return FakeMessageSegment("image", {"url": url}) @staticmethod - def node_custom( - user_id: str, - nickname: str, - content: Union["FakeMessage", "FakeMessageSegment", str], - ): - return FakeMessageSegment( - "node", {"user_id": user_id, "nickname": nickname, "content": content} - ) + def nested(content: "FakeMessage"): + return FakeMessageSegment("node", {"content": content}) def is_text(self) -> bool: return self.type == "text"