mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-27 18:45:05 +08:00
18 lines
631 B
Python
18 lines
631 B
Python
import json
|
|
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")
|
|
)
|
|
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"}}]}}'
|
|
)
|
|
s1 = json.dumps("123", cls = DataclassEncoder)
|
|
assert s1 == '"123"' |