-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Expect vision response data to have missing keys. #2761
Expect vision response data to have missing keys. #2761
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The majority of this PR seems unneeded? You are trying to prevent key errors that will never happen / have never been reported as happening.
Let's fix the actually reported bug and then discuss the rest after?
@@ -36,8 +36,9 @@ def from_api_repr(cls, response): | |||
:rtype: :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`. | |||
:returns: Populated instance of ``ImagePropertiesAnnotation``. | |||
""" | |||
colors = [ColorInformation.from_api_repr(color) for color in | |||
response['dominantColors']['colors']] | |||
raw_colors = response.get('dominantColors', {}).get('colors', []) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -61,12 +61,12 @@ def from_api_repr(cls, response): | |||
:returns: Instance of ``EntityAnnotation``. | |||
""" | |||
bounds = Bounds.from_api_repr(response.get('boundingPoly')) | |||
description = response['description'] | |||
locale = response.get('locale', None) | |||
description = response.get('description') |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -91,11 +91,13 @@ def from_api_repr(cls, response): | |||
:rtype: :class:`~google.cloud.vision.face.Emotions` | |||
:returns: Populated instance of `Emotions`. | |||
""" | |||
joy_likelihood = getattr(Likelihood, response['joyLikelihood']) | |||
sorrow_likelihood = getattr(Likelihood, response['sorrowLikelihood']) | |||
joy_likelihood = getattr(Likelihood, response.get('joyLikelihood')) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
class TestColorInformation(unittest.TestCase): | ||
@staticmethod | ||
def _get_target_class(): | ||
from google.cloud.vision.color import Color |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
OK, yeah I have trust issues after learning more about how protubuf treats 0 and null values. But yeah, later time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deal with the nit if you please. (Please squash before merging.)
return Color | ||
|
||
def test_rgb_color_data(self): | ||
COLORS = { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
8d79e62
to
fe85e0a
Compare
fe85e0a
to
ddc30eb
Compare
…y-values Expect vision response data to have missing keys.
Fixes #2757
I didn't add tests for the other classes, but I can if needed. Honestly, I'm not sure if and when to count on the data being there so my strategy was to try and default to
None
.