# Path: grazyna/plugins/admin.py
# def reload(bot, module):
# def load_plugin(bot, module, name):
# def remove_plugin(bot, name):
# def reload_config(bot, reload_plugins='yes'):
# def kick(bot, who, chan=None, why=''):
# def join(bot, chan):
# def quit_bot(bot):
# def say(bot, msg, nick=None, chan: is_chan=None):
# def op(bot, nick=None, chan: is_chan=None):
# def part(bot, chan: is_chan=None, why=None):
# def rocket(bot, nick, n: range_int(0, 10)=3, chan: is_chan=None):
# 
# Path: grazyna/irc/models.py
# class WhoisData(object):
#     __slots__ = ('idle', 'account', 'ircname', 'host',
#                  'channels', 'realname', 'server', 'nick')
# 
#     def __init__(self):
#         self.channels = []
#         self.idle = 0
#         self.nick = None
#         self.account = None
#         self.ircname = None
#         self.host = None
#         self.realname = None
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# class Message(list):
# 
#     def __init__(self, *args):
#         arg, *args = args
#         super().__init__([arg.upper()] + args)


import asyncio
import pytest
from grazyna.plugins import admin as admin_plugins
from grazyna.irc.models import WhoisData
from grazyna.test_mocks.sender import SayMessage, Message
from asynctest.mock import patch as async_patch, Mock as AsyncMock
from io import StringIO
    importer = public_bot.protocol.importer
    importer.plugins = {
        'ping': None,
        'old_ping': None,
    }

    yield from admin_plugins.reload_config(public_bot)

    importer.remove.assert_called_once_with('old_ping')
    importer.load.assert_called_once_with('new_ping', 'grazyna.plugins.ping')
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]


@pytest.mark.asyncio
@async_patch('grazyna.plugins.admin.open', create=True)
@async_patch('grazyna.plugins.admin.argv')
def test_admin_reload_config_without_plugins(mock_argv, mock_open, public_bot):
    mock_open.return_value = StringIO('''
[plugins]
ping = grazyna.plugins.ping
new_ping = grazyna.plugins.ping
    ''')
    yield from admin_plugins.reload_config(public_bot, 'no')

    importer = public_bot.protocol.importer
    assert importer.load.not_called
    assert importer.remove.not_called
    assert public_bot.protocol.messages == [

# Path: grazyna/plugins/admin.py
# def reload(bot, module):
# def load_plugin(bot, module, name):
# def remove_plugin(bot, name):
# def reload_config(bot, reload_plugins='yes'):
# def kick(bot, who, chan=None, why=''):
# def join(bot, chan):
# def quit_bot(bot):
# def say(bot, msg, nick=None, chan: is_chan=None):
# def op(bot, nick=None, chan: is_chan=None):
# def part(bot, chan: is_chan=None, why=None):
# def rocket(bot, nick, n: range_int(0, 10)=3, chan: is_chan=None):
# 
# Path: grazyna/irc/models.py
# class WhoisData(object):
#     __slots__ = ('idle', 'account', 'ircname', 'host',
#                  'channels', 'realname', 'server', 'nick')
# 
#     def __init__(self):
#         self.channels = []
#         self.idle = 0
#         self.nick = None
#         self.account = None
#         self.ircname = None
#         self.host = None
#         self.realname = None
# 
# Path: grazyna/test_mocks/sender.py
# class SayMessage(Message):
# 
#     def __init__(self, to, msg):
#         super().__init__('PRIVMSG', to, ':' + msg)
# 
# class Message(list):
# 
#     def __init__(self, *args):
#         arg, *args = args
#         super().__init__([arg.upper()] + args)


# Path: grazyna/tests/plugins/test_admin.py
import asyncio
import pytest
from grazyna.plugins import admin as admin_plugins
from grazyna.irc.models import WhoisData
from grazyna.test_mocks.sender import SayMessage, Message
from asynctest.mock import patch as async_patch, Mock as AsyncMock
from io import StringIO

    importer = public_bot.protocol.importer
    importer.plugins = {
        'ping': None,
        'old_ping': None,
    }

    yield from admin_plugins.reload_config(public_bot)

    importer.remove.assert_called_once_with('old_ping')
    importer.load.assert_called_once_with('new_ping', 'grazyna.plugins.ping')
    assert public_bot.protocol.messages == [
        SayMessage('#czarnobyl', 'socek: Done!'),
    ]


@pytest.mark.asyncio
@async_patch('grazyna.plugins.admin.open', create=True)
@async_patch('grazyna.plugins.admin.argv')
def test_admin_reload_config_without_plugins(mock_argv, mock_open, public_bot):
    mock_open.return_value = StringIO('''
[plugins]
ping = grazyna.plugins.ping
new_ping = grazyna.plugins.ping
    ''')
    yield from admin_plugins.reload_config(public_bot, 'no')

    importer = public_bot.protocol.importer
    assert importer.load.not_called
    assert importer.remove.not_called
    assert public_bot.protocol.messages == [

        SayMessage('#czarnobyl', 'socek: Done!'),