Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5800)

Unified Diff: chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/bucket_manager_test.py

Issue 16855010: Python Tools for Pixel-by-Pixel Image Comparison (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Set up folder structure, added bucket manager and tests. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/bucket_manager_test.py
diff --git a/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/bucket_manager_test.py b/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/bucket_manager_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..e878adb0f979ea84a5546cd7c79172e033c36538
--- /dev/null
+++ b/chrome/test/functional/ispy/ispy_core/Tests/BucketManagerTests/bucket_manager_test.py
@@ -0,0 +1,228 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+from PIL import Image
+
+from Tests.BucketManagerTests.DependancyInjection import boto_testing_injector
+from Tools import bucket_manager
+from Tools import image_tools
+
+
+class BucketManagerTest(unittest.TestCase):
+
+ def setUp(self):
+ self.injector = boto_testing_injector.TestingInjector()
+ self.manager = bucket_manager.Manager(self.injector)
+ self.white = Image.new('RGB', (25, 25), (255, 255, 255))
+ self.red = Image.new('RGB', (25, 25), (255, 0, 0))
+ self.black = Image.new('RGB', (25, 25), (0, 0, 0))
+
+ def testAuthenticateBucket(self):
+ self.injector.reset()
+# after calling authenticate bucket, ensure that all the functions:
+# storage_uri, connect, and get_bucket are called.
+ bucket = self.manager._AuthenticateBucket('bucket', 'key', 'secret')
+
+ self.assertTrue(
+ bucket.connection and
+ bucket.uri and
+ bucket.bucket_name == 'bucket' and
+ bucket.uri.uri_str == '' and
+ bucket.uri.default_scheme == 'gs' and
+ bucket.key == 'key' and
+ bucket.secret == 'secret'
+ )
+
+ def testGetConnection(self):
+ self.injector.reset()
+# set up two buckets that should be the same.
+ bucket_name = bucket_manager.BUCKET
+ key = bucket_manager.KEY
+ secret = bucket_manager.SECRET
+ bucket1 = self.manager._AuthenticateBucket(bucket_name, key, secret)
+ bucket2 = self.manager._GetConnection()
+# test that they have the same secret and key.
+ self.assertTrue(
+ bucket1.secret == bucket2.secret and
+ bucket2.key == bucket2.key
+ )
+
+ def testMakeKeyToFile(self):
+ self.injector.reset()
+
+# put a key in the database
+ bucket = self.manager._GetConnection()
+ key = self.injector.get_key(bucket)
+ key.set_path('path/to/cats')
+ key.set_contents_from_string('cat, cat, cat')
+
+# create a new key, and check that it already exists.
+ key = self.manager.MakeKeyToFile('path/to/cats')
+ self.assertEquals(key.path, 'path/to/cats')
+ self.assertTrue(key.exists())
+# create a new key that shouldn't already exist in the database.
+ key2 = self.manager.MakeKeyToFile('path/to/dogs')
+ self.assertEquals(key2.path, 'path/to/dogs')
+ self.assertFalse(key2.exists())
+
+ def testGetKeyToFile(self):
+ self.injector.reset()
+# set up a key in the database.
+ bucket = self.manager._GetConnection()
+ key = self.injector.get_key(bucket)
+ key.set_path('path/to/cats')
+ key.set_contents_from_string('tabby, siamese, bengle')
+# attempt to get the created key, should work.
+ key = self.manager.GetKeyToFile('path/to/cats')
+ self.assertEquals(key.path, 'path/to/cats')
+ self.assertTrue(key.exists())
+# attempt to get a key that doesn't exist in the database, should error.
+ self.assertRaises(
+ bucket_manager.NotFoundException,
+ self.manager.GetKeyToFile,
+ 'path/that/doesnt/exist'
+ )
+
+ def testUploadImage(self):
+ self.injector.reset()
+# set up a black image and upload it to the datastore.
+ self.manager.UploadImage('path/to/image.png', self.black)
+# confirm that the key
+ key = self.manager.GetKeyToFile('path/to/image.png')
+ self.assertIsNotNone(key)
+ self.assertEquals(
+ key.get_contents_as_string(),
+ image_tools.SerializeImage(self.black).decode('base64')
+ )
+
+ def testUploadTest(self):
+ self.injector.reset()
+# put the images into the datastore
+ self.manager.UploadTest('test', [self.white, self.black])
+# retreive the images
+ expected = self.manager.GetKeyToFile('Tests/test_expected.png')
+ mask = self.manager.GetKeyToFile('Tests/test_mask.png')
+# assert that white is the expected image and the mask image,
+# and that both images have proper meta-data.
+ self.assertEquals(
+ image_tools.SerializeImage(self.white).decode('base64'),
+ expected.contents)
+ self.assertEquals(expected.meta_data['Content-Type'], 'image/png')
+ self.assertEquals(
+ image_tools.SerializeImage(self.white).decode('base64'),
+ mask.contents)
+ self.assertEquals(mask.meta_data['Content-Type'], 'image/png')
+
+ def testUploadResult(self):
+ self.injector.reset()
+# set up the images to conduct the test.
+ expected = self.black
+ diff = self.white
+ actual = self.red
+# upload the images.
+ self.manager.UploadResult('test', 'testrun', expected, diff, actual)
+
+# collect the images from the datastore
+ ds_expected = self.manager.GetKeyToFile('Results/test/testrun/expected.png')
+ ds_diff = self.manager.GetKeyToFile('Results/test/testrun/diff.png')
+ ds_actual = self.manager.GetKeyToFile('Results/test/testrun/actual.png')
+
+# compare the datastore images with the originals
+
+ self.assertTrue(
+ image_tools.SerializeImage(expected) ==
+ ds_expected.get_contents_as_string().encode('base64') and
+ image_tools.SerializeImage(diff) ==
+ ds_diff.get_contents_as_string().encode('base64') and
+ image_tools.SerializeImage(actual) ==
+ ds_actual.get_contents_as_string().encode('base64'))
+
+ def testGetTest(self):
+ self.injector.reset()
+# set up and upload the test to the datastore
+ self.manager.UploadTest('bigtest', [self.white, self.black])
+# attempt to get the test that was uploaded
+ test = self.manager.GetTest('bigtest')
+# check that the expected and mask images match what should be uploaded
+ mask = image_tools.CreateMask([self.white, self.black])
+ expected = self.white
+ self.assertTrue(
+ image_tools.SameImage(mask, test['mask']) and
+ image_tools.SameImage(expected, test['expected'])
+ )
+
+# now check that the GetTest call throws NotFoundException.
+ self.assertRaises(
+ bucket_manager.NotFoundException,
+ self.manager.GetTest,
+ 'faketest'
+ )
+
+ def testGetResult(self):
+ self.injector.reset()
+# upload the result
+ self.manager.UploadResult('bigtest', 'color-run',
+ self.black, self.white, self.red)
+# get the urls to the result's images.
+ result = self.manager.GetResult('bigtest', 'color-run')
+# check that they are correct.
+ self.assertTrue(
+ result['expected'] == 'Results/bigtest/color-run/expected.png' and
+ result['diff'] == 'Results/bigtest/color-run/diff.png' and
+ result['actual'] == 'Results/bigtest/color-run/actual.png'
+ )
+# try to get some results that don't exist.
+ self.assertRaises(
+ bucket_manager.NotFoundException,
+ self.manager.GetResult,
+ 'littletest',
+ 'color-run'
+ )
+ self.assertRaises(
+ bucket_manager.NotFoundException,
+ self.manager.GetResult,
+ 'bigtest',
+ 'greyscale-run'
+ )
+
+ def testGetURL(self):
+ self.injector.reset()
+# set up image to get a url to
+ self.manager.UploadImage('path/to/image.png', self.white)
+# assert that url is correct, note that the testing injector
+# provides the path as the url.
+ self.assertTrue(
+ self.manager.GetURL('path/to/image.png') == 'path/to/image.png'
+ )
+# attempt to get a url to a file that doesn't exist.
+ self.assertRaises(
+ bucket_manager.NotFoundException,
+ self.manager.GetURL,
+ 'i/dont/exist.png'
+ )
+
+ def testGetAllKeys(self):
+ self.injector.reset()
+# populate the datastore with some keys
+ self.manager.UploadImage('image/red.png', self.red)
+ self.manager.UploadImage('image/special/black.png', self.black)
+ self.manager.UploadImage('image/white.png', self.white)
+
+# access the keys to these images, and confirm they are correct
+ self.assertTrue(
+ len(self.manager.GetAllKeys(prefix='image')) == 3
+ )
+ self.assertTrue(
+ len(self.manager.GetAllKeys(prefix='image/special')) == 1
+ )
+ self.assertTrue(
+ len(self.manager.GetAllKeys(prefix='')) == 3
+ )
+ self.assertTrue(
+ len(self.manager.GetAllKeys(prefix='notimage')) == 0
+ )
+
+if __name__ == '__main__':
+ unittest.main()

Powered by Google App Engine
This is Rietveld 408576698