Skip to content

Commit

Permalink
Add multiple result exception for GAX.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 13, 2017
1 parent 069f700 commit 958f90e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vision/google/cloud/vision/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def annotate(self, image, features):
images = annotator_client.batch_annotate_images(requests)
if len(images.responses) == 1:
return Annotations.from_pb(images.responses[0])
elif len(images.responses) > 1:
raise ValueError('Multiple image processing is not yet supported.')


def _to_gapic_feature(feature):
Expand Down
25 changes: 25 additions & 0 deletions vision/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ def test_annotate_no_results(self):

gax_api._annotator_client.batch_annotate_images.assert_called()

def test_annotate_multiple_results(self):
from google.cloud.vision.feature import Feature
from google.cloud.vision.feature import FeatureTypes
from google.cloud.vision.image import Image

client = mock.Mock(spec_set=[])
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
image_content = b'abc 1 2 3'
image = Image(client, content=image_content)
with mock.patch('google.cloud.vision._gax.image_annotator_client.'
'ImageAnnotatorClient'):
gax_api = self._make_one(client)

mock_response = {
'batch_annotate_images.return_value': mock.Mock(responses=[1, 2]),
}

gax_api._annotator_client = mock.Mock(
spec_set=['batch_annotate_images'], **mock_response)
with mock.patch('google.cloud.vision._gax.Annotations'):
with self.assertRaises(ValueError):
gax_api.annotate(image, [feature])

gax_api._annotator_client.batch_annotate_images.assert_called()


class Test__to_gapic_feature(unittest.TestCase):
def _call_fut(self, feature):
Expand Down

0 comments on commit 958f90e

Please sign in to comment.