Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAPIC Header Consistency: Vision #3050

Merged
merged 9 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions vision/google/cloud/vision/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from google.cloud.gapic.vision.v1 import image_annotator_client
from google.cloud.grpc.vision.v1 import image_annotator_pb2

from google.cloud.vision import __version__
from google.cloud.vision.annotations import Annotations


Expand All @@ -25,10 +26,14 @@ class _GAPICVisionAPI(object):

:type client: :class:`~google.cloud.vision.client.Client`
:param client: Instance of ``Client`` object.

:type kwargs: dict
:param kwargs: Additional keyword arguments are sent to the GAPIC client.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

"""
def __init__(self, client=None):
def __init__(self, client=None, credentials=None):
self._client = client
self._annotator_client = image_annotator_client.ImageAnnotatorClient()
self._annotator_client = image_annotator_client.ImageAnnotatorClient(
credentials=credentials, lib_name='gccl', lib_version=__version__)

This comment was marked as spam.


def annotate(self, images):
"""Annotate images through GAX.
Expand Down
3 changes: 2 additions & 1 deletion vision/google/cloud/vision/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def _vision_api(self):
"""
if self._vision_api_internal is None:
if self._use_gax:
self._vision_api_internal = _GAPICVisionAPI(self)
self._vision_api_internal = _GAPICVisionAPI(self,
credentials=None)

This comment was marked as spam.

else:
self._vision_api_internal = _HTTPVisionAPI(self)
return self._vision_api_internal
4 changes: 2 additions & 2 deletions vision/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
REQUIREMENTS = [
'enum34',
'google-cloud-core >= 0.23.0, < 0.24dev',
'gapic-google-cloud-vision-v1 >= 0.14.0, < 0.15dev',
'gapic-google-cloud-vision-v1 >= 0.15.0, < 0.16dev',
]

setup(
name='google-cloud-vision',
version='0.22.0',
version='0.23.0',
description='Python Client for Google Cloud Vision',
long_description=README,
namespace_packages=[
Expand Down
41 changes: 41 additions & 0 deletions vision/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ def test_ctor(self):
api = self._make_one(client)
self.assertIs(api._client, client)

def test_gapic_credentials(self):
from google.cloud.gapic.vision.v1.image_annotator_client import (
ImageAnnotatorClient)

from .test_client import _make_credentials

This comment was marked as spam.

This comment was marked as spam.


# Mock the GAPIC ImageAnnotatorClient, whose arguments we
# want to check.
with mock.patch.object(ImageAnnotatorClient, '__init__') as iac:
iac.return_value = None

# Create the GAX client.
credentials = _make_credentials()
self._make_one(client=object(), credentials=credentials)

This comment was marked as spam.


# Assert that the GAPIC constructor was called once, and
# that the credentials were sent.
iac.assert_called_once()
self.assertIs(iac.mock_calls[0][2]['credentials'], credentials)

This comment was marked as spam.

This comment was marked as spam.


def test_kwarg_lib_name(self):
from google.cloud.gapic.vision.v1.image_annotator_client import (
ImageAnnotatorClient)
from google.cloud.vision import __version__

from .test_client import _make_credentials

# Mock the GAPIC ImageAnnotatorClient, whose arguments we
# want to check.
with mock.patch.object(ImageAnnotatorClient, '__init__') as iac:
iac.return_value = None

# Create the GAX client.
self._make_one(client=object(), credentials=_make_credentials())

# Assert that the GAPIC constructor was called once, and
# that lib_name and lib_version were sent.
iac.assert_called_once()
self.assertEqual(iac.mock_calls[0][2]['lib_name'], 'gccl')
self.assertEqual(iac.mock_calls[0][2]['lib_version'], __version__)

This comment was marked as spam.


def test_annotation(self):
from google.cloud.vision.feature import Feature
from google.cloud.vision.feature import FeatureTypes
Expand Down