@@ -199,11 +199,10 @@ def test_sync_recognize_with_empty_results_gax(self):
199199 credentials = _Credentials ()
200200 client = self ._makeOne (credentials = credentials , use_gax = True )
201201 client .connection = _Connection ()
202+ _MockGAPICSpeechAPI ._results = []
202203
203204 with self .assertRaises (ValueError ):
204- mock_no_results = _MockGAPICSpeechAPI
205- mock_no_results ._results = []
206- with _Monkey (MUT , SpeechApi = mock_no_results ):
205+ with _Monkey (MUT , SpeechApi = _MockGAPICSpeechAPI ):
207206 sample = Sample (source_uri = self .AUDIO_SOURCE_URI ,
208207 encoding = speech .Encoding .FLAC ,
209208 sample_rate = self .SAMPLE_RATE )
@@ -218,9 +217,7 @@ def test_sync_recognize_with_gax(self):
218217 client = self ._makeOne (credentials = creds , use_gax = True )
219218 client .connection = _Connection ()
220219 client ._speech_api = None
221-
222- mock_no_results = _MockGAPICSpeechAPI
223- mock_no_results ._results = [_MockGAPICSyncResult ()]
220+ _MockGAPICSpeechAPI ._results = [_MockGAPICSyncResult ]
224221
225222 with _Monkey (MUT , SpeechApi = _MockGAPICSpeechAPI ):
226223 sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
@@ -277,13 +274,16 @@ def test_async_recognize_with_gax(self):
277274 credentials = _Credentials ()
278275 client = self ._makeOne (credentials = credentials )
279276 client .connection = _Connection ()
277+ client .connection .credentials = credentials
280278
281279 sample = client .sample (source_uri = self .AUDIO_SOURCE_URI ,
282280 encoding = speech .Encoding .LINEAR16 ,
283281 sample_rate = self .SAMPLE_RATE )
284282 with _Monkey (MUT , SpeechApi = _MockGAPICSpeechAPI ):
285- with self .assertRaises (NotImplementedError ):
286- client .async_recognize (sample )
283+ operation = client .async_recognize (sample )
284+
285+ self .assertFalse (operation .complete )
286+ self .assertIsNone (operation .response )
287287
288288 def test_speech_api_with_gax (self ):
289289 from google .cloud .speech import _gax as MUT
@@ -321,28 +321,40 @@ class _MockGAPICAlternative(object):
321321 confidence = 0.95234356
322322
323323
324+ class _MockGAPICMetadata (object ):
325+ type_url = None
326+
327+
324328class _MockGAPICSyncResult (object ):
325329 alternatives = [_MockGAPICAlternative ()]
326330
327331
328332class _MockGAPICSpeechResponse (object ):
329333 error = None
330334 endpointer_type = None
335+ name = None
336+ metadata = _MockGAPICMetadata ()
331337 results = []
332338 result_index = 0
333339
334340
335341class _MockGAPICSpeechAPI (object ):
336342 _requests = None
337- _response = _MockGAPICSpeechResponse ()
343+ _response = _MockGAPICSpeechResponse
338344 _results = [_MockGAPICSyncResult ()]
339345
346+ def async_recognize (self , config , audio ):
347+ from google .longrunning .operations_pb2 import Operation
348+ self .config = config
349+ self .audio = audio
350+ operation = Operation ()
351+ return operation
352+
340353 def sync_recognize (self , config , audio ):
341354 self .config = config
342355 self .audio = audio
343- mock_response = self ._response
344- mock_response .results = self ._results
345- return mock_response
356+ self ._response .results = self ._results
357+ return self ._response
346358
347359
348360class _Credentials (object ):
0 commit comments