generated from Dorukyum/pypi-package-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
109 lines (80 loc) · 3.1 KB
/
test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import discord
from pycord.multicog import Bot, subcommand
def run_test(func):
if __name__ == "__main__":
func()
return func
@run_test
def test_dependent():
bot = Bot()
class FirstCog(discord.Cog):
group = discord.SlashCommandGroup("group")
@group.command()
async def dummy(self, ctx):
await ctx.respond("I am a dummy command.")
class SecondCog(discord.Cog):
@subcommand("group")
@discord.slash_command()
async def test_command(self, ctx):
await ctx.respond("I am another dummy command.")
bot.add_cog(FirstCog())
bot.add_cog(SecondCog())
group = bot.pending_application_commands[0]
assert isinstance(group, discord.SlashCommandGroup)
test_command = group.subcommands[-1]
assert test_command.name == "test_command"
assert test_command.parent == group
bot.remove_cog("FirstCog")
assert not bot.pending_application_commands
@run_test
def test_independent():
bot = Bot()
class FirstCog(discord.Cog):
@subcommand("group", independent=True)
@discord.slash_command()
async def test_command(self, ctx):
await ctx.respond("Hello there.")
bot.add_cog(FirstCog())
group = bot.pending_application_commands[0]
assert isinstance(group, discord.SlashCommandGroup)
test_command = group.subcommands[0]
assert test_command.name == "test_command"
assert test_command.parent == group
bot.remove_cog("FirstCog")
group = bot.pending_application_commands[0]
assert isinstance(group, discord.SlashCommandGroup)
test_command = group.subcommands[0]
assert test_command.name == "test_command"
assert test_command.parent == group
@run_test
def test_subgroup():
bot = Bot()
def check_tree(parent, subgroup_name: str, command_name: str):
assert isinstance(parent, discord.SlashCommandGroup)
subgroup = parent.subcommands[-1]
assert isinstance(subgroup, discord.SlashCommandGroup)
assert subgroup.name == subgroup_name
command = subgroup.subcommands[-1]
assert command.name == command_name
assert command.parent == subgroup
class FirstCog(discord.Cog):
group = discord.SlashCommandGroup("group")
subgroup = group.create_subgroup("subgroup")
@subgroup.command()
async def dummy(self, ctx):
await ctx.respond("I am a dummy command.")
class SecondCog(discord.Cog):
@subcommand("group subgroup")
@discord.slash_command()
async def test_command(self, ctx):
await ctx.respond("I am another dummy command.")
@subcommand("another_group another_subgroup", independent=True)
@discord.slash_command()
async def test_command_2(self, ctx):
await ctx.respond("I am yet another dummy command.")
bot.add_cog(FirstCog())
bot.add_cog(SecondCog())
group = bot.pending_application_commands[0]
check_tree(group, "subgroup", "test_command")
another_group = bot.pending_application_commands[-1]
check_tree(another_group, "another_subgroup", "test_command_2")