# Path: grazyna/plugins/quotes.py
# @register(cmd='{cmd}')
# def quotes(bot, ask=None):
#     replies = get_replies(bot)
#     reply = random.choice(replies)
#     bot.reply(reply)
# 
# def get_replies(bot):
#     """funny random quotes"""
#     replies = bot.temp.get('replies')
#     if replies is None:
#         pathname = bot.config['file']
#         with open(pathname) as f:
#             replies = f.read().splitlines()
#         bot.temp['replies'] = replies
#     return replies
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)


from grazyna.plugins.quotes import quotes, get_replies
from grazyna.test_mocks.sender import SayMessage
from unittest.mock import patch
from asynctest.mock import patch as async_patch
from io import StringIO
import pytest




@pytest.mark.asyncio
@async_patch('grazyna.plugins.quotes.get_replies')
def test_quotes(get_replies_mock, public_bot):
    get_replies_mock.return_value = ['foobar']
    yield from quotes(public_bot)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: foobar'),
    ]


@patch('grazyna.plugins.quotes.open', create=True)
def test_get_replies(open_mock, public_bot):
    public_bot.config['file'] = 'socek.txt'

# Path: grazyna/plugins/quotes.py
# @register(cmd='{cmd}')
# def quotes(bot, ask=None):
#     replies = get_replies(bot)
#     reply = random.choice(replies)
#     bot.reply(reply)
# 
# def get_replies(bot):
#     """funny random quotes"""
#     replies = bot.temp.get('replies')
#     if replies is None:
#         pathname = bot.config['file']
#         with open(pathname) as f:
#             replies = f.read().splitlines()
#         bot.temp['replies'] = replies
#     return replies
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)


# Path: grazyna/tests/plugins/test_quotes.py
from grazyna.plugins.quotes import quotes, get_replies
from grazyna.test_mocks.sender import SayMessage
from unittest.mock import patch
from asynctest.mock import patch as async_patch
from io import StringIO
import pytest





@pytest.mark.asyncio
@async_patch('grazyna.plugins.quotes.get_replies')
def test_quotes(get_replies_mock, public_bot):
    get_replies_mock.return_value = ['foobar']
    yield from quotes(public_bot)
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: foobar'),
    ]


@patch('grazyna.plugins.quotes.open', create=True)
def test_get_replies(open_mock, public_bot):
    public_bot.config['file'] = 'socek.txt'

    open_mock.return_value = StringIO(