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

Unified Diff: gm/rebaseline_server/imagediffdb_test.py

Issue 125253002: create gm/rebaseline_server/test_all.py (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix line length Created 6 years, 11 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
« no previous file with comments | « no previous file | gm/rebaseline_server/results_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/rebaseline_server/imagediffdb_test.py
diff --git a/gm/rebaseline_server/imagediffdb_test.py b/gm/rebaseline_server/imagediffdb_test.py
index 9d0dc0de0696fec5363f72ab9aa461f9e01e9803..b76a2c0898671a8f1c4938d73bc8cb337fd28904 100755
--- a/gm/rebaseline_server/imagediffdb_test.py
+++ b/gm/rebaseline_server/imagediffdb_test.py
@@ -7,62 +7,79 @@ Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
Test imagediffdb.py
-
-TODO(epoger): Modify to use Python's unittest framework.
"""
# System-level imports
import logging
+import shutil
+import tempfile
+import unittest
# Local imports
import imagediffdb
-IMAGE_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitmap-64bitMD5/'
+IMG_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitmap-64bitMD5/'
+
+
+class ImageDiffDbTest(unittest.TestCase):
+
+ def setUp(self):
+ self._temp_dir = tempfile.mkdtemp()
+
+ def tearDown(self):
+ shutil.rmtree(self._temp_dir)
+
+ def shortDescription(self):
+ """Tell unittest framework to not print docstrings for test cases."""
+ return None
+
+ def test_simple(self):
+ # params for each self-test:
+ # 0. expected image locator
+ # 1. expected image URL
+ # 2. actual image locator
+ # 3. actual image URL
+ # 4. expected percent_pixels_differing (as a string, to 4 decimal places)
+ # 5. expected weighted_diff_measure (as a string, to 4 decimal places)
+ # 6. expected max_diff_per_channel
+ selftests = [
+ [
+ '16206093933823793653',
+ IMG_URL_BASE + 'arcofzorro/16206093933823793653.png',
+ '13786535001616823825',
+ IMG_URL_BASE + 'arcofzorro/13786535001616823825.png',
+ '0.0662', '0.0113', [255, 255, 247],
+ ],
+ [
+ '10552995703607727960',
+ IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
+ '11198253335583713230',
+ IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
+ '100.0000', '66.6667', [255, 0, 255],
+ ],
+ ]
+
+ # Add all image pairs to the database
+ db = imagediffdb.ImageDiffDB(self._temp_dir)
+ for selftest in selftests:
+ retval = db.add_image_pair(
+ expected_image_locator=selftest[0], expected_image_url=selftest[1],
+ actual_image_locator=selftest[2], actual_image_url=selftest[3])
+
+ # Fetch each image pair from the database
+ for selftest in selftests:
+ record = db.get_diff_record(expected_image_locator=selftest[0],
+ actual_image_locator=selftest[2])
+ self.assertEqual('%.4f' % record.get_percent_pixels_differing(),
+ selftest[4])
+ self.assertEqual('%.4f' % record.get_weighted_diff_measure(), selftest[5])
+ self.assertEqual(record.get_max_diff_per_channel(), selftest[6])
+
def main():
- logging.basicConfig(level=logging.INFO)
-
- # params for each self-test:
- # 0. expected image locator
- # 1. expected image URL
- # 2. actual image locator
- # 3. actual image URL
- # 4. expected percent_pixels_differing (as a string, to 4 decimal places)
- # 5. expected weighted_diff_measure (as a string, to 4 decimal places)
- # 6. expected max_diff_per_channel
- selftests = [
- [
- '16206093933823793653',
- IMAGE_URL_BASE + 'arcofzorro/16206093933823793653.png',
- '13786535001616823825',
- IMAGE_URL_BASE + 'arcofzorro/13786535001616823825.png',
- '0.0662', '0.0113', [255, 255, 247],
- ],
- [
- '10552995703607727960',
- IMAGE_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
- '11198253335583713230',
- IMAGE_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
- '100.0000', '66.6667', [255, 0, 255],
- ],
- ]
-
- # Add all image pairs to the database
- db = imagediffdb.ImageDiffDB('/tmp/ImageDiffDB')
- for selftest in selftests:
- retval = db.add_image_pair(
- expected_image_locator=selftest[0], expected_image_url=selftest[1],
- actual_image_locator=selftest[2], actual_image_url=selftest[3])
-
- # Fetch each image pair from the database
- for selftest in selftests:
- record = db.get_diff_record(expected_image_locator=selftest[0],
- actual_image_locator=selftest[2])
- assert (('%.4f' % record.get_percent_pixels_differing()) == selftest[4])
- assert (('%.4f' % record.get_weighted_diff_measure()) == selftest[5])
- assert (record.get_max_diff_per_channel() == selftest[6])
- logging.info("Self-test completed successfully!")
+ suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest)
+ unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':
« no previous file with comments | « no previous file | gm/rebaseline_server/results_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698