-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
29e7268
commit 122a5ca
Showing
2 changed files
with
32 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |