Skip to content

Commit

Permalink
Merge pull request #2834 from daspecster/vision-landmark-system-tests
Browse files Browse the repository at this point in the history
Add Vision detect_landmarks() system tests.
  • Loading branch information
daspecster committed Dec 7, 2016
2 parents 5d6148e + 22560ab commit 3598a1e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Binary file added system_tests/data/landmark.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 59 additions & 1 deletion system_tests/vision.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
LOGO_FILE = os.path.join(_SYS_TESTS_DIR, 'data', 'logo.png')
FACE_FILE = os.path.join(_SYS_TESTS_DIR, 'data', 'faces.jpg')
LABEL_FILE = os.path.join(_SYS_TESTS_DIR, 'data', 'car.jpg')
LANDMARK_FILE = os.path.join(_SYS_TESTS_DIR, 'data', 'landmark.jpg')


class Config(object):
Expand Down Expand Up @@ -243,7 +244,6 @@ def tearDown(self):
value.delete()

def _assert_label(self, label):

self.assertIsInstance(label, EntityAnnotation)
self.assertIn(label.description, self.DESCRIPTIONS)
self.assertIsInstance(label.mid, six.text_type)
Expand Down Expand Up @@ -282,3 +282,61 @@ def test_detect_labels_filename(self):
self.assertEqual(len(labels), 10)
for label in labels:
self._assert_label(label)


class TestVisionClientLandmark(BaseVisionTestCase):
DESCRIPTIONS = ('Mount Rushmore')

def setUp(self):
self.to_delete_by_case = []

def tearDown(self):
for value in self.to_delete_by_case:
value.delete()

def _assert_landmark(self, landmark):
self.assertIsInstance(landmark, EntityAnnotation)
self.assertIn(landmark.description, self.DESCRIPTIONS)
self.assertEqual(len(landmark.locations), 1)
location = landmark.locations[0]
self._assert_coordinate(location.latitude)
self._assert_coordinate(location.longitude)
for vertex in landmark.bounds.vertices:
self._assert_coordinate(vertex.x_coordinate)
self._assert_coordinate(vertex.y_coordinate)
self.assertGreater(landmark.score, 0.2)
self.assertIsInstance(landmark.mid, six.text_type)

def test_detect_landmark_content(self):
client = Config.CLIENT
with open(LANDMARK_FILE, 'rb') as image_file:
image = client.image(content=image_file.read())
landmarks = image.detect_landmarks()
self.assertEqual(len(landmarks), 1)
landmark = landmarks[0]
self._assert_landmark(landmark)

def test_detect_landmark_gcs(self):
bucket_name = Config.TEST_BUCKET.name
blob_name = 'landmark.jpg'
blob = Config.TEST_BUCKET.blob(blob_name)
self.to_delete_by_case.append(blob) # Clean-up.
with open(LANDMARK_FILE, 'rb') as file_obj:
blob.upload_from_file(file_obj)

source_uri = 'gs://%s/%s' % (bucket_name, blob_name)

client = Config.CLIENT
image = client.image(source_uri=source_uri)
landmarks = image.detect_landmarks()
self.assertEqual(len(landmarks), 1)
landmark = landmarks[0]
self._assert_landmark(landmark)

def test_detect_landmark_filename(self):
client = Config.CLIENT
image = client.image(filename=LANDMARK_FILE)
landmarks = image.detect_landmarks()
self.assertEqual(len(landmarks), 1)
landmark = landmarks[0]
self._assert_landmark(landmark)

0 comments on commit 3598a1e

Please sign in to comment.