mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-28 04:56:57 +08:00
✅ update dataclass encoder tests
This commit is contained in:
parent
9c0e05c615
commit
1d6a333b49
@ -6,14 +6,14 @@ from utils import make_fake_message
|
|||||||
def test_dataclass_encoder():
|
def test_dataclass_encoder():
|
||||||
from nonebot.utils import DataclassEncoder
|
from nonebot.utils import DataclassEncoder
|
||||||
|
|
||||||
MessageSegment = make_fake_message().get_segment_class()
|
simple = json.dumps("123", cls=DataclassEncoder)
|
||||||
ms = MessageSegment.node_custom(
|
assert simple == '"123"'
|
||||||
"1234", "testtest", "test" + MessageSegment.image("url")
|
|
||||||
)
|
Message = make_fake_message()
|
||||||
|
MessageSegment = Message.get_segment_class()
|
||||||
|
ms = MessageSegment.nested(Message(MessageSegment.text("text")))
|
||||||
s = json.dumps(ms, cls=DataclassEncoder)
|
s = json.dumps(ms, cls=DataclassEncoder)
|
||||||
assert (
|
assert (
|
||||||
s
|
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"'
|
|
||||||
|
@ -33,14 +33,8 @@ def make_fake_message():
|
|||||||
return FakeMessageSegment("image", {"url": url})
|
return FakeMessageSegment("image", {"url": url})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def node_custom(
|
def nested(content: "FakeMessage"):
|
||||||
user_id: str,
|
return FakeMessageSegment("node", {"content": content})
|
||||||
nickname: str,
|
|
||||||
content: Union["FakeMessage", "FakeMessageSegment", str],
|
|
||||||
):
|
|
||||||
return FakeMessageSegment(
|
|
||||||
"node", {"user_id": user_id, "nickname": nickname, "content": content}
|
|
||||||
)
|
|
||||||
|
|
||||||
def is_text(self) -> bool:
|
def is_text(self) -> bool:
|
||||||
return self.type == "text"
|
return self.type == "text"
|
||||||
|
Loading…
Reference in New Issue
Block a user