mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-01-19 01:18:19 +08:00
✅ add more tests
This commit is contained in:
parent
2ec5917709
commit
f3cc93c699
@ -1,3 +1,5 @@
|
||||
from pydantic import ValidationError, parse_obj_as
|
||||
|
||||
from utils import make_fake_message
|
||||
|
||||
|
||||
@ -22,6 +24,21 @@ def test_segment_add():
|
||||
)
|
||||
|
||||
|
||||
def test_segment_validate():
|
||||
Message = make_fake_message()
|
||||
MessageSegment = Message.get_segment_class()
|
||||
|
||||
assert parse_obj_as(
|
||||
MessageSegment, {"type": "text", "data": {"text": "text"}}
|
||||
) == MessageSegment.text("text")
|
||||
|
||||
try:
|
||||
parse_obj_as(MessageSegment, "some str")
|
||||
assert False
|
||||
except ValidationError:
|
||||
assert True
|
||||
|
||||
|
||||
def test_message_add():
|
||||
Message = make_fake_message()
|
||||
MessageSegment = Message.get_segment_class()
|
||||
@ -78,3 +95,24 @@ def test_message_getitem():
|
||||
assert message.get("image", 1) == Message([message["image", 0]])
|
||||
|
||||
assert message.count("image") == 2
|
||||
|
||||
|
||||
def test_message_validate():
|
||||
Message = make_fake_message()
|
||||
MessageSegment = Message.get_segment_class()
|
||||
|
||||
assert parse_obj_as(Message, "text") == Message([MessageSegment.text("text")])
|
||||
|
||||
assert parse_obj_as(Message, {"type": "text", "data": {"text": "text"}}) == Message(
|
||||
[MessageSegment.text("text")]
|
||||
)
|
||||
|
||||
assert parse_obj_as(
|
||||
Message, [{"type": "text", "data": {"text": "text"}}]
|
||||
) == Message([MessageSegment.text("text")])
|
||||
|
||||
try:
|
||||
parse_obj_as(Message, object())
|
||||
assert False
|
||||
except ValidationError:
|
||||
assert True
|
||||
|
Loading…
Reference in New Issue
Block a user