46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
import tracemalloc
|
|
|
|
tracemalloc.start()
|
|
|
|
import pytest
|
|
from disnake.ext.commands.common_bot_base import CommonBotBase
|
|
from mock import mock
|
|
|
|
import os
|
|
import sys
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
|
|
|
|
from bot.lib.CogsPrep import cog_list, work_with_cogs
|
|
|
|
|
|
def test_cog_list():
|
|
with mock.patch('bot.lib.CogsPrep.listdir') as MockClass:
|
|
MockClass.return_value = ['cog1.py', 'cog2.py']
|
|
result = cog_list()
|
|
assert result == ['cog1', 'cog2']
|
|
|
|
|
|
@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):
|
|
with (mock.patch('bot.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
|
|
|
|
|
|
snapshot = tracemalloc.take_snapshot()
|
|
top_stats = snapshot.statistics('lineno')
|
|
|
|
print("[ Top 10 ]")
|
|
for stat in top_stats[:10]:
|
|
print(stat)
|