From b343381fea3eab26e334a1b3bba202d715f9ea2e Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 19 Apr 2026 15:44:33 +0200 Subject: test: improve test assertions and edge cases --- tests/cogs/test_math_commands.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests/cogs/test_math_commands.py') diff --git a/tests/cogs/test_math_commands.py b/tests/cogs/test_math_commands.py index 0acac4a..5c78027 100644 --- a/tests/cogs/test_math_commands.py +++ b/tests/cogs/test_math_commands.py @@ -13,11 +13,11 @@ def math_cog(bot): @pytest.mark.asyncio async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, bot): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + mock_process = MagicMock() mock_process.returncode = 0 mock_process.communicate = AsyncMock(return_value=(b"4", b"")) - + with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process) as mock_subprocess: with patch('cogs.math_commands.re.search', return_value=None): with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: @@ -29,7 +29,7 @@ async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, @pytest.mark.asyncio async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guild, bot): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + with patch('cogs.math_commands.re.search', return_value=MagicMock()): with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await math_cog.math.callback(math_cog, ctx, equation="eval(1)") @@ -41,15 +41,15 @@ async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guil @pytest.mark.asyncio async def test_math_command_process_error(math_cog, mock_channel, mock_guild, bot): ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) - + mock_process = MagicMock() mock_process.returncode = 1 mock_process.communicate = AsyncMock(return_value=(b"", b"Error: invalid expression")) - + with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process): with patch('cogs.math_commands.re.search', return_value=None): with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: await math_cog.math.callback(math_cog, ctx, equation="2++") mock_respond.assert_called_once() args = mock_respond.call_args - assert "error" in str(args).lower() or "Error" in str(args) \ No newline at end of file + assert "error" in str(args).lower() or "Error" in str(args) -- cgit v1.2.3