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_music_audio.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'tests/cogs/test_music_audio.py') diff --git a/tests/cogs/test_music_audio.py b/tests/cogs/test_music_audio.py index b53cf95..7ea902e 100644 --- a/tests/cogs/test_music_audio.py +++ b/tests/cogs/test_music_audio.py @@ -7,13 +7,13 @@ from tests.conftest import MockApplicationContext @pytest.mark.asyncio async def test_validate_voice_channel_not_in_voice(): from cogs.music.audio_playback import AudioPlaybackManager - + mock_ctx = MagicMock() mock_ctx.author.voice = None mock_ctx.respond = AsyncMock() - + result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) - + assert result is None mock_ctx.respond.assert_called_once() @@ -21,24 +21,24 @@ async def test_validate_voice_channel_not_in_voice(): @pytest.mark.asyncio async def test_validate_voice_channel_in_voice(): from cogs.music.audio_playback import AudioPlaybackManager - + mock_channel = MagicMock() mock_ctx = MagicMock() mock_ctx.author.voice = MagicMock() mock_ctx.author.voice.channel = mock_channel mock_ctx.respond = AsyncMock() - + result = await AudioPlaybackManager.validate_voice_channel(mock_ctx) - + assert result == mock_channel @pytest.mark.asyncio async def test_prepare_file_source_file_not_found(): from cogs.music.audio_playback import AudioPlaybackManager - + display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") - + assert display_name is None assert absolute_path is None @@ -46,11 +46,11 @@ async def test_prepare_file_source_file_not_found(): @pytest.mark.asyncio async def test_prepare_file_source_absolute_path(): from cogs.music.audio_playback import AudioPlaybackManager - + with patch('os.path.exists', return_value=True): with patch('os.path.isabs', return_value=True): display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/tmp/test.mp3") - + assert display_name == "test" assert absolute_path == "/tmp/test.mp3" @@ -58,9 +58,9 @@ async def test_prepare_file_source_absolute_path(): @pytest.mark.asyncio async def test_prepare_source_url(): from cogs.music.audio_playback import AudioPlaybackManager - - source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream") - + + source, _, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "https://example.com/stream") + assert is_url == True assert source == "https://example.com/stream" @@ -68,10 +68,10 @@ async def test_prepare_source_url(): @pytest.mark.asyncio async def test_prepare_source_local_file(): from cogs.music.audio_playback import AudioPlaybackManager - + with patch('os.path.exists', return_value=True): source, display_name, is_url = await AudioPlaybackManager.prepare_source(MagicMock(), "/tmp/test.mp3") - + assert is_url == False assert display_name == "test" @@ -79,7 +79,7 @@ async def test_prepare_source_local_file(): @pytest.mark.asyncio async def test_cleanup_temp_file(): from cogs.music.audio_playback import AudioPlaybackManager - + with patch('os.path.exists', return_value=True): with patch('os.remove'): await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3") @@ -88,6 +88,6 @@ async def test_cleanup_temp_file(): @pytest.mark.asyncio async def test_cleanup_temp_file_not_exists(): from cogs.music.audio_playback import AudioPlaybackManager - + with patch('os.path.exists', return_value=False): - await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") \ No newline at end of file + await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3") -- cgit v1.2.3