Skip to content

Commit

Permalink
Return instance instead of list for ImagePropertiesAnnotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
daspecster committed Jan 19, 2017
1 parent 1bcd5dd commit ca14aec
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
12 changes: 3 additions & 9 deletions system_tests/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ def test_detect_properties_content(self):
with open(FACE_FILE, 'rb') as image_file:
image = client.image(content=image_file.read())
properties = image.detect_properties()
self.assertEqual(len(properties), 1)
image_property = properties[0]
self._assert_properties(image_property)
self._assert_properties(properties[0])

def test_detect_properties_gcs(self):
client = Config.CLIENT
Expand All @@ -514,14 +512,10 @@ def test_detect_properties_gcs(self):

image = client.image(source_uri=source_uri)
properties = image.detect_properties()
self.assertEqual(len(properties), 1)
image_property = properties[0]
self._assert_properties(image_property)
self._assert_properties(properties[0])

def test_detect_properties_filename(self):
client = Config.CLIENT
image = client.image(filename=FACE_FILE)
properties = image.detect_properties()
self.assertEqual(len(properties), 1)
image_property = properties[0]
self._assert_properties(image_property)
self._assert_properties(properties[0])
2 changes: 1 addition & 1 deletion vision/google/cloud/vision/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def _make_image_properties_from_pb(image_properties):
:rtype: list
:returns: List of ``ImageProperties``.
"""
return ImagePropertiesAnnotation.from_pb(image_properties)
return [ImagePropertiesAnnotation.from_pb(image_properties)]


def _entity_from_response_type(feature_type, results):
Expand Down
2 changes: 1 addition & 1 deletion vision/google/cloud/vision/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def from_pb(cls, image_properties):
"""
colors = getattr(image_properties.dominant_colors, 'colors', ())
if len(colors) > 0:
return [cls([ColorInformation.from_pb(color) for color in colors])]
return cls([ColorInformation.from_pb(color) for color in colors])

@property
def colors(self):
Expand Down
4 changes: 1 addition & 3 deletions vision/unit_tests/test_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,8 @@ def test_color_annotation_from_pb(self):
dominant_colors=dominant_colors)

color_info = self._get_target_class()
image_properties_result = color_info.from_pb(image_properties_pb)
image_properties = color_info.from_pb(image_properties_pb)

self.assertEqual(len(image_properties_result), 1)
image_properties = image_properties_result[0]
self.assertEqual(image_properties.colors[0].pixel_fraction, 1.0)
self.assertEqual(image_properties.colors[0].score, 1.0)
self.assertEqual(image_properties.colors[0].color.red, 1.0)
Expand Down

0 comments on commit ca14aec

Please sign in to comment.