fix: improve voice test mocking to handle async prompt behavior

This commit is contained in:
Paul Gauthier (aider) 2024-11-30 15:42:42 -08:00
parent ba032ce60e
commit 5c208dba41

View file

@ -71,8 +71,15 @@ def test_record_and_transcribe(mock_litellm, mock_soundfile):
voice = Voice()
# Mock the recording process
with patch("prompt_toolkit.shortcuts.prompt", return_value=""):
with patch("sounddevice.InputStream"):
with patch("sounddevice.InputStream") as mock_stream:
# Set up the mock stream to simulate some audio data
mock_data = np.zeros((1000, 1))
mock_stream.return_value.__enter__.return_value = mock_data
# Mock prompt_toolkit's prompt function more completely
with patch("prompt_toolkit.shortcuts.prompt") as mock_prompt:
mock_prompt.return_value = "" # Simulate pressing Enter
# Mock the transcription response
mock_litellm.transcription.return_value = Mock(text="Hello, world!")