diff --git a/system_tests/vision.py b/system_tests/vision.py index f23f0a275b6e..c831b469b1d6 100644 --- a/system_tests/vision.py +++ b/system_tests/vision.py @@ -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) diff --git a/vision/google/cloud/vision/color.py b/vision/google/cloud/vision/color.py index 2d060977ff51..5a4370d94bb8 100644 --- a/vision/google/cloud/vision/color.py +++ b/vision/google/cloud/vision/color.py @@ -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): @@ -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): @@ -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) diff --git a/vision/unit_tests/test_annotations.py b/vision/unit_tests/test_annotations.py index 4ea57988174f..e2786b6a0fd0 100644 --- a/vision/unit_tests/test_annotations.py +++ b/vision/unit_tests/test_annotations.py @@ -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):