Skip to content

Commit 68ee99a

Browse files
committed
Update tests from #2682.
1 parent dc9e92b commit 68ee99a

File tree

1 file changed

+56
-13
lines changed

1 file changed

+56
-13
lines changed

speech/unit_tests/test_client.py

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def make_channel(*args):
230230
return channel_obj
231231

232232
def speech_api(channel=None):
233-
return _MockGAPICSpeechAPI(response=self._make_sync_response(),
233+
return _MockGAPICSpeechAPI(response=_make_sync_response(),
234234
channel=channel)
235235

236236
host = 'foo.apis.invalid'
@@ -284,7 +284,7 @@ def make_channel(*args):
284284

285285
def speech_api(channel=None):
286286
return _MockGAPICSpeechAPI(
287-
response=self._make_sync_response(result),
287+
response=_make_sync_response(result),
288288
channel=channel)
289289

290290
host = 'foo.apis.invalid'
@@ -424,16 +424,27 @@ def test_streaming_closed_stream(self):
424424
client.connection = _Connection()
425425
client.connection.credentials = credentials
426426

427-
def speech_api():
428-
return _MockGAPICSpeechAPI(client)
427+
channel_args = []
428+
channel_obj = object()
429+
430+
def make_channel(*args):
431+
channel_args.append(args)
432+
return channel_obj
433+
434+
def speech_api(channel=None):
435+
return _MockGAPICSpeechAPI(channel=channel)
436+
437+
host = 'foo.apis.invalid'
438+
speech_api.SERVICE_ADDRESS = host
429439

430440
stream.close()
431441

432442
sample = client.sample(content=stream,
433443
encoding=Encoding.LINEAR16,
434444
sample_rate=self.SAMPLE_RATE)
435445

436-
with _Monkey(_gax, SpeechApi=speech_api):
446+
with _Monkey(_gax, SpeechApi=speech_api,
447+
make_secure_channel=make_channel):
437448
client._speech_api = _gax.GAPICSpeechAPI(client)
438449

439450
with self.assertRaises(ValueError):
@@ -465,10 +476,21 @@ def test_stream_recognize_interim_results(self):
465476
_make_sync_response(result),
466477
_make_sync_response(result)]
467478

468-
def speech_api():
469-
return _MockGAPICSpeechAPI(responses)
479+
channel_args = []
480+
channel_obj = object()
470481

471-
with _Monkey(_gax, SpeechApi=speech_api):
482+
def make_channel(*args):
483+
channel_args.append(args)
484+
return channel_obj
485+
486+
def speech_api(channel=None):
487+
return _MockGAPICSpeechAPI(channel=channel, response=responses)
488+
489+
host = 'foo.apis.invalid'
490+
speech_api.SERVICE_ADDRESS = host
491+
492+
with _Monkey(_gax, SpeechApi=speech_api,
493+
make_secure_channel=make_channel):
472494
client._speech_api = _gax.GAPICSpeechAPI(client)
473495

474496
sample = client.sample(content=stream,
@@ -503,8 +525,18 @@ def test_stream_recognize(self):
503525

504526
responses = [_make_sync_response()]
505527

506-
def speech_api():
507-
return _MockGAPICSpeechAPI(responses)
528+
channel_args = []
529+
channel_obj = object()
530+
531+
def make_channel(*args):
532+
channel_args.append(args)
533+
return channel_obj
534+
535+
def speech_api(channel=None):
536+
return _MockGAPICSpeechAPI(channel=channel, response=responses)
537+
538+
host = 'foo.apis.invalid'
539+
speech_api.SERVICE_ADDRESS = host
508540

509541
with _Monkey(_gax, SpeechApi=speech_api):
510542
client._speech_api = _gax.GAPICSpeechAPI(client)
@@ -532,10 +564,21 @@ def test_stream_recognize_no_results(self):
532564

533565
responses = [_make_sync_response()]
534566

535-
def speech_api():
536-
return _MockGAPICSpeechAPI(responses)
567+
channel_args = []
568+
channel_obj = object()
537569

538-
with _Monkey(_gax, SpeechApi=speech_api):
570+
def make_channel(*args):
571+
channel_args.append(args)
572+
return channel_obj
573+
574+
def speech_api(channel=None):
575+
return _MockGAPICSpeechAPI(channel=channel, response=responses)
576+
577+
host = 'foo.apis.invalid'
578+
speech_api.SERVICE_ADDRESS = host
579+
580+
with _Monkey(_gax, SpeechApi=speech_api,
581+
make_secure_channel=make_channel):
539582
client._speech_api = _gax.GAPICSpeechAPI(client)
540583

541584
sample = client.sample(content=stream,

0 commit comments

Comments
 (0)