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

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

Issue 157593006: rebaseline_server: add ImagePair class, a step towards new intermediate JSON schema (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: style fix Created 6 years, 10 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
« no previous file with comments | « gm/rebaseline_server/imagediffdb.py ('k') | gm/rebaseline_server/imagepair.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bitm ap-64bitMD5/' 22 IMG_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitm ap-64bitMD5/'
23 23
24 24
25 class ImageDiffDbTest(unittest.TestCase): 25 class ImageDiffDbTest(unittest.TestCase):
26 26
27 def setUp(self): 27 def setUp(self):
28 self._temp_dir = tempfile.mkdtemp() 28 self._temp_dir = tempfile.mkdtemp()
29 self.maxDiff = None
29 30
30 def tearDown(self): 31 def tearDown(self):
31 shutil.rmtree(self._temp_dir) 32 shutil.rmtree(self._temp_dir)
32 33
33 def shortDescription(self): 34 def shortDescription(self):
34 """Tell unittest framework to not print docstrings for test cases.""" 35 """Tell unittest framework to not print docstrings for test cases."""
35 return None 36 return None
36 37
38 def test_sanitize_locator(self):
39 """Test _sanitize_locator()."""
40 self.assertEqual(imagediffdb._sanitize_locator('simple'), 'simple')
41 self.assertEqual(imagediffdb._sanitize_locator(1234), '1234')
42 self.assertEqual(imagediffdb._sanitize_locator('one/two'), 'one_two')
43 self.assertEqual(imagediffdb._sanitize_locator('one\\two'), 'one_two')
44 self.assertEqual(imagediffdb._sanitize_locator('one_two'), 'one_two')
45
37 def test_simple(self): 46 def test_simple(self):
47 """Test ImageDiffDB, downloading real known images from Google Storage.
48
49 TODO(epoger): Instead of hitting Google Storage, we should read image
50 files from local disk using a file:// IMG_URL_BASE.
51 """
38 # params for each self-test: 52 # params for each self-test:
39 # 0. expected image locator 53 # 0. expected image locator
40 # 1. expected image URL 54 # 1. expected image URL
41 # 2. actual image locator 55 # 2. actual image locator
42 # 3. actual image URL 56 # 3. actual image URL
43 # 4. expected percent_pixels_differing (as a string, to 4 decimal places) 57 # 4. expected percent_pixels_differing (as a string, to 4 decimal places)
44 # 5. expected weighted_diff_measure (as a string, to 4 decimal places) 58 # 5. expected weighted_diff_measure (as a string, to 4 decimal places)
45 # 6. expected max_diff_per_channel 59 # 6. expected max_diff_per_channel
46 selftests = [ 60 selftests = [
47 [ 61 [
48 '16206093933823793653', 62 'arcofzorro/16206093933823793653',
49 IMG_URL_BASE + 'arcofzorro/16206093933823793653.png', 63 IMG_URL_BASE + 'arcofzorro/16206093933823793653.png',
50 '13786535001616823825', 64 'arcofzorro/13786535001616823825',
51 IMG_URL_BASE + 'arcofzorro/13786535001616823825.png', 65 IMG_URL_BASE + 'arcofzorro/13786535001616823825.png',
52 '0.0662', '0.0113', [255, 255, 247], 66 '0.0662', '0.0113', [255, 255, 247],
53 ], 67 ],
54 [ 68 [
55 '10552995703607727960', 69 'gradients_degenerate_2pt/10552995703607727960',
56 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png', 70 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
57 '11198253335583713230', 71 'gradients_degenerate_2pt/11198253335583713230',
58 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png', 72 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
59 '100.0000', '66.6667', [255, 0, 255], 73 '100.0000', '66.6667', [255, 0, 255],
60 ], 74 ],
61 ] 75 ]
62 76
63 # Add all image pairs to the database 77 # Add all image pairs to the database
64 db = imagediffdb.ImageDiffDB(self._temp_dir) 78 db = imagediffdb.ImageDiffDB(self._temp_dir)
65 for selftest in selftests: 79 for selftest in selftests:
66 retval = db.add_image_pair( 80 retval = db.add_image_pair(
67 expected_image_locator=selftest[0], expected_image_url=selftest[1], 81 expected_image_locator=selftest[0], expected_image_url=selftest[1],
68 actual_image_locator=selftest[2], actual_image_url=selftest[3]) 82 actual_image_locator=selftest[2], actual_image_url=selftest[3])
69 83
70 # Fetch each image pair from the database 84 # Fetch each image pair from the database
71 for selftest in selftests: 85 for selftest in selftests:
72 record = db.get_diff_record(expected_image_locator=selftest[0], 86 record = db.get_diff_record(expected_image_locator=selftest[0],
73 actual_image_locator=selftest[2]) 87 actual_image_locator=selftest[2])
74 self.assertEqual('%.4f' % record.get_percent_pixels_differing(), 88 self.assertEqual('%.4f' % record.get_percent_pixels_differing(),
75 selftest[4]) 89 selftest[4])
76 self.assertEqual('%.4f' % record.get_weighted_diff_measure(), selftest[5]) 90 self.assertEqual('%.4f' % record.get_weighted_diff_measure(), selftest[5])
77 self.assertEqual(record.get_max_diff_per_channel(), selftest[6]) 91 self.assertEqual(record.get_max_diff_per_channel(), selftest[6])
78 92
79 93
80 def main(): 94 def main():
81 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest) 95 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest)
82 unittest.TextTestRunner(verbosity=2).run(suite) 96 unittest.TextTestRunner(verbosity=2).run(suite)
83 97
84 98
85 if __name__ == '__main__': 99 if __name__ == '__main__':
86 main() 100 main()
OLDNEW
« no previous file with comments | « gm/rebaseline_server/imagediffdb.py ('k') | gm/rebaseline_server/imagepair.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698