import pytest from models.message import MessageSegment from models.objects import GroupInfo, StrangerInfo class TestMessageSegment: def test_text_segment(self): seg = MessageSegment.text("Hello") assert seg.type == "text" assert seg.data["text"] == "Hello" assert str(seg) == "Hello" def test_at_segment(self): seg = MessageSegment.at(123456) assert seg.type == "at" assert seg.data["qq"] == "123456" assert str(seg) == "[CQ:at,qq=123456]" def test_image_segment(self): seg = MessageSegment.image("http://example.com/img.jpg", cache=False, proxy=False) assert seg.type == "image" assert seg.data["file"] == "http://example.com/img.jpg" assert str(seg) == "[CQ:image,file=http://example.com/img.jpg,cache=0,proxy=0]" def test_face_segment(self): seg = MessageSegment.face(123) assert seg.type == "face" assert seg.data["id"] == "123" assert str(seg) == "[CQ:face,id=123]" def test_reply_segment(self): seg = MessageSegment.reply(1001) assert seg.type == "reply" assert seg.data["id"] == "1001" assert str(seg) == "[CQ:reply,id=1001]" def test_add_segments(self): seg1 = MessageSegment.text("Hello ") seg2 = MessageSegment.at(123) combined = seg1 + seg2 assert isinstance(combined, list) assert len(combined) == 2 assert combined[0] == seg1 assert combined[1] == seg2 def test_add_segment_and_string(self): seg = MessageSegment.at(123) combined = seg + " Hello" assert isinstance(combined, list) assert len(combined) == 2 assert combined[0] == seg assert combined[1].type == "text" assert combined[1].data["text"] == " Hello" class TestObjects: def test_group_info(self): data = { "group_id": 123456, "group_name": "Test Group", "member_count": 10, "max_member_count": 100 } group = GroupInfo(**data) assert group.group_id == 123456 assert group.group_name == "Test Group" def test_stranger_info(self): data = { "user_id": 111111, "nickname": "Stranger", "sex": "male", "age": 18 } user = StrangerInfo(**data) assert user.user_id == 111111 assert user.nickname == "Stranger"