Skip to content

Commit 958f90e

Browse files
committed
Add multiple result exception for GAX.
1 parent 069f700 commit 958f90e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

vision/google/cloud/vision/_gax.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def annotate(self, image, features):
5353
images = annotator_client.batch_annotate_images(requests)
5454
if len(images.responses) == 1:
5555
return Annotations.from_pb(images.responses[0])
56+
elif len(images.responses) > 1:
57+
raise ValueError('Multiple image processing is not yet supported.')
5658

5759

5860
def _to_gapic_feature(feature):

vision/unit_tests/test__gax.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ def test_annotate_no_results(self):
8282

8383
gax_api._annotator_client.batch_annotate_images.assert_called()
8484

85+
def test_annotate_multiple_results(self):
86+
from google.cloud.vision.feature import Feature
87+
from google.cloud.vision.feature import FeatureTypes
88+
from google.cloud.vision.image import Image
89+
90+
client = mock.Mock(spec_set=[])
91+
feature = Feature(FeatureTypes.LABEL_DETECTION, 5)
92+
image_content = b'abc 1 2 3'
93+
image = Image(client, content=image_content)
94+
with mock.patch('google.cloud.vision._gax.image_annotator_client.'
95+
'ImageAnnotatorClient'):
96+
gax_api = self._make_one(client)
97+
98+
mock_response = {
99+
'batch_annotate_images.return_value': mock.Mock(responses=[1, 2]),
100+
}
101+
102+
gax_api._annotator_client = mock.Mock(
103+
spec_set=['batch_annotate_images'], **mock_response)
104+
with mock.patch('google.cloud.vision._gax.Annotations'):
105+
with self.assertRaises(ValueError):
106+
gax_api.annotate(image, [feature])
107+
108+
gax_api._annotator_client.batch_annotate_images.assert_called()
109+
85110

86111
class Test__to_gapic_feature(unittest.TestCase):
87112
def _call_fut(self, feature):

0 commit comments

Comments
 (0)