Skip to content

Commit 20227ec

Browse files
yoshi-automationtseaver
authored andcommitted
Pick up fixes to GAIPC generator. (googleapis#6508)
1 parent 4523af4 commit 20227ec

File tree

6 files changed

+96
-22
lines changed

6 files changed

+96
-22
lines changed

speech/google/cloud/speech_v1/gapic/speech_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self,
7474
transport=None,
7575
channel=None,
7676
credentials=None,
77-
client_config=speech_client_config.config,
77+
client_config=None,
7878
client_info=None):
7979
"""Constructor.
8080
@@ -107,13 +107,20 @@ def __init__(self,
107107
your own client library.
108108
"""
109109
# Raise deprecation warnings for things we want to go away.
110-
if client_config:
111-
warnings.warn('The `client_config` argument is deprecated.',
112-
PendingDeprecationWarning)
110+
if client_config is not None:
111+
warnings.warn(
112+
'The `client_config` argument is deprecated.',
113+
PendingDeprecationWarning,
114+
stacklevel=2)
115+
else:
116+
client_config = speech_client_config.config
117+
113118
if channel:
114119
warnings.warn(
115120
'The `channel` argument is deprecated; use '
116-
'`transport` instead.', PendingDeprecationWarning)
121+
'`transport` instead.',
122+
PendingDeprecationWarning,
123+
stacklevel=2)
117124

118125
# Instantiate the transport.
119126
# The transport is responsible for handling serialization and

speech/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def __init__(self,
6363
credentials=credentials,
6464
)
6565

66+
self._channel = channel
67+
6668
# gRPC uses objects called "stubs" that are bound to the
6769
# channel and provide a basic method for each RPC.
6870
self._stubs = {
@@ -98,6 +100,15 @@ def create_channel(cls,
98100
scopes=cls._OAUTH_SCOPES,
99101
)
100102

103+
@property
104+
def channel(self):
105+
"""The gRPC channel used by the transport.
106+
107+
Returns:
108+
grpc.Channel: A gRPC channel object.
109+
"""
110+
return self._channel
111+
101112
@property
102113
def recognize(self):
103114
"""Return the gRPC stub for {$apiMethod.name}.

speech/google/cloud/speech_v1p1beta1/gapic/speech_client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self,
7474
transport=None,
7575
channel=None,
7676
credentials=None,
77-
client_config=speech_client_config.config,
77+
client_config=None,
7878
client_info=None):
7979
"""Constructor.
8080
@@ -107,13 +107,20 @@ def __init__(self,
107107
your own client library.
108108
"""
109109
# Raise deprecation warnings for things we want to go away.
110-
if client_config:
111-
warnings.warn('The `client_config` argument is deprecated.',
112-
PendingDeprecationWarning)
110+
if client_config is not None:
111+
warnings.warn(
112+
'The `client_config` argument is deprecated.',
113+
PendingDeprecationWarning,
114+
stacklevel=2)
115+
else:
116+
client_config = speech_client_config.config
117+
113118
if channel:
114119
warnings.warn(
115120
'The `channel` argument is deprecated; use '
116-
'`transport` instead.', PendingDeprecationWarning)
121+
'`transport` instead.',
122+
PendingDeprecationWarning,
123+
stacklevel=2)
117124

118125
# Instantiate the transport.
119126
# The transport is responsible for handling serialization and

speech/google/cloud/speech_v1p1beta1/gapic/transports/speech_grpc_transport.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def __init__(self,
6363
credentials=credentials,
6464
)
6565

66+
self._channel = channel
67+
6668
# gRPC uses objects called "stubs" that are bound to the
6769
# channel and provide a basic method for each RPC.
6870
self._stubs = {
@@ -98,6 +100,15 @@ def create_channel(cls,
98100
scopes=cls._OAUTH_SCOPES,
99101
)
100102

103+
@property
104+
def channel(self):
105+
"""The gRPC channel used by the transport.
106+
107+
Returns:
108+
grpc.Channel: A gRPC channel object.
109+
"""
110+
return self._channel
111+
101112
@property
102113
def recognize(self):
103114
"""Return the gRPC stub for {$apiMethod.name}.

speech/tests/unit/gapic/v1/test_speech_client_v1.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
"""Unit tests."""
1717

18+
import mock
1819
import pytest
1920

2021
from google.rpc import status_pb2
@@ -79,7 +80,10 @@ def test_recognize(self):
7980

8081
# Mock the API response
8182
channel = ChannelStub(responses=[expected_response])
82-
client = speech_v1.SpeechClient(channel=channel)
83+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
84+
with patch as create_channel:
85+
create_channel.return_value = channel
86+
client = speech_v1.SpeechClient()
8387

8488
# Setup Request
8589
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -105,7 +109,10 @@ def test_recognize(self):
105109
def test_recognize_exception(self):
106110
# Mock the API response
107111
channel = ChannelStub(responses=[CustomException()])
108-
client = speech_v1.SpeechClient(channel=channel)
112+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
113+
with patch as create_channel:
114+
create_channel.return_value = channel
115+
client = speech_v1.SpeechClient()
109116

110117
# Setup request
111118
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -133,7 +140,10 @@ def test_long_running_recognize(self):
133140

134141
# Mock the API response
135142
channel = ChannelStub(responses=[operation])
136-
client = speech_v1.SpeechClient(channel=channel)
143+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
144+
with patch as create_channel:
145+
create_channel.return_value = channel
146+
client = speech_v1.SpeechClient()
137147

138148
# Setup Request
139149
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -166,7 +176,10 @@ def test_long_running_recognize_exception(self):
166176

167177
# Mock the API response
168178
channel = ChannelStub(responses=[operation])
169-
client = speech_v1.SpeechClient(channel=channel)
179+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
180+
with patch as create_channel:
181+
create_channel.return_value = channel
182+
client = speech_v1.SpeechClient()
170183

171184
# Setup Request
172185
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -192,7 +205,10 @@ def test_streaming_recognize(self):
192205

193206
# Mock the API response
194207
channel = ChannelStub(responses=[iter([expected_response])])
195-
client = speech_v1.SpeechClient(channel=channel)
208+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
209+
with patch as create_channel:
210+
create_channel.return_value = channel
211+
client = speech_v1.SpeechClient()
196212

197213
# Setup Request
198214
request = {}
@@ -213,7 +229,10 @@ def test_streaming_recognize(self):
213229
def test_streaming_recognize_exception(self):
214230
# Mock the API response
215231
channel = ChannelStub(responses=[CustomException()])
216-
client = speech_v1.SpeechClient(channel=channel)
232+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
233+
with patch as create_channel:
234+
create_channel.return_value = channel
235+
client = speech_v1.SpeechClient()
217236

218237
# Setup request
219238
request = {}

speech/tests/unit/gapic/v1p1beta1/test_speech_client_v1p1beta1.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616
"""Unit tests."""
1717

18+
import mock
1819
import pytest
1920

2021
from google.rpc import status_pb2
@@ -79,7 +80,10 @@ def test_recognize(self):
7980

8081
# Mock the API response
8182
channel = ChannelStub(responses=[expected_response])
82-
client = speech_v1p1beta1.SpeechClient(channel=channel)
83+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
84+
with patch as create_channel:
85+
create_channel.return_value = channel
86+
client = speech_v1p1beta1.SpeechClient()
8387

8488
# Setup Request
8589
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -105,7 +109,10 @@ def test_recognize(self):
105109
def test_recognize_exception(self):
106110
# Mock the API response
107111
channel = ChannelStub(responses=[CustomException()])
108-
client = speech_v1p1beta1.SpeechClient(channel=channel)
112+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
113+
with patch as create_channel:
114+
create_channel.return_value = channel
115+
client = speech_v1p1beta1.SpeechClient()
109116

110117
# Setup request
111118
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -133,7 +140,10 @@ def test_long_running_recognize(self):
133140

134141
# Mock the API response
135142
channel = ChannelStub(responses=[operation])
136-
client = speech_v1p1beta1.SpeechClient(channel=channel)
143+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
144+
with patch as create_channel:
145+
create_channel.return_value = channel
146+
client = speech_v1p1beta1.SpeechClient()
137147

138148
# Setup Request
139149
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -166,7 +176,10 @@ def test_long_running_recognize_exception(self):
166176

167177
# Mock the API response
168178
channel = ChannelStub(responses=[operation])
169-
client = speech_v1p1beta1.SpeechClient(channel=channel)
179+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
180+
with patch as create_channel:
181+
create_channel.return_value = channel
182+
client = speech_v1p1beta1.SpeechClient()
170183

171184
# Setup Request
172185
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
@@ -192,7 +205,10 @@ def test_streaming_recognize(self):
192205

193206
# Mock the API response
194207
channel = ChannelStub(responses=[iter([expected_response])])
195-
client = speech_v1p1beta1.SpeechClient(channel=channel)
208+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
209+
with patch as create_channel:
210+
create_channel.return_value = channel
211+
client = speech_v1p1beta1.SpeechClient()
196212

197213
# Setup Request
198214
request = {}
@@ -213,7 +229,10 @@ def test_streaming_recognize(self):
213229
def test_streaming_recognize_exception(self):
214230
# Mock the API response
215231
channel = ChannelStub(responses=[CustomException()])
216-
client = speech_v1p1beta1.SpeechClient(channel=channel)
232+
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
233+
with patch as create_channel:
234+
create_channel.return_value = channel
235+
client = speech_v1p1beta1.SpeechClient()
217236

218237
# Setup request
219238
request = {}

0 commit comments

Comments
 (0)