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

Side by Side Diff: gm/rebaseline_server/imagediffdb_test.py

Issue 397103003: combine base_unittest.py modules from gm and tools (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: everything but pylint cleanup Created 6 years, 5 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 unified diff | Download patch
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2013 Google Inc. 4 Copyright 2013 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Test imagediffdb.py 9 Test imagediffdb.py
10 """ 10 """
11 11
12 # System-level imports 12 # System-level imports
13 import logging 13 import logging
14 import shutil 14 import shutil
15 import tempfile 15 import tempfile
16 import unittest 16 import unittest
17 17
18 # Local imports 18 # Local imports
19 import imagediffdb 19 import imagediffdb
20 20
21 21
22 IMG_URL_BASE = ('http://chromium-skia-gm.commondatastorage.googleapis.com/gm/' 22 IMG_URL_BASE = ('http://chromium-skia-gm.commondatastorage.googleapis.com/gm/'
23 'bitmap-64bitMD5/') 23 'bitmap-64bitMD5/')
24 24
25 25
26 class ImageDiffDbTest(unittest.TestCase): 26 class ImageDiffDbTest(unittest.TestCase):
27 27
28 def setUp(self): 28 def setUp(self):
29 self._temp_dir = tempfile.mkdtemp() 29 self.temp_dir = tempfile.mkdtemp()
30 self.maxDiff = None 30 self.maxDiff = None
31 31
32 def tearDown(self): 32 def tearDown(self):
33 shutil.rmtree(self._temp_dir) 33 shutil.rmtree(self.temp_dir)
34 34
35 def shortDescription(self): 35 def shortDescription(self):
36 """Tell unittest framework to not print docstrings for test cases.""" 36 """Tell unittest framework to not print docstrings for test cases."""
37 return None 37 return None
38 38
39 def test_sanitize_locator(self): 39 def test_sanitize_locator(self):
40 """Test _sanitize_locator().""" 40 """Test _sanitize_locator()."""
41 self.assertEqual(imagediffdb._sanitize_locator('simple'), 'simple') 41 self.assertEqual(imagediffdb._sanitize_locator('simple'), 'simple')
42 self.assertEqual(imagediffdb._sanitize_locator(1234), '1234') 42 self.assertEqual(imagediffdb._sanitize_locator(1234), '1234')
43 self.assertEqual(imagediffdb._sanitize_locator('one/two'), 'one_two') 43 self.assertEqual(imagediffdb._sanitize_locator('one/two'), 'one_two')
(...skipping 25 matching lines...) Expand all
69 [ 69 [
70 'gradients_degenerate_2pt/10552995703607727960', 70 'gradients_degenerate_2pt/10552995703607727960',
71 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png', 71 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
72 'gradients_degenerate_2pt/11198253335583713230', 72 'gradients_degenerate_2pt/11198253335583713230',
73 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png', 73 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
74 '100.0000', '100.0000', [255, 0, 255], 74 '100.0000', '100.0000', [255, 0, 255],
75 ], 75 ],
76 ] 76 ]
77 77
78 # Add all image pairs to the database 78 # Add all image pairs to the database
79 db = imagediffdb.ImageDiffDB(self._temp_dir) 79 db = imagediffdb.ImageDiffDB(self.temp_dir)
80 for selftest in selftests: 80 for selftest in selftests:
81 retval = db.add_image_pair( 81 retval = db.add_image_pair(
82 expected_image_locator=selftest[0], expected_image_url=selftest[1], 82 expected_image_locator=selftest[0], expected_image_url=selftest[1],
83 actual_image_locator=selftest[2], actual_image_url=selftest[3]) 83 actual_image_locator=selftest[2], actual_image_url=selftest[3])
84 84
85 # Fetch each image pair from the database 85 # Fetch each image pair from the database
86 for selftest in selftests: 86 for selftest in selftests:
87 record = db.get_diff_record(expected_image_locator=selftest[0], 87 record = db.get_diff_record(expected_image_locator=selftest[0],
88 actual_image_locator=selftest[2]) 88 actual_image_locator=selftest[2])
89 self.assertEqual('%.4f' % record.get_percent_pixels_differing(), 89 self.assertEqual('%.4f' % record.get_percent_pixels_differing(),
90 selftest[4]) 90 selftest[4])
91 self.assertEqual('%.4f' % record.get_perceptual_difference(), selftest[5]) 91 self.assertEqual('%.4f' % record.get_perceptual_difference(), selftest[5])
92 self.assertEqual(record.get_max_diff_per_channel(), selftest[6]) 92 self.assertEqual(record.get_max_diff_per_channel(), selftest[6])
93 93
94 94
95 def main(): 95 def main():
96 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest) 96 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest)
97 unittest.TextTestRunner(verbosity=2).run(suite) 97 unittest.TextTestRunner(verbosity=2).run(suite)
98 98
99 99
100 if __name__ == '__main__': 100 if __name__ == '__main__':
101 main() 101 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698