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
|
2023-02-22 23:32:48 +08:00
|
|
|
from nonebot.utils import DataclassEncoder
|
2022-02-17 15:06:26 +08:00
|
|
|
|
|
|
|
|
|
|
|
def test_dataclass_encoder():
|
2022-02-17 15:35:39 +08:00
|
|
|
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")))
|
2022-02-17 15:12:29 +08:00
|
|
|
s = json.dumps(ms, cls=DataclassEncoder)
|
2022-02-17 15:06:26 +08:00
|
|
|
assert (
|
|
|
|
s
|
2022-02-17 15:35:39 +08:00
|
|
|
== '{"type": "node", "data": {"content": [{"type": "text", "data": {"text": "text"}}]}}'
|
2022-02-17 15:06:26 +08:00
|
|
|
)
|