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

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

Issue 856103002: Revert "Revert "delete old things!"" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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 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
(Empty)
1 #!/usr/bin/python
2
3 """
4 Copyright 2013 Google Inc.
5
6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file.
8
9 Test imagediffdb.py
10 """
11
12 # System-level imports
13 import shutil
14 import tempfile
15 import unittest
16
17 # Local imports
18 import imagediffdb
19
20
21 IMG_URL_BASE = ('http://chromium-skia-gm.commondatastorage.googleapis.com/gm/'
22 'bitmap-64bitMD5/')
23
24
25 class ImageDiffDbTest(unittest.TestCase):
26
27 def setUp(self):
28 self.temp_dir = tempfile.mkdtemp()
29 self.maxDiff = None
30
31 def tearDown(self):
32 shutil.rmtree(self.temp_dir)
33
34 def shortDescription(self):
35 """Tell unittest framework to not print docstrings for test cases."""
36 return None
37
38 def test_sanitize_locator(self):
39 """Test _sanitize_locator()."""
40 # pylint: disable=W0212
41 self.assertEqual(imagediffdb._sanitize_locator('simple'), 'simple')
42 self.assertEqual(imagediffdb._sanitize_locator(1234), '1234')
43 self.assertEqual(imagediffdb._sanitize_locator('one/two'), 'one_two')
44 self.assertEqual(imagediffdb._sanitize_locator('one\\two'), 'one_two')
45 self.assertEqual(imagediffdb._sanitize_locator('one_two'), 'one_two')
46
47 def test_simple(self):
48 """Test ImageDiffDB, downloading real known images from Google Storage.
49
50 TODO(epoger): Instead of hitting Google Storage, we should read image
51 files from local disk using a file:// IMG_URL_BASE.
52 """
53 # params for each self-test:
54 # 0. expected image locator
55 # 1. expected image URL
56 # 2. actual image locator
57 # 3. actual image URL
58 # 4. expected percent_pixels_differing (as a string, to 4 decimal places)
59 # 5. expected perceptual difference (as a string, to 4 decimal places)
60 # 6. expected max_diff_per_channel
61 selftests = [
62 [
63 'arcofzorro/16206093933823793653',
64 IMG_URL_BASE + 'arcofzorro/16206093933823793653.png',
65 'arcofzorro/13786535001616823825',
66 IMG_URL_BASE + 'arcofzorro/13786535001616823825.png',
67 '0.0662', '0.0662', [255, 255, 247],
68 ],
69 [
70 'gradients_degenerate_2pt/10552995703607727960',
71 IMG_URL_BASE + 'gradients_degenerate_2pt/10552995703607727960.png',
72 'gradients_degenerate_2pt/11198253335583713230',
73 IMG_URL_BASE + 'gradients_degenerate_2pt/11198253335583713230.png',
74 '100.0000', '100.0000', [255, 0, 255],
75 ],
76 ]
77
78 # Add all image pairs to the database
79 db = imagediffdb.ImageDiffDB(self.temp_dir)
80 for selftest in selftests:
81 db.add_image_pair(
82 expected_image_locator=selftest[0], expected_image_url=selftest[1],
83 actual_image_locator=selftest[2], actual_image_url=selftest[3])
84
85 # Fetch each image pair from the database
86 for selftest in selftests:
87 record = db.get_diff_record(expected_image_locator=selftest[0],
88 actual_image_locator=selftest[2])
89 self.assertEqual('%.4f' % record.get_percent_pixels_differing(),
90 selftest[4])
91 self.assertEqual('%.4f' % record.get_perceptual_difference(), selftest[5])
92 self.assertEqual(record.get_max_diff_per_channel(), selftest[6])
93
94
95 def main():
96 suite = unittest.TestLoader().loadTestsFromTestCase(ImageDiffDbTest)
97 unittest.TextTestRunner(verbosity=2).run(suite)
98
99
100 if __name__ == '__main__':
101 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