updated lib_Cog test

This commit is contained in:
bacon
2024-03-17 21:34:03 +03:00
parent cb72e48f09
commit 4e535f6580
4 changed files with 25 additions and 22 deletions

View File

View File

@@ -1,29 +1,28 @@
import pytest
from disnake.ext.commands import Bot
from disnake.ext.commands.common_bot_base import CommonBotBase
from mock import mock
from ..lib.CogsPrep import cog_list, work_with_cogs
from lib.CogsPrep import cog_list, work_with_cogs
@mock.patch('discord_bot.lib.CogsPrep.cog_list')
def test_cog_list(mock_cog_list):
with mock.patch('discord_bot.lib.CogsPrep.listdir') as MockClass:
def test_cog_list():
with mock.patch('lib.CogsPrep.listdir') as MockClass:
MockClass.return_value = ['cog1.py', 'cog2.py']
result = cog_list()
assert result == ['cog1', 'cog2']
# @pytest.mark.skip(reason=None)
@pytest.mark.asyncio
@pytest.mark.parametrize("cog", ["cog1.py", "cog2"])
@pytest.mark.parametrize("what_do", ['load', 'unload', 'reload', 'disable', 'enable'])
async def test_work_with_cogs(what_do, cog):
mock_logger = mock.AsyncMock()
with (mock.patch('discord_bot.lib.CogsPrep.logger.info') as mocked_logger):
mock_bot = mock.AsyncMock()
await mock_bot(spec=Bot)
with mock.patch('discord_bot.lib.CogsPrep.rename') as mock_rename:
mock_rename.return_value = True
result = await work_with_cogs(what_do, mock_bot, cog)
assert len(mocked_logger.call_args_list) == 1, f"Not listed what_do {what_do}"
with (mock.patch('lib.CogsPrep.rename') as mock_rename):
mock_rename.return_value = None
mock_bot = mock.MagicMock(spec=CommonBotBase)
result = await work_with_cogs(what_do, mock_bot, cog)
if what_do in ['load', 'enable']:
assert mock_bot.load_extension.called
elif what_do in ['unload', 'disable']:
assert mock_bot.unload_extension.called
elif what_do == 'reload':
assert mock_bot.reload_extension.called