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
This commit is contained in:
commit-bot@chromium.org 2014-01-06 18:33:19 +00:00
parent 91e3ffded5
commit 2a78e82f5e
3 changed files with 92 additions and 49 deletions

View File

@ -7,22 +7,34 @@ 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/'
def main():
logging.basicConfig(level=logging.INFO)
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
@ -34,22 +46,22 @@ def main():
selftests = [
[
'16206093933823793653',
IMAGE_URL_BASE + 'arcofzorro/16206093933823793653.png',
IMG_URL_BASE + 'arcofzorro/16206093933823793653.png',
'13786535001616823825',
IMAGE_URL_BASE + 'arcofzorro/13786535001616823825.png',
IMG_URL_BASE + 'arcofzorro/13786535001616823825.png',
'0.0662', '0.0113', [255, 255, 247],
],
[
'10552995703607727960',
IMAGE_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
'11198253335583713230',
IMAGE_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
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('/tmp/ImageDiffDB')
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],
@ -59,10 +71,15 @@ def main():
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!")
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():
suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest)
unittest.TextTestRunner(verbosity=2).run(suite)
if __name__ == '__main__':

View File

@ -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(

View File

@ -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()