aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cogs/test_plot.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
committersalmonik <raisersoft@proton.me>2026-04-19 15:44:33 +0200
commitb343381fea3eab26e334a1b3bba202d715f9ea2e (patch)
tree792210018d1e11ac3b160edfe29cf878eb4e3f56 /tests/cogs/test_plot.py
parentchore: add pycord dependency, update main (diff)
downloadsenator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.tar.gz
senator-sperma-b343381fea3eab26e334a1b3bba202d715f9ea2e.zip
test: improve test assertions and edge cases
Diffstat (limited to 'tests/cogs/test_plot.py')
-rw-r--r--tests/cogs/test_plot.py85
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 @@
1import pytest
2from unittest.mock import AsyncMock, patch, MagicMock
3import os
4from tests.conftest import MockApplicationContext
5
6
7def 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
17def 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
25def 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
35def plot_cog(bot):
36 from cogs.plot import Plot
37 cog = Plot(bot)
38 return cog
39
40
41@pytest.mark.asyncio
42async 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
54async 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
71async 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