-
-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathtest_subclassing.py
72 lines (57 loc) · 2.49 KB
/
test_subclassing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# -*- coding: utf-8 -*-
"""
jishaku subclassing functionality test
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: (c) 2021 Devon (scarletcafe) R
:license: MIT, see LICENSE for more details.
"""
import discord
import pytest
import pytest_asyncio
from discord.ext import commands
from tests import utils
@pytest_asyncio.fixture(
scope='function',
params=[
# Subclass 1 (Feature)
("tests.subclassed_module_1", "Magnet1", "overridden with a third party feature", commands.Bot, {}),
("tests.subclassed_module_1", "Magnet1", "overridden with a third party feature", commands.Bot, {"shard_id": 0, "shard_count": 2}),
("tests.subclassed_module_1", "Magnet1", "overridden with a third party feature", commands.AutoShardedBot, {}),
# Subclass 2 (direct)
("tests.subclassed_module_2", "Magnet2", "overridden directly", commands.Bot, {}),
("tests.subclassed_module_2", "Magnet2", "overridden directly", commands.Bot, {"shard_id": 0, "shard_count": 2}),
("tests.subclassed_module_2", "Magnet2", "overridden directly", commands.AutoShardedBot, {}),
# Test that the original still works after the load test
("jishaku", "Jishaku", "Module was loaded", commands.Bot, {}),
("jishaku", "Jishaku", "Module was loaded", commands.Bot, {"shard_id": 0, "shard_count": 2}),
("jishaku", "Jishaku", "Module was loaded", commands.AutoShardedBot, {}),
],
ids=[
"Feature-based subclass (Bot, unsharded)",
"Feature-based subclass (Bot, sharded)",
"Feature-based subclass (AutoShardedBot)",
"direct subclass (Bot, unsharded)",
"direct subclass (Bot, sharded)",
"direct subclass (AutoShardedBot)",
"native (Bot, unsharded)",
"native (Bot, sharded)",
"native (AutoShardedBot)"
]
)
async def bot(request):
b = request.param[3]('?', intents=discord.Intents.all(), **request.param[4])
await discord.utils.maybe_coroutine(b.load_extension, request.param[0])
b.test_cog = request.param[1]
b.test_predicate = request.param[2]
yield b
await discord.utils.maybe_coroutine(b.unload_extension, request.param[0])
@pytest.mark.asyncio
async def test_commands(bot):
cog = bot.get_cog(bot.test_cog)
assert cog is not None
# test 'jsk'
with utils.mock_ctx() as ctx:
await bot.get_command('jsk').callback(cog, ctx)
ctx.send.assert_called_once()
text = ctx.send.call_args[0][0]
assert bot.test_predicate in text