diff options
| author | salmonik <raisersoft@proton.me> | 2026-04-18 16:24:42 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-04-18 16:24:42 +0200 |
| commit | 857a7364ddb9b10529593c5e9c3578eb95c1da9b (patch) | |
| tree | cc160ed8685039fcb08663226395fb97d78fcea6 /tests/cogs/test_tts.py | |
| parent | add support for x^2+y^2=0,4 and alike (diff) | |
| download | senator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.tar.gz senator-sperma-857a7364ddb9b10529593c5e9c3578eb95c1da9b.zip | |
add a test suite
Signed-off-by: salmonik <raisersoft@proton.me>
Diffstat (limited to 'tests/cogs/test_tts.py')
| -rw-r--r-- | tests/cogs/test_tts.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/cogs/test_tts.py b/tests/cogs/test_tts.py new file mode 100644 index 0000000..8c95670 --- /dev/null +++ b/tests/cogs/test_tts.py | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | import pytest | ||
| 2 | from unittest.mock import AsyncMock, patch, MagicMock | ||
| 3 | import discord | ||
| 4 | from tests.conftest import MockApplicationContext | ||
| 5 | |||
| 6 | |||
| 7 | @pytest.fixture | ||
| 8 | def tts_cog(bot): | ||
| 9 | from cogs.tts import TTS | ||
| 10 | cog = TTS(bot) | ||
| 11 | return cog | ||
| 12 | |||
| 13 | |||
| 14 | @pytest.mark.asyncio | ||
| 15 | async def test_tts_file_output(tts_cog, mock_channel, mock_guild, bot, mock_user): | ||
| 16 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 17 | ctx.user = mock_user | ||
| 18 | ctx.author = mock_user | ||
| 19 | |||
| 20 | mock_temp_path = "/tmp/test_tts.mp3" | ||
| 21 | |||
| 22 | with patch('cogs.tts.gTTS') as mock_gtts: | ||
| 23 | with patch('os.path.exists', return_value=True): | ||
| 24 | with patch('os.unlink'): | ||
| 25 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 26 | with patch('cogs.tts.get_volume', return_value=1.0): | ||
| 27 | await tts_cog.tts.callback(tts_cog, ctx, text="Hello", output="file") | ||
| 28 | mock_respond.assert_called_once() | ||
| 29 | |||
| 30 | |||
| 31 | @pytest.mark.asyncio | ||
| 32 | async def test_tts_voice_output_not_in_channel(tts_cog, mock_channel, mock_guild, bot, mock_user): | ||
| 33 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 34 | ctx.user = mock_user | ||
| 35 | ctx.author = mock_user | ||
| 36 | ctx.author.voice = None | ||
| 37 | |||
| 38 | with patch('cogs.tts.gTTS'): | ||
| 39 | with patch('os.path.exists', return_value=True): | ||
| 40 | with patch('os.unlink'): | ||
| 41 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 42 | with patch('cogs.tts.get_volume', return_value=1.0): | ||
| 43 | await tts_cog.tts.callback(tts_cog, ctx, text="Hello", output="vc") | ||
| 44 | |||
| 45 | |||
| 46 | @pytest.mark.asyncio | ||
| 47 | async def test_tts_error_handling(tts_cog, mock_channel, mock_guild, bot, mock_user): | ||
| 48 | ctx = MockApplicationContext(bot=bot, channel=mock_channel, guild=mock_guild) | ||
| 49 | ctx.user = mock_user | ||
| 50 | ctx.author = mock_user | ||
| 51 | |||
| 52 | with patch('cogs.tts.gTTS', side_effect=Exception("TTS Error")): | ||
| 53 | with patch('os.path.exists', return_value=False): | ||
| 54 | with patch.object(ctx, 'respond', new_callable=AsyncMock) as mock_respond: | ||
| 55 | await tts_cog.tts.callback(tts_cog, ctx, text="Hello", output="file") | ||
| 56 | mock_respond.assert_called_once() | ||
| 57 | args = mock_respond.call_args | ||
| 58 | assert "Error" in str(args) or "eror" in str(args) \ No newline at end of file | ||
