diff options
author | 2020-03-09 13:10:21 -0700 | |
---|---|---|
committer | 2020-03-09 13:53:48 -0700 | |
commit | d31f7e3f4a4876d51119d5875afa9221b14b285e (patch) | |
tree | 64d916a1b8b93268e93fd98f73ebcd444342da40 /tests | |
parent | Cog tests: create boilerplate for command name tests (diff) |
Cog tests: add a function to get all commands
For tests, ideally creating instances of cogs should be avoided to avoid
extra code execution. This function was copied over from discord.py
because their function is not a static method, though it still works as
one. It was probably just a design decision on their part to not make it
static.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bot/cogs/test_cogs.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/bot/cogs/test_cogs.py b/tests/bot/cogs/test_cogs.py index 6f5d07030..b128ca123 100644 --- a/tests/bot/cogs/test_cogs.py +++ b/tests/bot/cogs/test_cogs.py @@ -1,7 +1,19 @@ """Test suite for general tests which apply to all cogs.""" +import typing as t import unittest +from discord.ext import commands + class CommandNameTests(unittest.TestCase): """Tests for shadowing command names and aliases.""" + + @staticmethod + def walk_commands(cog: commands.Cog) -> t.Iterator[commands.Command]: + """An iterator that recursively walks through `cog`'s commands and subcommands.""" + for command in cog.__cog_commands__: + if command.parent is None: + yield command + if isinstance(command, commands.GroupMixin): + yield from command.walk_commands() |