Skip to content

Commit

Permalink
unfuck tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Snipy7374 committed Jul 17, 2023
1 parent a2dfd73 commit 01e340f
Showing 1 changed file with 10 additions and 62 deletions.
72 changes: 10 additions & 62 deletions tests/test_events.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# SPDX-License-Identifier: MIT

from typing import Any

import pytest
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -42,101 +40,53 @@ 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:
...

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:
...
Expand All @@ -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):
Expand Down

0 comments on commit 01e340f

Please sign in to comment.