Skip to content

Commit 867a359

Browse files
authored
Merge pull request googleapis#2839 from daspecster/vision-image-properties-system-tests
Add Vision detect_properties() system tests.
2 parents 6375e1f + df7c3c8 commit 867a359

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

system_tests/vision.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,65 @@ def test_detect_safe_search_filename(self):
392392
self.assertEqual(len(safe_searches), 1)
393393
safe_search = safe_searches[0]
394394
self._assert_safe_search(safe_search)
395+
396+
397+
class TestVisionClientImageProperties(BaseVisionTestCase):
398+
def setUp(self):
399+
self.to_delete_by_case = []
400+
401+
def tearDown(self):
402+
for value in self.to_delete_by_case:
403+
value.delete()
404+
405+
def _assert_color(self, color):
406+
self.assertIsInstance(color.red, int)
407+
self.assertIsInstance(color.green, int)
408+
self.assertIsInstance(color.blue, int)
409+
self.assertNotEqual(color.red, 0.0)
410+
self.assertNotEqual(color.green, 0.0)
411+
self.assertNotEqual(color.blue, 0.0)
412+
self.assertIsInstance(color.alpha, float)
413+
414+
def _assert_properties(self, image_property):
415+
from google.cloud.vision.color import ImagePropertiesAnnotation
416+
417+
self.assertIsInstance(image_property, ImagePropertiesAnnotation)
418+
results = image_property.colors
419+
for color_info in results:
420+
self._assert_color(color_info.color)
421+
self.assertNotEqual(color_info.pixel_fraction, 0.0)
422+
self.assertNotEqual(color_info.score, 0.0)
423+
424+
def test_detect_properties_content(self):
425+
client = Config.CLIENT
426+
with open(FACE_FILE, 'rb') as image_file:
427+
image = client.image(content=image_file.read())
428+
properties = image.detect_properties()
429+
self.assertEqual(len(properties), 1)
430+
image_property = properties[0]
431+
self._assert_properties(image_property)
432+
433+
def test_detect_properties_gcs(self):
434+
bucket_name = Config.TEST_BUCKET.name
435+
blob_name = 'faces.jpg'
436+
blob = Config.TEST_BUCKET.blob(blob_name)
437+
self.to_delete_by_case.append(blob) # Clean-up.
438+
with open(FACE_FILE, 'rb') as file_obj:
439+
blob.upload_from_file(file_obj)
440+
441+
source_uri = 'gs://%s/%s' % (bucket_name, blob_name)
442+
443+
client = Config.CLIENT
444+
image = client.image(source_uri=source_uri)
445+
properties = image.detect_properties()
446+
self.assertEqual(len(properties), 1)
447+
image_property = properties[0]
448+
self._assert_properties(image_property)
449+
450+
def test_detect_properties_filename(self):
451+
client = Config.CLIENT
452+
image = client.image(filename=FACE_FILE)
453+
properties = image.detect_properties()
454+
self.assertEqual(len(properties), 1)
455+
image_property = properties[0]
456+
self._assert_properties(image_property)

0 commit comments

Comments
 (0)