import pytest from unittest.mock import AsyncMock, patch, MagicMock import os from conftest import MockApplicationContext @pytest.mark.asyncio async def test_validate_voice_channel_not_in_voice(): from cogs.voice import VoiceManager as 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() @pytest.mark.asyncio async def test_validate_voice_channel_in_voice(): from cogs.voice import VoiceManager as 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.voice import VoiceManager as AudioPlaybackManager display_name, absolute_path = await AudioPlaybackManager.prepare_file_source("/nonexistent/file.mp3") assert display_name is None assert absolute_path is None @pytest.mark.asyncio async def test_prepare_file_source_absolute_path(): from cogs.voice import VoiceManager as 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" @pytest.mark.asyncio async def test_prepare_source_url(): from cogs.voice import VoiceManager as AudioPlaybackManager source, _, is_url = await AudioPlaybackManager.prepare_source("https://example.com/stream") assert is_url == True assert source == "https://example.com/stream" @pytest.mark.asyncio async def test_prepare_source_local_file(): from cogs.voice import VoiceManager as AudioPlaybackManager with patch('os.path.exists', return_value=True): source, display_name, is_url = await AudioPlaybackManager.prepare_source("/tmp/test.mp3") assert is_url == False assert display_name == "test" @pytest.mark.asyncio async def test_cleanup_temp_file(): from cogs.voice import VoiceManager as AudioPlaybackManager with patch('os.path.exists', return_value=True): with patch('os.remove'): await AudioPlaybackManager.cleanup_temp_file("/tmp/test.mp3") @pytest.mark.asyncio async def test_cleanup_temp_file_not_exists(): from cogs.voice import VoiceManager as AudioPlaybackManager with patch('os.path.exists', return_value=False): await AudioPlaybackManager.cleanup_temp_file("/nonexistent/file.mp3")