Skip to content

Commit 4af337c

Browse files
Speech Client Library Header (#3048)
1 parent 6e2a184 commit 4af337c

File tree

4 files changed

+96
-21
lines changed

4 files changed

+96
-21
lines changed

packages/google-cloud-speech/google/cloud/speech/_gax.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from google.cloud._helpers import make_secure_stub
3232
from google.cloud._http import DEFAULT_USER_AGENT
3333

34+
from google.cloud.speech import __version__
3435
from google.cloud.speech.operation import Operation
3536
from google.cloud.speech.result import Result
3637

@@ -45,12 +46,17 @@ def __init__(self, client=None):
4546
channel = make_secure_channel(
4647
credentials, DEFAULT_USER_AGENT,
4748
SpeechClient.SERVICE_ADDRESS)
48-
self._gapic_api = SpeechClient(channel=channel)
49+
self._gapic_api = SpeechClient(
50+
channel=channel,
51+
lib_name='gccl',
52+
lib_version=__version__,
53+
)
4954
self._operations_stub = make_secure_stub(
5055
credentials,
5156
DEFAULT_USER_AGENT,
5257
operations_grpc.OperationsStub,
53-
OPERATIONS_API_HOST)
58+
OPERATIONS_API_HOST,
59+
)
5460

5561
def async_recognize(self, sample, language_code=None,
5662
max_alternatives=None, profanity_filter=None,

packages/google-cloud-speech/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@
5151
REQUIREMENTS = [
5252
'google-cloud-core >= 0.23.0, < 0.24dev',
5353
'grpcio >= 1.0.2, < 2.0dev',
54-
'gapic-google-cloud-speech-v1beta1 >= 0.15.0, < 0.16dev',
54+
'gapic-google-cloud-speech-v1beta1 >= 0.15.1, < 0.16dev',
5555
]
5656

5757
setup(
5858
name='google-cloud-speech',
59-
version='0.22.0',
59+
version='0.23.0',
6060
description='Python Client for Google Cloud Speech',
6161
long_description=README,
6262
namespace_packages=[

packages/google-cloud-speech/unit_tests/test__gax.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,71 @@
1414

1515
import unittest
1616

17+
import mock
18+
19+
20+
def _make_credentials():
21+
import google.auth.credentials
22+
23+
return mock.Mock(spec=google.auth.credentials.Credentials)
24+
25+
26+
class TestGAPICSpeechAPI(unittest.TestCase):
27+
28+
@staticmethod
29+
def _get_target_class():
30+
from google.cloud.speech._gax import GAPICSpeechAPI
31+
32+
return GAPICSpeechAPI
33+
34+
def _make_one(self, *args, **kw):
35+
return self._get_target_class()(*args, **kw)
36+
37+
@mock.patch(
38+
'google.cloud._helpers.make_secure_channel',
39+
return_value=mock.sentinel.channel)
40+
@mock.patch(
41+
'google.cloud.gapic.speech.v1beta1.speech_client.SpeechClient',
42+
SERVICE_ADDRESS='hey.you.guys')
43+
@mock.patch(
44+
'google.cloud._helpers.make_secure_stub',
45+
return_value=mock.sentinel.stub)
46+
def test_constructor(self, mocked_stub, mocked_cls, mocked_channel):
47+
from google.longrunning import operations_grpc
48+
from google.cloud._http import DEFAULT_USER_AGENT
49+
from google.cloud.speech import __version__
50+
from google.cloud.speech._gax import OPERATIONS_API_HOST
51+
52+
mock_cnxn = mock.Mock(
53+
credentials=_make_credentials(),
54+
spec=['credentials'],
55+
)
56+
mock_client = mock.Mock(_connection=mock_cnxn, spec=['_connection'])
57+
58+
speech_api = self._make_one(mock_client)
59+
self.assertIs(speech_api._client, mock_client)
60+
self.assertIs(
61+
speech_api._gapic_api,
62+
mocked_cls.return_value,
63+
)
64+
65+
mocked_stub.assert_called_once_with(
66+
mock_cnxn.credentials,
67+
DEFAULT_USER_AGENT,
68+
operations_grpc.OperationsStub,
69+
OPERATIONS_API_HOST,
70+
)
71+
mocked_cls.assert_called_once_with(
72+
channel=mock.sentinel.channel,
73+
lib_name='gccl',
74+
lib_version=__version__,
75+
)
76+
mocked_channel.assert_called_once_with(
77+
mock_cnxn.credentials,
78+
DEFAULT_USER_AGENT,
79+
mocked_cls.SERVICE_ADDRESS,
80+
)
81+
1782

1883
class TestSpeechGAXMakeRequests(unittest.TestCase):
1984
SAMPLE_RATE = 16000

packages/google-cloud-speech/unit_tests/test_client.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ def make_channel(*args):
258258
channel_args.append(args)
259259
return channel_obj
260260

261-
def speech_api(channel=None):
261+
def speech_api(channel=None, **kwargs):
262262
return _MockGAPICSpeechAPI(response=_make_sync_response(),
263-
channel=channel)
263+
channel=channel, **kwargs)
264264

265265
host = 'foo.apis.invalid'
266266
speech_api.SERVICE_ADDRESS = host
@@ -311,10 +311,10 @@ def make_channel(*args):
311311
channel_args.append(args)
312312
return channel_obj
313313

314-
def speech_api(channel=None):
314+
def speech_api(channel=None, **kwargs):
315315
return _MockGAPICSpeechAPI(
316316
response=_make_sync_response(result),
317-
channel=channel)
317+
channel=channel, **kwargs)
318318

319319
host = 'foo.apis.invalid'
320320
speech_api.SERVICE_ADDRESS = host
@@ -407,8 +407,8 @@ def make_channel(*args):
407407
encoding=speech.Encoding.LINEAR16,
408408
sample_rate=self.SAMPLE_RATE)
409409

410-
def speech_api(channel=None):
411-
return _MockGAPICSpeechAPI(channel=channel)
410+
def speech_api(channel=None, **kwargs):
411+
return _MockGAPICSpeechAPI(channel=channel, **kwargs)
412412

413413
host = 'foo.apis.invalid'
414414
speech_api.SERVICE_ADDRESS = host
@@ -463,8 +463,8 @@ def make_channel(*args):
463463
channel_args.append(args)
464464
return channel_obj
465465

466-
def speech_api(channel=None):
467-
return _MockGAPICSpeechAPI(channel=channel)
466+
def speech_api(channel=None, **kwargs):
467+
return _MockGAPICSpeechAPI(channel=channel, **kwargs)
468468

469469
host = 'foo.apis.invalid'
470470
speech_api.SERVICE_ADDRESS = host
@@ -522,8 +522,9 @@ def make_channel(*args):
522522
channel_args.append(args)
523523
return channel_obj
524524

525-
def speech_api(channel=None):
526-
return _MockGAPICSpeechAPI(channel=channel, response=responses)
525+
def speech_api(channel=None, **kwargs):
526+
return _MockGAPICSpeechAPI(channel=channel, response=responses,
527+
**kwargs)
527528

528529
host = 'foo.apis.invalid'
529530
speech_api.SERVICE_ADDRESS = host
@@ -599,8 +600,9 @@ def make_channel(*args):
599600
channel_args.append(args)
600601
return channel_obj
601602

602-
def speech_api(channel=None):
603-
return _MockGAPICSpeechAPI(channel=channel, response=responses)
603+
def speech_api(channel=None, **kwargs):
604+
return _MockGAPICSpeechAPI(channel=channel, response=responses,
605+
**kwargs)
604606

605607
host = 'foo.apis.invalid'
606608
speech_api.SERVICE_ADDRESS = host
@@ -643,8 +645,9 @@ def make_channel(*args):
643645
channel_args.append(args)
644646
return channel_obj
645647

646-
def speech_api(channel=None):
647-
return _MockGAPICSpeechAPI(channel=channel, response=responses)
648+
def speech_api(channel=None, **kwargs):
649+
return _MockGAPICSpeechAPI(channel=channel, response=responses,
650+
**kwargs)
648651

649652
host = 'foo.apis.invalid'
650653
speech_api.SERVICE_ADDRESS = host
@@ -677,8 +680,8 @@ def make_channel(*args):
677680
channel_args.append(args)
678681
return channel_obj
679682

680-
def speech_api(channel=None):
681-
return _MockGAPICSpeechAPI(channel=channel)
683+
def speech_api(channel=None, **kwargs):
684+
return _MockGAPICSpeechAPI(channel=channel, **kwargs)
682685

683686
host = 'foo.apis.invalid'
684687
speech_api.SERVICE_ADDRESS = host
@@ -720,9 +723,10 @@ class _MockGAPICSpeechAPI(object):
720723

721724
SERVICE_ADDRESS = 'foo.apis.invalid'
722725

723-
def __init__(self, response=None, channel=None):
726+
def __init__(self, response=None, channel=None, **kwargs):
724727
self._response = response
725728
self._channel = channel
729+
self._kwargs = kwargs
726730

727731
def async_recognize(self, config, audio):
728732
from google.gapic.longrunning.operations_client import OperationsClient

0 commit comments

Comments
 (0)