diff options
author | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-06 18:33:19 +0000 |
---|---|---|
committer | commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2014-01-06 18:33:19 +0000 |
commit | 2a78e82f5eb82c3832231e36957110044b0783b3 (patch) | |
tree | 6cbf708dfc3c6c7fc0df2229317b96093e14c3da /gm/rebaseline_server | |
parent | 91e3ffded5a2e7fd2ca902eea6dc75d48b97e28e (diff) |
create gm/rebaseline_server/test_all.py
Uses proper Python unittest framework to launch all unittests within the directory.
NOTRY=True
R=rmistry@google.com
Author: epoger@google.com
Review URL: https://codereview.chromium.org/125253002
git-svn-id: http://skia.googlecode.com/svn/trunk@12915 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'gm/rebaseline_server')
-rwxr-xr-x | gm/rebaseline_server/imagediffdb_test.py | 107 | ||||
-rwxr-xr-x | gm/rebaseline_server/results_test.py | 8 | ||||
-rwxr-xr-x | gm/rebaseline_server/test_all.py | 26 |
3 files changed, 92 insertions, 49 deletions
diff --git a/gm/rebaseline_server/imagediffdb_test.py b/gm/rebaseline_server/imagediffdb_test.py index 9d0dc0de06..b76a2c0898 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__': diff --git a/gm/rebaseline_server/results_test.py b/gm/rebaseline_server/results_test.py index e5f969c5ea..8263f58920 100755 --- a/gm/rebaseline_server/results_test.py +++ b/gm/rebaseline_server/results_test.py @@ -8,10 +8,6 @@ found in the LICENSE file. Test results.py -TODO(epoger): Launch this (and other unittests within this dir) automatically -on the housekeeper bot, but first make sure it works properly after having been -checked out (from both git and svn) - TODO(epoger): Create a command to update the expected results (in OUTPUT_DIR_EXPECTED) when appropriate. For now, you should: 1. examine the results in OUTPUT_DIR_ACTUAL and make sure they are ok @@ -67,6 +63,10 @@ class ResultsTest(unittest.TestCase): ('found differing files between actual dir %s and expected dir %s: %s' % (self._output_dir_actual, self._output_dir_expected, different_files)) + def shortDescription(self): + """Tell unittest framework to not print docstrings for test cases.""" + return None + def test_gm(self): """Process results of a GM run with the Results object.""" results_obj = results.Results( diff --git a/gm/rebaseline_server/test_all.py b/gm/rebaseline_server/test_all.py new file mode 100755 index 0000000000..ba3d8fdbe0 --- /dev/null +++ b/gm/rebaseline_server/test_all.py @@ -0,0 +1,26 @@ +#!/usr/bin/python + +""" +Copyright 2014 Google Inc. + +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. + +Run all unittests within this directory tree, recursing into subdirectories. + +TODO(epoger): Launch this automatically on the housekeeper bot, but first make +sure it works properly after having been checked out (from both git and svn) +""" + +import os +import unittest + + +def main(): + suite = unittest.TestLoader().discover(os.path.dirname(__file__), + pattern='*_test.py') + unittest.TextTestRunner(verbosity=2).run(suite) + + +if __name__ == '__main__': + main() |