Skip to content

Commit

Permalink
Pick up fixes to GAPIC generator. (#6510)
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 092b021 commit 052ddfe
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=text_to_speech_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -103,13 +103,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 = text_to_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 @@ -62,6 +62,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 @@ -92,6 +94,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 list_voices(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=text_to_speech_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -103,13 +103,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 = text_to_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 @@ -62,6 +62,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 @@ -92,6 +94,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 list_voices(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.cloud import texttospeech_v1
Expand Down Expand Up @@ -69,7 +70,10 @@ def test_list_voices(self):

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

response = client.list_voices()
assert expected_response == response
Expand All @@ -82,7 +86,10 @@ def test_list_voices(self):
def test_list_voices_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = texttospeech_v1.TextToSpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = texttospeech_v1.TextToSpeechClient()

with pytest.raises(CustomException):
client.list_voices()
Expand All @@ -96,7 +103,10 @@ def test_synthesize_speech(self):

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

# Setup Request
input_ = {}
Expand All @@ -115,7 +125,10 @@ def test_synthesize_speech(self):
def test_synthesize_speech_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = texttospeech_v1.TextToSpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = texttospeech_v1.TextToSpeechClient()

# Setup request
input_ = {}
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.cloud import texttospeech_v1beta1
Expand Down Expand Up @@ -69,7 +70,10 @@ def test_list_voices(self):

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

response = client.list_voices()
assert expected_response == response
Expand All @@ -82,7 +86,10 @@ def test_list_voices(self):
def test_list_voices_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = texttospeech_v1beta1.TextToSpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = texttospeech_v1beta1.TextToSpeechClient()

with pytest.raises(CustomException):
client.list_voices()
Expand All @@ -96,7 +103,10 @@ def test_synthesize_speech(self):

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

# Setup Request
input_ = {}
Expand All @@ -115,7 +125,10 @@ def test_synthesize_speech(self):
def test_synthesize_speech_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = texttospeech_v1beta1.TextToSpeechClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = texttospeech_v1beta1.TextToSpeechClient()

# Setup request
input_ = {}
Expand Down

0 comments on commit 052ddfe

Please sign in to comment.