diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/cogs/test_plot.py | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/tests/cogs/test_plot.py b/tests/cogs/test_plot.py deleted file mode 100644 index e38a2c7..0000000 --- a/tests/cogs/test_plot.py +++ /dev/null | |||
| @@ -1,85 +0,0 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock | ||
| 3 | import os | ||
| 4 | from tests.conftest import MockApplicationContext | ||
| 5 | |||
| 6 | |||
| 7 | def test_parse_expression(): | ||
| 8 | from cogs.plot import parse_expression | ||
| 9 | |||
| 10 | assert parse_expression("x^2") == "x**2" | ||
| 11 | assert parse_expression("x!") == "factorial(x)" | ||
| 12 | assert parse_expression("2x") == "2*x" | ||
| 13 | assert parse_expression("x2") == "x*2" | ||
| 14 | assert parse_expression("sin(x)") == "sin(x)" | ||
| 15 | |||
| 16 | |||
| 17 | def test_is_implicit(): | ||
| 18 | from cogs.plot import is_implicit | ||
| 19 | |||
| 20 | assert is_implicit("x^2 + y^2 = 1") == True | ||
| 21 | assert is_implicit("x^2 = y") == True | ||
| 22 | assert is_implicit("x^2 + 1") == False | ||
| 23 | |||
| 24 | |||
| 25 | def test_parse_implicit(): | ||
| 26 | from cogs.plot import parse_implicit | ||
| 27 | |||
| 28 | lhs, rhs = parse_implicit("x^2 + y = 2") | ||
| 29 | assert "x**2" in lhs | ||
| 30 | assert "+ y" in lhs or "+y" in lhs | ||
| 31 | assert rhs == "2" | ||
| 32 | |||
| 33 | |||
| 34 | @pytest.fixture | ||
| 35 | def plot_cog(bot): | ||
| 36 | from cogs.plot import Plot | ||
| 37 | cog = Plot(bot) | ||
| 38 | return cog | ||
| 39 | |||
| 40 | |||
| 41 | @pytest.mark.asyncio | ||
| 42 | async def test_plot_command_not_available(plot_cog, mock_channel, mock_guild, bot): | ||
| 43 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 44 | |||
| 45 | with patch('cogs.plot._ensure_plot', return_value=False): | ||
| 46 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 47 | await plot_cog.plot.callback(plot_cog, ctx, funkcja="x^2") | ||
| 48 | mock_respond.assert_called_once() | ||
| 49 | args = mock_respond.call_args | ||
| 50 | assert "matplotlib" in str(args).lower() or "nie jest dostępne" in str(args) | ||
| 51 | |||
| 52 | |||
| 53 | @pytest.mark.asyncio | ||
| 54 | async def test_plot_command_success(plot_cog, mock_channel, mock_guild, bot): | ||
| 55 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 56 | |||
| 57 | with patch('cogs.plot._ensure_plot', return_value=True): | ||
| 58 | with patch('cogs.plot._plt_module') as mock_plt: | ||
| 59 | with patch('cogs.utils.temp.get_temp_dir', return_value="/tmp"): | ||
| 60 | with patch('os.path.exists', return_value=True): | ||
| 61 | with patch('os.unlink'): | ||
| 62 | with patch.object(ctx, 'followup', send=AsyncMock()) as mock_followup: | ||
| 63 | mock_fig = MagicMock() | ||
| 64 | mock_plt.subplots.return_value = (mock_fig, MagicMock()) | ||
| 65 | |||
| 66 | await plot_cog.plot.callback(plot_cog, ctx, funkcja="x^2") | ||
| 67 | mock_followup.send.assert_called_once() | ||
| 68 | |||
| 69 | |||
| 70 | @pytest.mark.asyncio | ||
| 71 | async def test_plot_command_error_handling(plot_cog, mock_channel, mock_guild, bot): | ||
| 72 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 73 | |||
| 74 | with patch('cogs.plot._ensure_plot', return_value=True): | ||
| 75 | with patch('cogs.plot._plt_module') as mock_plt: | ||
| 76 | with patch('cogs.utils.temp.get_temp_dir', return_value="/tmp"): | ||
| 77 | with patch('os.path.exists', return_value=True): | ||
| 78 | with patch('os.unlink'): | ||
| 79 | with patch.object(ctx, 'followup', send=AsyncMock()) as mock_followup: | ||
| 80 | mock_plt.subplots.side_effect = ValueError("Test error") | ||
| 81 | |||
| 82 | await plot_cog.plot.callback(plot_cog, ctx, funkcja="invalid!!") | ||
| 83 | mock_followup.send.assert_called_once() | ||
| 84 | args = mock_followup.send.call_args | ||
| 85 | assert "Nie można" in str(args) or "Błąd" in str(args) \ No newline at end of file | ||
