Skip to content

Commit

Permalink
Pick up fixes to GAIPC generator. (#6508)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored and tseaver committed Nov 19, 2018
1 parent 392ba49 commit 99d2ac9
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=speech_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -107,13 +107,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = speech_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -98,6 +100,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def recognize(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=speech_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -107,13 +107,20 @@ def __init__(self,
your own client library.
"""
# Raise deprecation warnings for things we want to go away.
if client_config:
warnings.warn('The `client_config` argument is deprecated.',
PendingDeprecationWarning)
if client_config is not None:
warnings.warn(
'The `client_config` argument is deprecated.',
PendingDeprecationWarning,
stacklevel=2)
else:
client_config = speech_client_config.config

if channel:
warnings.warn(
'The `channel` argument is deprecated; use '
'`transport` instead.', PendingDeprecationWarning)
'`transport` instead.',
PendingDeprecationWarning,
stacklevel=2)

# Instantiate the transport.
# The transport is responsible for handling serialization and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(self,
credentials=credentials,
)

self._channel = channel

# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
Expand Down Expand Up @@ -98,6 +100,15 @@ def create_channel(cls,
scopes=cls._OAUTH_SCOPES,
)

@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel

@property
def recognize(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

# Setup Request
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
Expand All @@ -105,7 +109,10 @@ def test_recognize(self):
def test_recognize_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[operation])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[operation])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[iter([expected_response])])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

# Setup Request
request = {}
Expand All @@ -213,7 +229,10 @@ def test_streaming_recognize(self):
def test_streaming_recognize_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = speech_v1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1.SpeechClient()

# Setup request
request = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

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

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

# Setup Request
encoding = enums.RecognitionConfig.AudioEncoding.FLAC
Expand All @@ -105,7 +109,10 @@ def test_recognize(self):
def test_recognize_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[operation])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[operation])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

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

# Mock the API response
channel = ChannelStub(responses=[iter([expected_response])])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

# Setup Request
request = {}
Expand All @@ -213,7 +229,10 @@ def test_streaming_recognize(self):
def test_streaming_recognize_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = speech_v1p1beta1.SpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = speech_v1p1beta1.SpeechClient()

# Setup request
request = {}
Expand Down

0 comments on commit 99d2ac9

Please sign in to comment.