diff --git a/tests/test_events.py b/tests/test_events.py index 26f8e5faa0..15cc467151 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -1,5 +1,4 @@ # SPDX-License-Identifier: MIT - from typing import Any import pytest @@ -8,9 +7,8 @@ from disnake import Event from disnake.ext import commands -# n.b. the specific choice of events used in this file is irrelevant - +# n.b. the specific choice of events used in this file is irrelevant @pytest.fixture def client(): return disnake.Client() @@ -32,7 +30,7 @@ def client_or_bot(request): # @Client.event -def test_client_event(client_or_bot: disnake.Client) -> None: +def test_event(client_or_bot: disnake.Client) -> None: assert not hasattr(client_or_bot, "on_message_edit") @client_or_bot.event @@ -42,93 +40,45 @@ async def on_message_edit(self, *args: Any) -> None: assert client_or_bot.on_message_edit is on_message_edit # type: ignore -# Client.add_listener / Client.remove_listener - - -@pytest.mark.parametrize("event", ["on_guild_remove", Event.guild_remove]) -def test_client_addremove_listener(client_or_bot: disnake.Client, event) -> None: - async def callback(self, *args: Any) -> None: - ... - - client_or_bot.add_listener(callback, event) - assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 - - client_or_bot.remove_listener(callback, event) - assert len(client_or_bot.extra_events["on_guild_remove"]) == 0 - - -def test_client_addremove_listener__implicit(client_or_bot: disnake.Client) -> None: - async def on_guild_remove(self, *args: Any) -> None: - ... - - client_or_bot.add_listener(on_guild_remove) - assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 - - client_or_bot.remove_listener(on_guild_remove) - assert len(client_or_bot.extra_events["on_guild_remove"]) == 0 - - -# @Client.listen - - -@pytest.mark.parametrize("event", ["on_guild_role_create", Event.guild_role_create]) -def test_client_listen(client_or_bot: disnake.Client, event) -> None: - @client_or_bot.listen(event) - async def callback(self, *args: Any) -> None: - ... - - assert len(client_or_bot.extra_events["on_guild_role_create"]) == 1 - - -def test_client_listen__implicit(client_or_bot: disnake.Client) -> None: - @client_or_bot.listen() - async def on_guild_role_create(self, *args: Any) -> None: - ... - - assert len(client_or_bot.extra_events["on_guild_role_create"]) == 1 - - -# Bot.wait_for +# Client.wait_for @pytest.mark.parametrize("event", ["thread_create", Event.thread_create]) -def test_wait_for(client_or_bot: commands.Bot, event) -> None: +def test_wait_for(client_or_bot: disnake.Client, event) -> None: coro = client_or_bot.wait_for(event) assert len(client_or_bot._listeners["thread_create"]) == 1 coro.close() # close coroutine to avoid warning -# Bot.add_listener / Bot.remove_listener +# Client.add_listener / Client.remove_listener @pytest.mark.parametrize("event", ["on_guild_remove", Event.guild_remove]) -def test_bot_addremove_listener(client_or_bot: commands.Bot, event) -> None: +def test_addremove_listener(client_or_bot: disnake.Client, event) -> None: async def callback(self, *args: Any) -> None: ... client_or_bot.add_listener(callback, event) assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 - client_or_bot.remove_listener(callback, event) assert len(client_or_bot.extra_events["on_guild_remove"]) == 0 -def test_bot_addremove_listener__implicit(client_or_bot: commands.Bot) -> None: +def test_addremove_listener__implicit(client_or_bot: disnake.Client) -> None: async def on_guild_remove(self, *args: Any) -> None: ... client_or_bot.add_listener(on_guild_remove) assert len(client_or_bot.extra_events["on_guild_remove"]) == 1 - client_or_bot.remove_listener(on_guild_remove) assert len(client_or_bot.extra_events["on_guild_remove"]) == 0 -# @Bot.listen +# @Client.listen @pytest.mark.parametrize("event", ["on_guild_role_create", Event.guild_role_create]) -def test_bot_listen(client_or_bot: commands.Bot, event) -> None: +def test_listen(client_or_bot: disnake.Client, event) -> None: @client_or_bot.listen(event) async def callback(self, *args: Any) -> None: ... @@ -136,7 +86,7 @@ async def callback(self, *args: Any) -> None: assert len(client_or_bot.extra_events["on_guild_role_create"]) == 1 -def test_bot_listen__implicit(client_or_bot: commands.Bot) -> None: +def test_listen__implicit(client_or_bot: disnake.Client) -> None: @client_or_bot.listen() async def on_guild_role_create(self, *args: Any) -> None: ... @@ -145,8 +95,6 @@ async def on_guild_role_create(self, *args: Any) -> None: # @commands.Cog.listener - - @pytest.mark.parametrize("event", ["on_automod_rule_update", Event.automod_rule_update]) def test_listener(bot: commands.Bot, event) -> None: class Cog(commands.Cog):