Skip to content

Commit

Permalink
Fix KeyError for unsupported annotation types. (#2961)
Browse files Browse the repository at this point in the history
* Fix KeyError for unsupported annotation types.
  • Loading branch information
daspecster authored Jan 30, 2017
1 parent 3584917 commit f822e44
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions vision/google/cloud/vision/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def from_api_repr(cls, response):
_KEY_MAP[feature_type]: _entity_from_response_type(
feature_type, annotation)
for feature_type, annotation in six.iteritems(response)
if feature_type in _KEY_MAP
}
return cls(**annotations)

Expand Down
9 changes: 9 additions & 0 deletions vision/unit_tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ def test_ctor(self):
self.assertEqual(annotations.safe_searches, [True])
self.assertEqual(annotations.texts, [True])

def test_unsupported_http_annotation(self):
returned = {
'responses': [
{'someMadeUpAnnotation': None},
],
}
annotation = self._get_target_class().from_api_repr(returned)
self.assertIsInstance(annotation, self._get_target_class())

def test_from_pb(self):
from google.cloud.vision.likelihood import Likelihood
from google.cloud.vision.safe_search import SafeSearchAnnotation
Expand Down

0 comments on commit f822e44

Please sign in to comment.