Skip to content

Commit

Permalink
[test] recognize_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
ftnext committed Dec 5, 2023
1 parent fdd9af9 commit 54bb083
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/recognizers/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock, patch
from urllib.request import Request

from speech_recognition import Recognizer
from speech_recognition.audio import AudioData
from speech_recognition.recognizers import google

Expand Down Expand Up @@ -108,3 +109,35 @@ def test_obtain(self, urlopen):
urlopen.assert_called_once_with(request, timeout=0)
response.read.assert_called_once_with()
response.read.return_value.decode.assert_called_once_with("utf-8")


class RecognizeLegacyTestCase(TestCase):
@patch(f"{MODULE_UNDER_TEST}.OutputParser")
@patch(f"{MODULE_UNDER_TEST}.obtain_transcription")
@patch(f"{MODULE_UNDER_TEST}.create_request_builder")
def test_default_values(
self, create_request_builder, obtain_transcription, OutputParser
):
request_builder = create_request_builder.return_value
request = request_builder.build.return_value
response_text = obtain_transcription.return_value
output_parser = OutputParser.return_value

# Add operation_timeout attribute by spec=<instance>
recognizer = MagicMock(spec=Recognizer())
audio_data = MagicMock(spec=AudioData)

actual = google.recognize_legacy(recognizer, audio_data)

self.assertEqual(actual, output_parser.parse.return_value)
create_request_builder.assert_called_once_with(
key=None, language="en-US", filter_level=0
)
request_builder.build.assert_called_once_with(audio_data)
obtain_transcription.assert_called_once_with(
request, timeout=recognizer.operation_timeout
)
OutputParser.assert_called_once_with(
show_all=False, with_confidence=False
)
output_parser.parse.assert_called_once_with(response_text)

0 comments on commit 54bb083

Please sign in to comment.