Skip to content

Commit

Permalink
Cleanup RGBa ctor, and fix system test typo.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 19, 2017
1 parent 2aaec55 commit 1bcd5dd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
5 changes: 1 addition & 4 deletions system_tests/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,7 @@ def _assert_color(self, color):
self.assertIsInstance(color.red, (int, float))
self.assertIsInstance(color.green, (int, float))
self.assertIsInstance(color.blue, (int, float))
if not isinstance(color.alpha, float):
self.assertIsInstance(color.alpha.value, float)
else:
self.assertIsInstance(color.alpha, float)
self.assertIsInstance(color.alpha, float)
self.assertNotEqual(color.red, 0.0)
self.assertNotEqual(color.green, 0.0)
self.assertNotEqual(color.blue, 0.0)
Expand Down
15 changes: 5 additions & 10 deletions vision/google/cloud/vision/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def from_pb(cls, image_properties):
:returns: List of ``ImagePropertiesAnnotation``.
"""
colors = getattr(image_properties.dominant_colors, 'colors', ())
if len(colors) == 0:
return ()
return [cls([ColorInformation.from_pb(color) for color in colors])]
if len(colors) > 0:
return [cls([ColorInformation.from_pb(color) for color in colors])]

@property
def colors(self):
Expand Down Expand Up @@ -115,17 +114,13 @@ def from_api_repr(cls, response):
def from_pb(cls, color):
"""Factory: construct a ``Color`` from a protobuf response.
:type color: :class:`~google.type.color_pb2`
:type color: :module: `google.type.color_pb2`
:param color: ``Color`` from API Response.
:rtype: :class:`~google.cloud.vision.color.Color`
:returns: Instance of :class:`~google.cloud.vision.color.Color`.
"""
red = getattr(color, 'red', 0.0)
green = getattr(color, 'green', 0.0)
blue = getattr(color, 'blue', 0.0)
alpha = getattr(color.alpha, 'value', 0.0)
return cls(red, green, blue, alpha)
return cls(color.red, color.green, color.blue, color.alpha.value)

@property
def red(self):
Expand Down Expand Up @@ -192,7 +187,7 @@ def from_api_repr(cls, color_information):
:rtype: :class:`~google.cloud.vision.color.ColorInformation`
:returns: Instance of ``ColorInformation``.
"""
color = Color.from_api_repr(color_information.get('color'))
color = Color.from_api_repr(color_information.get('color', {}))
score = color_information.get('score')
pixel_fraction = color_information.get('pixelFraction')
return cls(color, score, pixel_fraction)
Expand Down
2 changes: 1 addition & 1 deletion vision/unit_tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_from_pb(self):
self.assertEqual(annotations.landmarks, [])
self.assertEqual(annotations.texts, [])
self.assertEqual(annotations.safe_searches, ())
self.assertEqual(annotations.properties, ())
self.assertIsNone(annotations.properties)


class Test__make_entity_from_pb(unittest.TestCase):
Expand Down

0 comments on commit 1bcd5dd

Please sign in to comment.