Skip to content

Commit ab6bb00

Browse files
authored
[AIRFLOW-6971] Fix return type in CloudSpeechToTextRecognizeSpeechOperator (#7607)
1 parent 2ea9278 commit ab6bb00

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

β€Žairflow/providers/google/cloud/operators/speech_to_text.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from google.api_core.retry import Retry
2424
from google.cloud.speech_v1.types import RecognitionConfig
25+
from google.protobuf.json_format import MessageToDict
2526

2627
from airflow.exceptions import AirflowException
2728
from airflow.models import BaseOperator
@@ -90,6 +91,7 @@ def _validate_inputs(self):
9091

9192
def execute(self, context):
9293
hook = CloudSpeechToTextHook(gcp_conn_id=self.gcp_conn_id)
93-
return hook.recognize_speech(
94+
respones = hook.recognize_speech(
9495
config=self.config, audio=self.audio, retry=self.retry, timeout=self.timeout
9596
)
97+
return MessageToDict(respones)

β€Žtests/providers/google/cloud/operators/test_speech_to_text.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import unittest
2020

21-
from mock import Mock, patch
21+
from mock import MagicMock, Mock, patch
2222

2323
from airflow.exceptions import AirflowException
2424
from airflow.providers.google.cloud.operators.speech_to_text import CloudSpeechToTextRecognizeSpeechOperator
@@ -32,7 +32,7 @@
3232
class TestCloudSql(unittest.TestCase):
3333
@patch("airflow.providers.google.cloud.operators.speech_to_text.CloudSpeechToTextHook")
3434
def test_recognize_speech_green_path(self, mock_hook):
35-
mock_hook.return_value.recognize_speech.return_value = True
35+
mock_hook.return_value.recognize_speech.return_value = MagicMock()
3636

3737
CloudSpeechToTextRecognizeSpeechOperator( # pylint: disable=no-value-for-parameter
3838
project_id=PROJECT_ID, gcp_conn_id=GCP_CONN_ID, config=CONFIG, audio=AUDIO, task_id="id"

0 commit comments

Comments
 (0)