30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
import pytest
|
|
from disnake.ext.commands import Bot
|
|
from mock import mock
|
|
|
|
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:
|
|
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}"
|