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

Side by Side Diff: chrome/test/functional/ispy/common/ispy_utils_unittest.py

Issue 58623002: [I-Spy] Add utilities to help manage expectations that track Chrome versions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nit: slight changes to a docstring Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/functional/ispy/common/ispy_utils.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
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os 5 import os
6 from PIL import Image 6 from PIL import Image
7 import sys 7 import sys
8 import unittest 8 import unittest
9 9
10 import cloud_bucket 10 import cloud_bucket
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 self.bucket.Reset() 67 self.bucket.Reset()
68 # Upload some images to the datastore. 68 # Upload some images to the datastore.
69 self.ispy_utils.UploadImage('path/to/image.png', self.white) 69 self.ispy_utils.UploadImage('path/to/image.png', self.white)
70 self.assertEquals(self.bucket.datastore['path/to/image.png'], 70 self.assertEquals(self.bucket.datastore['path/to/image.png'],
71 image_tools.EncodePNG(self.white)) 71 image_tools.EncodePNG(self.white))
72 self.ispy_utils.UpdateImage('path/to/image.png', self.black) 72 self.ispy_utils.UpdateImage('path/to/image.png', self.black)
73 # Confirm that the image actually got updated. 73 # Confirm that the image actually got updated.
74 self.assertEquals(self.bucket.datastore['path/to/image.png'], 74 self.assertEquals(self.bucket.datastore['path/to/image.png'],
75 image_tools.EncodePNG(self.black)) 75 image_tools.EncodePNG(self.black))
76 76
77 def testUploadExpectation(self): 77 def testGenerateExpectation(self):
78 self.bucket.Reset() 78 self.bucket.Reset()
79 # Upload some tests to the datastore. 79 # Upload some tests to the datastore.
80 self.ispy_utils.UploadExpectation('test', [self.white, self.black]) 80 self.ispy_utils.GenerateExpectation('test', [self.white, self.black])
81 self.ispy_utils.UploadExpectation('test1', [self.black, self.black]) 81 self.ispy_utils.GenerateExpectation('test1', [self.black, self.black])
82 # Confirm that the tests were successfully uploaded. 82 # Confirm that the tests were successfully uploaded.
83 self.assertEquals(self.bucket.datastore[ 83 self.assertEquals(self.bucket.datastore[
84 ispy_utils.GetExpectationPath('test', 'expected.png')], 84 ispy_utils.GetExpectationPath('test', 'expected.png')],
85 image_tools.EncodePNG(self.white)) 85 image_tools.EncodePNG(self.white))
86 self.assertEquals(self.bucket.datastore[ 86 self.assertEquals(self.bucket.datastore[
87 ispy_utils.GetExpectationPath('test', 'mask.png')], 87 ispy_utils.GetExpectationPath('test', 'mask.png')],
88 image_tools.EncodePNG(self.white)) 88 image_tools.EncodePNG(self.white))
89 self.assertEquals(self.bucket.datastore[ 89 self.assertEquals(self.bucket.datastore[
90 ispy_utils.GetExpectationPath('test1', 'expected.png')], 90 ispy_utils.GetExpectationPath('test1', 'expected.png')],
91 image_tools.EncodePNG(self.black)) 91 image_tools.EncodePNG(self.black))
92 self.assertEquals(self.bucket.datastore[ 92 self.assertEquals(self.bucket.datastore[
93 ispy_utils.GetExpectationPath('test1', 'mask.png')], 93 ispy_utils.GetExpectationPath('test1', 'mask.png')],
94 image_tools.EncodePNG(self.black)) 94 image_tools.EncodePNG(self.black))
95 95
96 def testRunTest(self): 96 def testPerformComparison(self):
97 self.bucket.Reset() 97 self.bucket.Reset()
98 self.ispy_utils.UploadExpectation('test1', [self.red, self.red]) 98 self.ispy_utils.GenerateExpectation('test1', [self.red, self.red])
99 self.ispy_utils.RunTest('test', 'test1', self.black) 99 self.ispy_utils.PerformComparison('test', 'test1', self.black)
100 self.assertEquals(self.bucket.datastore[ 100 self.assertEquals(self.bucket.datastore[
101 ispy_utils.GetFailurePath('test', 'test1', 'actual.png')], 101 ispy_utils.GetFailurePath('test', 'test1', 'actual.png')],
102 image_tools.EncodePNG(self.black)) 102 image_tools.EncodePNG(self.black))
103 self.ispy_utils.RunTest('test', 'test1', self.red) 103 self.ispy_utils.PerformComparison('test', 'test1', self.red)
104 self.assertTrue(self.bucket.datastore.has_key( 104 self.assertTrue(self.bucket.datastore.has_key(
105 ispy_utils.GetFailurePath('test', 'test1', 'actual.png'))) 105 ispy_utils.GetFailurePath('test', 'test1', 'actual.png')))
106 106
107 def testGetExpectation(self): 107 def testGetExpectation(self):
108 self.bucket.Reset() 108 self.bucket.Reset()
109 # Upload some tests to the datastore 109 # Upload some tests to the datastore
110 self.ispy_utils.UploadExpectation('test1', [self.white, self.black]) 110 self.ispy_utils.GenerateExpectation('test1', [self.white, self.black])
111 self.ispy_utils.UploadExpectation('test2', [self.red, self.white]) 111 self.ispy_utils.GenerateExpectation('test2', [self.red, self.white])
112 test1 = self.ispy_utils.GetExpectation('test1') 112 test1 = self.ispy_utils.GetExpectation('test1')
113 test2 = self.ispy_utils.GetExpectation('test2') 113 test2 = self.ispy_utils.GetExpectation('test2')
114 # Check that GetExpectation gets the appropriate tests. 114 # Check that GetExpectation gets the appropriate tests.
115 self.assertEquals(image_tools.EncodePNG(test1.expected), 115 self.assertEquals(image_tools.EncodePNG(test1.expected),
116 image_tools.EncodePNG(self.white)) 116 image_tools.EncodePNG(self.white))
117 self.assertEquals(image_tools.EncodePNG(test1.mask), 117 self.assertEquals(image_tools.EncodePNG(test1.mask),
118 image_tools.EncodePNG(self.white)) 118 image_tools.EncodePNG(self.white))
119 self.assertEquals(image_tools.EncodePNG(test2.expected), 119 self.assertEquals(image_tools.EncodePNG(test2.expected),
120 image_tools.EncodePNG(self.red)) 120 image_tools.EncodePNG(self.red))
121 self.assertEquals(image_tools.EncodePNG(test2.mask), 121 self.assertEquals(image_tools.EncodePNG(test2.mask),
122 image_tools.EncodePNG(self.white)) 122 image_tools.EncodePNG(self.white))
123 # Check that GetExpectation throws an error for a nonexistant test. 123 # Check that GetExpectation throws an error for a nonexistant test.
124 self.assertRaises( 124 self.assertRaises(
125 cloud_bucket.FileNotFoundError, self.ispy_utils.GetExpectation, 'test3') 125 cloud_bucket.FileNotFoundError, self.ispy_utils.GetExpectation, 'test3')
126 126
127 def testExpectationExists(self): 127 def testExpectationExists(self):
128 self.bucket.Reset() 128 self.bucket.Reset()
129 self.ispy_utils.UploadExpectation('test1', [self.white, self.black]) 129 self.ispy_utils.GenerateExpectation('test1', [self.white, self.black])
130 self.ispy_utils.UploadExpectation('test2', [self.white, self.black]) 130 self.ispy_utils.GenerateExpectation('test2', [self.white, self.black])
131 self.assertTrue(self.ispy_utils.ExpectationExists('test1')) 131 self.assertTrue(self.ispy_utils.ExpectationExists('test1'))
132 self.assertTrue(self.ispy_utils.ExpectationExists('test2')) 132 self.assertTrue(self.ispy_utils.ExpectationExists('test2'))
133 self.assertFalse(self.ispy_utils.ExpectationExists('test3')) 133 self.assertFalse(self.ispy_utils.ExpectationExists('test3'))
134 134
135 def testFailureExists(self): 135 def testFailureExists(self):
136 self.bucket.Reset() 136 self.bucket.Reset()
137 self.ispy_utils.UploadExpectation('test1', [self.white, self.white]) 137 self.ispy_utils.GenerateExpectation('test1', [self.white, self.white])
138 self.ispy_utils.RunTest('test', 'test1', self.black) 138 self.ispy_utils.PerformComparison('test', 'test1', self.black)
139 self.ispy_utils.RunTest('test', 'test1', self.white) 139 self.ispy_utils.PerformComparison('test', 'test1', self.white)
140 self.assertTrue(self.ispy_utils.FailureExists('test', 'test1')) 140 self.assertTrue(self.ispy_utils.FailureExists('test', 'test1'))
141 self.assertFalse(self.ispy_utils.FailureExists('test', 'test2')) 141 self.assertFalse(self.ispy_utils.FailureExists('test', 'test2'))
142 142
143 def testRemoveExpectation(self): 143 def testRemoveExpectation(self):
144 self.bucket.Reset() 144 self.bucket.Reset()
145 self.ispy_utils.UploadExpectation('test1', [self.white, self.white]) 145 self.ispy_utils.GenerateExpectation('test1', [self.white, self.white])
146 self.ispy_utils.UploadExpectation('test2', [self.white, self.white]) 146 self.ispy_utils.GenerateExpectation('test2', [self.white, self.white])
147 self.assertTrue(self.ispy_utils.ExpectationExists('test1')) 147 self.assertTrue(self.ispy_utils.ExpectationExists('test1'))
148 self.assertTrue(self.ispy_utils.ExpectationExists('test2')) 148 self.assertTrue(self.ispy_utils.ExpectationExists('test2'))
149 self.ispy_utils.RemoveExpectation('test1') 149 self.ispy_utils.RemoveExpectation('test1')
150 self.assertFalse(self.ispy_utils.ExpectationExists('test1')) 150 self.assertFalse(self.ispy_utils.ExpectationExists('test1'))
151 self.assertTrue(self.ispy_utils.ExpectationExists('test2')) 151 self.assertTrue(self.ispy_utils.ExpectationExists('test2'))
152 self.ispy_utils.RemoveExpectation('test2') 152 self.ispy_utils.RemoveExpectation('test2')
153 self.assertFalse(self.ispy_utils.ExpectationExists('test1')) 153 self.assertFalse(self.ispy_utils.ExpectationExists('test1'))
154 self.assertFalse(self.ispy_utils.ExpectationExists('test2')) 154 self.assertFalse(self.ispy_utils.ExpectationExists('test2'))
155 155
156 def testRemoveFailure(self): 156 def testRemoveFailure(self):
157 self.bucket.Reset() 157 self.bucket.Reset()
158 self.ispy_utils.UploadExpectation('test1', [self.white, self.white]) 158 self.ispy_utils.GenerateExpectation('test1', [self.white, self.white])
159 self.ispy_utils.UploadExpectation('test2', [self.white, self.white]) 159 self.ispy_utils.GenerateExpectation('test2', [self.white, self.white])
160 self.ispy_utils.RunTest('test', 'test1', self.black) 160 self.ispy_utils.PerformComparison('test', 'test1', self.black)
161 self.ispy_utils.RemoveFailure('test', 'test1') 161 self.ispy_utils.RemoveFailure('test', 'test1')
162 self.assertFalse(self.ispy_utils.FailureExists('test', 'test1')) 162 self.assertFalse(self.ispy_utils.FailureExists('test', 'test1'))
163 self.assertTrue(self.ispy_utils.ExpectationExists('test1')) 163 self.assertTrue(self.ispy_utils.ExpectationExists('test1'))
164 self.assertFalse(self.ispy_utils.FailureExists('test', 'test2')) 164 self.assertFalse(self.ispy_utils.FailureExists('test', 'test2'))
165 self.assertTrue(self.ispy_utils.ExpectationExists('test2')) 165 self.assertTrue(self.ispy_utils.ExpectationExists('test2'))
166 166
167 def testGetFailure(self): 167 def testGetFailure(self):
168 self.bucket.Reset() 168 self.bucket.Reset()
169 # Upload a result 169 # Upload a result
170 self.ispy_utils.UploadExpectation('test1', [self.red, self.red]) 170 self.ispy_utils.GenerateExpectation('test1', [self.red, self.red])
171 self.ispy_utils.RunTest('test', 'test1', self.black) 171 self.ispy_utils.PerformComparison('test', 'test1', self.black)
172 res = self.ispy_utils.GetFailure('test', 'test1') 172 res = self.ispy_utils.GetFailure('test', 'test1')
173 # Check that the function correctly got the result. 173 # Check that the function correctly got the result.
174 self.assertEquals(image_tools.EncodePNG(res.expected), 174 self.assertEquals(image_tools.EncodePNG(res.expected),
175 image_tools.EncodePNG(self.red)) 175 image_tools.EncodePNG(self.red))
176 self.assertEquals(image_tools.EncodePNG(res.diff), 176 self.assertEquals(image_tools.EncodePNG(res.diff),
177 image_tools.EncodePNG(self.masked)) 177 image_tools.EncodePNG(self.masked))
178 self.assertEquals(image_tools.EncodePNG(res.actual), 178 self.assertEquals(image_tools.EncodePNG(res.actual),
179 image_tools.EncodePNG(self.black)) 179 image_tools.EncodePNG(self.black))
180 # Check that the function raises an error when given non-existant results. 180 # Check that the function raises an error when given non-existant results.
181 self.assertRaises(cloud_bucket.FileNotFoundError, 181 self.assertRaises(cloud_bucket.FileNotFoundError,
182 self.ispy_utils.GetFailure, 'test', 'test2') 182 self.ispy_utils.GetFailure, 'test', 'test2')
183 183
184 def testGetAllPaths(self): 184 def testGetAllPaths(self):
185 self.bucket.Reset() 185 self.bucket.Reset()
186 # Upload some tests. 186 # Upload some tests.
187 self.ispy_utils.UploadExpectation('test1', [self.white, self.black]) 187 self.ispy_utils.GenerateExpectation('test1', [self.white, self.black])
188 # Check that the function gets all urls matching the prefix. 188 # Check that the function gets all urls matching the prefix.
189 self.assertEquals( 189 self.assertEquals(
190 set(self.ispy_utils.GetAllPaths( 190 set(self.ispy_utils.GetAllPaths(
191 ispy_utils.GetExpectationPath('test1'))), 191 ispy_utils.GetExpectationPath('test1'))),
192 set([ispy_utils.GetExpectationPath('test1', 'expected.png'), 192 set([ispy_utils.GetExpectationPath('test1', 'expected.png'),
193 ispy_utils.GetExpectationPath('test1', 'mask.png')])) 193 ispy_utils.GetExpectationPath('test1', 'mask.png')]))
194 self.assertEquals( 194 self.assertEquals(
195 set(self.ispy_utils.GetAllPaths( 195 set(self.ispy_utils.GetAllPaths(
196 ispy_utils.GetExpectationPath('test3'))), set()) 196 ispy_utils.GetExpectationPath('test3'))), set())
197 197
198 198
199 if __name__ == '__main__': 199 if __name__ == '__main__':
200 unittest.main() 200 unittest.main()
OLDNEW
« no previous file with comments | « chrome/test/functional/ispy/common/ispy_utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698