diff --git a/tests/unit/test_text_to_speech.py b/tests/unit/test_text_to_speech.py index 2faccbd..291fc67 100644 --- a/tests/unit/test_text_to_speech.py +++ b/tests/unit/test_text_to_speech.py @@ -1,33 +1,7 @@ -import contextlib - import pytest -from pydantic import ValidationError from pydub import AudioSegment -from sounddevice import PortAudioError -from pyrobbot.chat_configs import VoiceChatConfigs from pyrobbot.sst_and_tts import SpeechToText -from pyrobbot.voice_chat import VoiceChat - - -def test_cannot_instanciate_assistant_is_soundcard_not_imported(mocker): - """Test that the voice chat cannot be instantiated if soundcard is not imported.""" - mocker.patch("pyrobbot.voice_chat._sounddevice_imported", False) - with pytest.raises(ImportError, match="Module `sounddevice`"): - VoiceChat() - - -@pytest.mark.parametrize("param_name", ["sample_rate", "frame_duration"]) -def test_cannot_instanciate_assistant_with_invalid_webrtcvad_params(param_name): - """Test that the voice chat cannot be instantiated with invalid webrtcvad params.""" - with pytest.raises(ValidationError, match="Input should be"): - VoiceChat(configs=VoiceChatConfigs(**{param_name: 1})) - - -def test_listen(default_voice_chat): - """Test the listen method.""" - with contextlib.suppress(PortAudioError, pytest.PytestUnraisableExceptionWarning): - default_voice_chat.listen() @pytest.mark.parametrize("stt_engine", ["google", "openai"]) diff --git a/tests/unit/test_voice_chat.py b/tests/unit/test_voice_chat.py new file mode 100644 index 0000000..092c5f8 --- /dev/null +++ b/tests/unit/test_voice_chat.py @@ -0,0 +1,32 @@ +import contextlib + +import pytest +from pydantic import ValidationError +from sounddevice import PortAudioError + +from pyrobbot.chat_configs import VoiceChatConfigs +from pyrobbot.voice_chat import VoiceChat + + +def test_cannot_instanciate_assistant_is_soundcard_not_imported(mocker): + """Test that the voice chat cannot be instantiated if soundcard is not imported.""" + mocker.patch("pyrobbot.voice_chat._sounddevice_imported", False) + with pytest.raises(ImportError, match="Module `sounddevice`"): + VoiceChat() + + +@pytest.mark.parametrize("param_name", ["sample_rate", "frame_duration"]) +def test_cannot_instanciate_assistant_with_invalid_webrtcvad_params(param_name): + """Test that the voice chat cannot be instantiated with invalid webrtcvad params.""" + with pytest.raises(ValidationError, match="Input should be"): + VoiceChat(configs=VoiceChatConfigs(**{param_name: 1})) + + +def test_listen(default_voice_chat): + """Test the listen method.""" + with contextlib.suppress(PortAudioError, pytest.PytestUnraisableExceptionWarning): + default_voice_chat.listen() + + +def test_answer_question(default_voice_chat): + default_voice_chat.answer_question("foo")