Skip to content

Commit

Permalink
Language: pick up fixes to GAPIC generator. (googleapis#6521)
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored and erikwebb committed Dec 3, 2018
1 parent 93289e5 commit 31c0fff
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 42 deletions.
17 changes: 12 additions & 5 deletions language/google/cloud/language_v1/gapic/language_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=language_service_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -106,13 +106,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 = language_service_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 analyze_sentiment(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=language_service_client_config.config,
client_config=None,
client_info=None):
"""Constructor.
Expand Down Expand Up @@ -106,13 +106,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 = language_service_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 analyze_sentiment(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
2 changes: 2 additions & 0 deletions language/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@

s.move(library / f'google/cloud/language_{version}/proto')
s.move(library / f'google/cloud/language_{version}/gapic')
s.move(library / f'tests/unit/gapic/{version}')
s.move(library / f'tests/system/gapic/{version}')
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2017, Google LLC All rights reserved.
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -13,14 +15,13 @@
# limitations under the License.

import time
import unittest

from google.cloud import language_v1
from google.cloud.language_v1 import enums
from google.cloud.language_v1.proto import language_service_pb2


class TestSystemLanguageService(unittest.TestCase):
class TestSystemLanguageService(object):
def test_analyze_sentiment(self):

client = language_v1.LanguageServiceClient()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import time

from google.cloud import language_v1beta2
from google.cloud.language_v1beta2 import enums
from google.cloud.language_v1beta2.proto import language_service_pb2


class TestSystemLanguageService(object):
def test_analyze_sentiment(self):

client = language_v1beta2.LanguageServiceClient()
content = 'Hello, world!'
type_ = enums.Document.Type.PLAIN_TEXT
document = {'content': content, 'type': type_}
response = client.analyze_sentiment(document)
67 changes: 53 additions & 14 deletions language/tests/unit/gapic/v1/test_language_service_client_v1.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Copyright 2017, Google LLC All rights reserved.
# -*- coding: utf-8 -*-
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -13,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.cloud import language_v1
Expand Down Expand Up @@ -68,7 +71,10 @@ def test_analyze_sentiment(self):

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

# Setup Request
document = {}
Expand All @@ -85,7 +91,10 @@ def test_analyze_sentiment(self):
def test_analyze_sentiment_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand All @@ -102,7 +111,10 @@ def test_analyze_entities(self):

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

# Setup Request
document = {}
Expand All @@ -119,7 +131,10 @@ def test_analyze_entities(self):
def test_analyze_entities_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand All @@ -136,7 +151,10 @@ def test_analyze_entity_sentiment(self):

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

# Setup Request
document = {}
Expand All @@ -153,7 +171,10 @@ def test_analyze_entity_sentiment(self):
def test_analyze_entity_sentiment_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand All @@ -170,7 +191,10 @@ def test_analyze_syntax(self):

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

# Setup Request
document = {}
Expand All @@ -187,7 +211,10 @@ def test_analyze_syntax(self):
def test_analyze_syntax_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand All @@ -203,7 +230,10 @@ def test_classify_text(self):

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

# Setup Request
document = {}
Expand All @@ -220,7 +250,10 @@ def test_classify_text(self):
def test_classify_text_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand All @@ -237,7 +270,10 @@ def test_annotate_text(self):

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

# Setup Request
document = {}
Expand All @@ -255,7 +291,10 @@ def test_annotate_text(self):
def test_annotate_text_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = language_v1.LanguageServiceClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = language_v1.LanguageServiceClient()

# Setup request
document = {}
Expand Down
Loading

0 comments on commit 31c0fff

Please sign in to comment.