diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-19 15:44:33 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-19 15:44:33 +0200 |
| commit | b343381fea3eab26e334a1b3bba202d715f9ea2e (patch) | |
| tree | 792210018d1e11ac3b160edfe29cf878eb4e3f56 /tests/cogs/test_math_commands.py | |
| parent | chore: add pycord dependency, update main (diff) | |
| download | senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.tar.gz senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.zip | |
test: improve test assertions and edge cases
Diffstat (limited to 'tests/cogs/test_math_commands.py')
| -rw-r--r-- | tests/cogs/test_math_commands.py | 12 |
1 files changed, 6 insertions, 6 deletions
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): | |||
| 13 | @pytest.mark.asyncio | 13 | @pytest.mark.asyncio |
| 14 | async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, bot): | 14 | async def test_math_command_valid_expression(math_cog, mock_channel, mock_guild, bot): |
| 15 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 15 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 16 | 16 | ||
| 17 | mock_process = MagicMock() | 17 | mock_process = MagicMock() |
| 18 | mock_process.returncode = 0 | 18 | mock_process.returncode = 0 |
| 19 | mock_process.communicate = AsyncMock(return_value=(b"4", b"")) | 19 | mock_process.communicate = AsyncMock(return_value=(b"4", b"")) |
| 20 | 20 | ||
| 21 | with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process) as mock_subprocess: | 21 | with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process) as mock_subprocess: |
| 22 | with patch('cogs.math_commands.re.search', return_value=None): | 22 | with patch('cogs.math_commands.re.search', return_value=None): |
| 23 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 23 | 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, | |||
| 29 | @pytest.mark.asyncio | 29 | @pytest.mark.asyncio |
| 30 | async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guild, bot): | 30 | async def test_math_command_invalid_expression(math_cog, mock_channel, mock_guild, bot): |
| 31 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 31 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 32 | 32 | ||
| 33 | with patch('cogs.math_commands.re.search', return_value=MagicMock()): | 33 | with patch('cogs.math_commands.re.search', return_value=MagicMock()): |
| 34 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 34 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 35 | await math_cog.math.callback(math_cog, ctx, equation="eval(1)") | 35 | 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 | |||
| 41 | @pytest.mark.asyncio | 41 | @pytest.mark.asyncio |
| 42 | async def test_math_command_process_error(math_cog, mock_channel, mock_guild, bot): | 42 | async def test_math_command_process_error(math_cog, mock_channel, mock_guild, bot): |
| 43 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | 43 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) |
| 44 | 44 | ||
| 45 | mock_process = MagicMock() | 45 | mock_process = MagicMock() |
| 46 | mock_process.returncode = 1 | 46 | mock_process.returncode = 1 |
| 47 | mock_process.communicate = AsyncMock(return_value=(b"", b"Error: invalid expression")) | 47 | mock_process.communicate = AsyncMock(return_value=(b"", b"Error: invalid expression")) |
| 48 | 48 | ||
| 49 | with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process): | 49 | with patch('cogs.math_commands.asyncio.create_subprocess_exec', return_value=mock_process): |
| 50 | with patch('cogs.math_commands.re.search', return_value=None): | 50 | with patch('cogs.math_commands.re.search', return_value=None): |
| 51 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | 51 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: |
| 52 | await math_cog.math.callback(math_cog, ctx, equation="2++") | 52 | await math_cog.math.callback(math_cog, ctx, equation="2++") |
| 53 | mock_respond.assert_called_once() | 53 | mock_respond.assert_called_once() |
| 54 | args = mock_respond.call_args | 54 | args = mock_respond.call_args |
| 55 | assert "error" in str(args).lower() or "Error" in str(args) \ No newline at end of file | 55 | assert "error" in str(args).lower() or "Error" in str(args) |
