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

Side by Side Diff: gm/rebaseline_server/imagepair_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/imagepair.py ('k') | no next file » | 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 2014 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 imagepair.py
10 """
11
12 # System-level imports
13 import shutil
14 import tempfile
15 import unittest
16
17 # Local imports
18 import imagediffdb
19 import imagepair
20
21
22 IMG_URL_BASE = 'http://chromium-skia-gm.commondatastorage.googleapis.com/gm/bitm ap-64bitMD5/'
23
24
25 class ImagePairTest(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_endToEnd(self):
39 """Test ImagePair, using a real ImageDiffDB to download real images.
40
41 TODO(epoger): Either in addition to or instead of this end-to-end test,
42 we should perform some tests using either:
43 1. a mock ImageDiffDB, or
44 2. a real ImageDiffDB that doesn't hit Google Storage looking for input
45 image files (maybe a file:// IMG_URL_BASE)
46 """
47 # params for each self-test:
48 #
49 # inputs:
50 # 0. imageA_relative_URL
51 # 1. imageB_relative_URL
52 # 2. expectations dict
53 # 3. extra_columns dict
54 # expected output:
55 # 4. expected result of ImagePair.as_dict()
56 selftests = [
57 [
58 # inputs:
59 'arcofzorro/16206093933823793653.png',
60 'arcofzorro/16206093933823793653.png',
61 None,
62 {
63 'builder': 'MyBuilder',
64 'test': 'MyTest',
65 },
66 # expected output:
67 {
68 'extraColumnValues': {
69 'builder': 'MyBuilder',
70 'test': 'MyTest',
71 },
72 'imageAUrl': 'arcofzorro/16206093933823793653.png',
73 'imageBUrl': 'arcofzorro/16206093933823793653.png',
74 'isDifferent': False,
75 },
76 ],
77
78 [
79 # inputs:
80 'arcofzorro/16206093933823793653.png',
81 'arcofzorro/13786535001616823825.png',
82 None,
83 None,
84 # expected output:
85 {
86 'differenceData': {
87 'maxDiffPerChannel': [255, 255, 247],
88 'numDifferingPixels': 662,
89 'percentDifferingPixels': 0.0662,
90 'weightedDiffMeasure': 0.01127756555171088,
91 },
92 'imageAUrl': 'arcofzorro/16206093933823793653.png',
93 'imageBUrl': 'arcofzorro/13786535001616823825.png',
94 'isDifferent': True,
95 },
96 ],
97
98 [
99 # inputs:
100 'gradients_degenerate_2pt/10552995703607727960.png',
101 'gradients_degenerate_2pt/11198253335583713230.png',
102 {
103 'ignoreFailure': True,
104 'bugs': [1001, 1002],
105 },
106 {
107 'builder': 'MyBuilder',
108 'test': 'MyTest',
109 },
110 # expected output:
111 {
112 'differenceData': {
113 'maxDiffPerChannel': [255, 0, 255],
114 'numDifferingPixels': 102400,
115 'percentDifferingPixels': 100.00,
116 'weightedDiffMeasure': 66.66666666666667,
117 },
118 'expectationsData': {
119 'bugs': [1001, 1002],
120 'ignoreFailure': True,
121 },
122 'extraColumnValues': {
123 'builder': 'MyBuilder',
124 'test': 'MyTest',
125 },
126 'imageAUrl':
127 'gradients_degenerate_2pt/10552995703607727960.png',
128 'imageBUrl':
129 'gradients_degenerate_2pt/11198253335583713230.png',
130 'isDifferent': True,
131 },
132 ],
133 ]
134
135 db = imagediffdb.ImageDiffDB(self._temp_dir)
136 for selftest in selftests:
137 image_pair = imagepair.ImagePair(
138 image_diff_db=db,
139 base_url=IMG_URL_BASE,
140 imageA_relative_url=selftest[0],
141 imageB_relative_url=selftest[1],
142 expectations=selftest[2],
143 extra_columns=selftest[3])
144 self.assertEqual(image_pair.as_dict(), selftest[4])
145
146
147 def main():
148 suite = unittest.TestLoader().loadTestsFromTestCase(ImagePairTest)
149 unittest.TextTestRunner(verbosity=2).run(suite)
150
151
152 if __name__ == '__main__':
153 main()
OLDNEW
« no previous file with comments | « gm/rebaseline_server/imagepair.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698