2022-02-17 15:06:26 +08:00
|
|
|
import json
|
2022-02-17 15:12:29 +08:00
|
|
|
|
2022-02-17 15:06:26 +08:00
|
|
|
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")
|
|
|
|
)
|
2022-02-17 15:12:29 +08:00
|
|
|
s = json.dumps(ms, cls=DataclassEncoder)
|
2022-02-17 15:06:26 +08:00
|
|
|
assert (
|
|
|
|
s
|
|
|
|
== '{"type": "node", "data": {"user_id": "1234", "nickname": "testtest", "content": [{"type": "text", "data": {"text": "test"}}, {"type": "image", "data": {"url": "url"}}]}}'
|
|
|
|
)
|
2022-02-17 15:12:29 +08:00
|
|
|
s1 = json.dumps("123", cls=DataclassEncoder)
|
|
|
|
assert s1 == '"123"'
|