Skip to content

Commit

Permalink
Add a few tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulovcmedeiros committed Feb 4, 2024
1 parent 29e7268 commit 122a5ca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
26 changes: 0 additions & 26 deletions tests/unit/test_text_to_speech.py
Original file line number Diff line number Diff line change
@@ -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"])
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/test_voice_chat.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 122a5ca

Please sign in to comment.