From 0a1c4475218669a172d68ef3eaf35bc00daeaa4f Mon Sep 17 00:00:00 2001 From: MSec Date: Tue, 5 Nov 2024 01:56:10 +0000 Subject: [PATCH] fix test cases for ascii_cog.py --- tests/cogs/test_ascii_cog.py | 160 +++++++++++++++++++++++++++++++++++ twitchrce/cogs/ascii_cog.py | 15 +++- 2 files changed, 172 insertions(+), 3 deletions(-) create mode 100644 tests/cogs/test_ascii_cog.py diff --git a/tests/cogs/test_ascii_cog.py b/tests/cogs/test_ascii_cog.py new file mode 100644 index 0000000..9fa0bb5 --- /dev/null +++ b/tests/cogs/test_ascii_cog.py @@ -0,0 +1,160 @@ +import pytest + +from twitchrce import custom_bot +from twitchrce.cogs.ascii_cog import AsciiCog + + +@pytest.fixture +def mock_bot(mocker): + mock_bot: custom_bot.CustomBot = mocker.Mock() + mock_bot._checks = [] + return mock_bot + + +@pytest.fixture +def mock_ctx(mocker, mock_bot): + mock_ctx = mocker.Mock() + mock_ctx.bot = mock_bot + mock_ctx.author = mocker.Mock() + mock_ctx.author.name = "author_name" + mock_ctx.channel = mocker.Mock() + mock_ctx.channel.name = "channel_name" + mock_ctx.channel.channel.name = "channel_name" + mock_ctx.channel.__messageable_channel__ = True + mock_ctx.send = mocker.AsyncMock() + return mock_ctx + + +@pytest.mark.asyncio +async def test_kill_everyone(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.kill_everyone(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_mario(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.mario(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_spider(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.spider(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_spider_swarm(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.spider_swarm(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_deez(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.deez(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_secplus(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.secplus(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_letsgo(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.letsgo(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_capybara(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.capybara(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_weeb1(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.weeb1(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_weeb2(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.weeb2(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_shark(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.shark(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_gotem(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.gotem(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_fuchat(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.fuchat(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_creeper(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.creeper(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") + + +@pytest.mark.asyncio +async def test_timehascome(mock_bot, mock_ctx): + ascii_cog = AsciiCog(bot=mock_bot) + try: + await ascii_cog.timehascome(mock_ctx) + except Exception as error: + pytest.fail(f"Raised an exception: {error}") diff --git a/twitchrce/cogs/ascii_cog.py b/twitchrce/cogs/ascii_cog.py index 16b27f4..46f3e70 100644 --- a/twitchrce/cogs/ascii_cog.py +++ b/twitchrce/cogs/ascii_cog.py @@ -1,8 +1,17 @@ +import logging + import twitchio from twitchio.ext import commands from twitchrce import custom_bot +logging.basicConfig( + level=logging.INFO, + format="%(asctime)s | %(levelname)-8s | %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", +) +logger = logging.getLogger(__name__) + class AsciiCog(commands.Cog): @@ -10,10 +19,10 @@ def __init__(self, bot: custom_bot.CustomBot): self.bot = bot @commands.Cog.event() - async def event_message(self, message: twitchio.Message): + async def event_message(self, message: twitchio.Message): # pragma: no cover if message.echo: return - # print('RCECog: ', message.author.name, message.content) + logger.info('[RCECog]: ', message.author.name, message.content) @commands.command() async def kill_everyone(self, ctx: commands.Context): @@ -49,7 +58,7 @@ async def spider(self, ctx: commands.Context): ) @commands.command() - async def spiderswarm(self, ctx: commands.Context): + async def spider_swarm(self, ctx: commands.Context): await ctx.send( f"⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ " f"╱╲⎝⧹༼◕ ͜ﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞﱞo.◕ ༽⧸⎠╱╲"