# Path: tests/conftest.py
# def wait_for_message(chats=None, msg_types=None, except_self=True, timeout=30):
#     """
#     等待一条指定的消息，并返回这条消息
# 
#     :param chats: 所需等待消息所在的聊天会话
#     :param msg_types: 所需等待的消息类型
#     :param except_self: 是否排除自己发送的消息
#     :param timeout: 等待的超时秒数，若为 None 则一直等待，直到收到所需的消息
#     :return: 若在超时内等到了消息，则返回此消息，否则抛出 `queue.Empty` 异常
#     """
# 
#     received = Queue()
# 
#     @_bot.register(chats=chats, msg_types=msg_types, except_self=except_self)
#     def _func(msg):
#         received.put(msg)
# 
#     _config = _bot.registered.get_config_by_func(_func)
# 
#     ret = received.get(timeout=timeout)
# 
#     _bot.registered.remove(_config)
# 
#     return ret


from datetime import datetime
from tests.conftest import wait_for_message
from wxpy import *



def sent_message(sent_msg, msg_type, receiver):
    assert isinstance(sent_msg, SentMessage)
    assert sent_msg.type == msg_type
    assert sent_msg.receiver == receiver
    assert sent_msg.bot == receiver.bot
    assert sent_msg.sender == receiver.bot.self
    assert isinstance(sent_msg.receive_time, datetime)
    assert isinstance(sent_msg.create_time, datetime)
    assert sent_msg.create_time < sent_msg.receive_time


class TestMessage:
    def test_text_message(self, group, friend):
        sent_message(group.send('text'), TEXT, group)
        msg = wait_for_message(group, TEXT)
        assert isinstance(msg, Message)
        assert msg.type == TEXT
        assert msg.text == 'Hello!'
        assert not msg.is_at
        assert msg.chat == group
        assert msg.sender == group
        assert msg.receiver == group.self
        assert msg.member == friend
        assert 0 < msg.latency < 30

        group.send('at')

# Path: tests/conftest.py
# def wait_for_message(chats=None, msg_types=None, except_self=True, timeout=30):
#     """
#     等待一条指定的消息，并返回这条消息
# 
#     :param chats: 所需等待消息所在的聊天会话
#     :param msg_types: 所需等待的消息类型
#     :param except_self: 是否排除自己发送的消息
#     :param timeout: 等待的超时秒数，若为 None 则一直等待，直到收到所需的消息
#     :return: 若在超时内等到了消息，则返回此消息，否则抛出 `queue.Empty` 异常
#     """
# 
#     received = Queue()
# 
#     @_bot.register(chats=chats, msg_types=msg_types, except_self=except_self)
#     def _func(msg):
#         received.put(msg)
# 
#     _config = _bot.registered.get_config_by_func(_func)
# 
#     ret = received.get(timeout=timeout)
# 
#     _bot.registered.remove(_config)
# 
#     return ret


# Path: tests/api/messages/test_message.py
from datetime import datetime
from tests.conftest import wait_for_message
from wxpy import *




def sent_message(sent_msg, msg_type, receiver):
    assert isinstance(sent_msg, SentMessage)
    assert sent_msg.type == msg_type
    assert sent_msg.receiver == receiver
    assert sent_msg.bot == receiver.bot
    assert sent_msg.sender == receiver.bot.self
    assert isinstance(sent_msg.receive_time, datetime)
    assert isinstance(sent_msg.create_time, datetime)
    assert sent_msg.create_time < sent_msg.receive_time


class TestMessage:
    def test_text_message(self, group, friend):
        sent_message(group.send('text'), TEXT, group)
        msg = wait_for_message(group, TEXT)
        assert isinstance(msg, Message)
        assert msg.type == TEXT
        assert msg.text == 'Hello!'
        assert not msg.is_at
        assert msg.chat == group
        assert msg.sender == group
        assert msg.receiver == group.self
        assert msg.member == friend
        assert 0 < msg.latency < 30

        group.send('at')

        msg = wait_for_message(group, TEXT)