OLD | NEW |
---|---|
1 # Copyright 2013-2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2013-2015 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 collections | 5 import collections |
6 | 6 |
7 from .util import ModuleInjectionSite, static_call, static_wraps | 7 from .util import ModuleInjectionSite, static_call, static_wraps |
8 from .types import freeze | |
8 | 9 |
9 def combineify(name, dest, a, b): | 10 def combineify(name, dest, a, b): |
10 """ | 11 """ |
11 Combines dictionary members in two objects into a third one using addition. | 12 Combines dictionary members in two objects into a third one using addition. |
12 | 13 |
13 Args: | 14 Args: |
14 name - the name of the member | 15 name - the name of the member |
15 dest - the destination object | 16 dest - the destination object |
16 a - the first source object | 17 a - the first source object |
17 b - the second source object | 18 b - the second source object |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__() | 153 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__() |
153 | 154 |
154 | 155 |
155 class TestData(BaseTestData): | 156 class TestData(BaseTestData): |
156 def __init__(self, name=None): | 157 def __init__(self, name=None): |
157 super(TestData, self).__init__() | 158 super(TestData, self).__init__() |
158 self.name = name | 159 self.name = name |
159 self.properties = {} # key -> val | 160 self.properties = {} # key -> val |
160 self.mod_data = collections.defaultdict(ModuleTestData) | 161 self.mod_data = collections.defaultdict(ModuleTestData) |
161 self.step_data = collections.defaultdict(StepTestData) | 162 self.step_data = collections.defaultdict(StepTestData) |
163 self.depend_on_data = {} | |
162 self.expected_exception = None | 164 self.expected_exception = None |
163 | 165 |
164 def __add__(self, other): | 166 def __add__(self, other): |
165 assert isinstance(other, TestData) | 167 assert isinstance(other, TestData) |
166 ret = TestData(self.name or other.name) | 168 ret = TestData(self.name or other.name) |
167 | 169 |
168 ret.properties.update(self.properties) | 170 ret.properties.update(self.properties) |
169 ret.properties.update(other.properties) | 171 ret.properties.update(other.properties) |
170 | 172 |
171 combineify('mod_data', ret, self, other) | 173 combineify('mod_data', ret, self, other) |
172 combineify('step_data', ret, self, other) | 174 combineify('step_data', ret, self, other) |
173 ret.expected_exception = self.expected_exception | 175 ret.expected_exception = self.expected_exception |
174 if other.expected_exception: | 176 if other.expected_exception: |
175 ret.expected_exception = other.expected_exception | 177 ret.expected_exception = other.expected_exception |
178 ret.depend_on_data.update(self.depend_on_data) | |
Paweł Hajdan Jr.
2015/11/13 12:30:00
Would it make sense to use combineify here for con
martiniss
2015/11/13 23:19:02
That works alright. Fixed.
| |
179 ret.depend_on_data.update(other.depend_on_data) | |
176 | 180 |
177 return ret | 181 return ret |
178 | 182 |
179 def empty(self): | 183 def empty(self): |
180 return not self.step_data | 184 return not self.step_data |
181 | 185 |
182 def pop_step_test_data(self, step_name, step_test_data_fn): | 186 def pop_step_test_data(self, step_name, step_test_data_fn): |
183 step_test_data = step_test_data_fn() | 187 step_test_data = step_test_data_fn() |
184 if step_name in self.step_data: | 188 if step_name in self.step_data: |
185 step_test_data += self.step_data.pop(step_name) | 189 step_test_data += self.step_data.pop(step_name) |
186 return step_test_data | 190 return step_test_data |
187 | 191 |
188 def get_module_test_data(self, module_name): | 192 def get_module_test_data(self, module_name): |
189 return self.mod_data.get(module_name, ModuleTestData()) | 193 return self.mod_data.get(module_name, ModuleTestData()) |
190 | 194 |
191 def expect_exception(self, exception): | 195 def expect_exception(self, exception): |
192 assert not self.expected_exception | 196 assert not self.expected_exception |
193 assert isinstance(exception, basestring), ( | 197 assert isinstance(exception, basestring), ( |
194 'expect_exception expects a string containing the exception class name') | 198 'expect_exception expects a string containing the exception class name') |
195 self.expected_exception = exception | 199 self.expected_exception = exception |
196 | 200 |
197 def is_unexpected_exception(self, exception): | 201 def is_unexpected_exception(self, exception): |
198 name = exception.__class__.__name__ | 202 name = exception.__class__.__name__ |
199 return not (self.enabled and name == self.expected_exception) | 203 return not (self.enabled and name == self.expected_exception) |
200 | 204 |
205 def depend_on(self, recipe, properties, result): | |
206 assert recipe not in self.depend_on_data, ( | |
Paweł Hajdan Jr.
2015/11/13 12:30:00
If I understand this correctly, this uses recipe a
martiniss
2015/11/13 23:19:02
Changed to recipe, properties.
| |
207 "Already gave test data for %s" % recipe) | |
Paweł Hajdan Jr.
2015/11/13 12:30:00
nit: Prefer single quotes ' .
martiniss
2015/11/13 23:19:02
Fixed.
| |
208 self.depend_on_data[recipe] = freeze((properties, result)) | |
209 | |
201 def __repr__(self): | 210 def __repr__(self): |
202 return "TestData(%r)" % ({ | 211 return "TestData(%r)" % ({ |
203 'name': self.name, | 212 'name': self.name, |
204 'properties': self.properties, | 213 'properties': self.properties, |
205 'mod_data': dict(self.mod_data.iteritems()), | 214 'mod_data': dict(self.mod_data.iteritems()), |
206 'step_data': dict(self.step_data.iteritems()), | 215 'step_data': dict(self.step_data.iteritems()), |
207 'expected_exception': self.expected_exception, | 216 'expected_exception': self.expected_exception, |
217 'depend_on_data': self.depend_on_data | |
208 },) | 218 },) |
209 | 219 |
210 | 220 |
211 class DisabledTestData(BaseTestData): | 221 class DisabledTestData(BaseTestData): |
212 def __init__(self): | 222 def __init__(self): |
213 super(DisabledTestData, self).__init__(False) | 223 super(DisabledTestData, self).__init__(False) |
214 | 224 |
215 def __getattr__(self, name): | 225 def __getattr__(self, name): |
216 return self | 226 return self |
217 | 227 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
455 def override_step_data(self, name, *data, **kwargs): | 465 def override_step_data(self, name, *data, **kwargs): |
456 """See _step_data()""" | 466 """See _step_data()""" |
457 kwargs['override'] = True | 467 kwargs['override'] = True |
458 return self._step_data(name, *data, **kwargs) | 468 return self._step_data(name, *data, **kwargs) |
459 override_step_data.__doc__ = _step_data.__doc__ | 469 override_step_data.__doc__ = _step_data.__doc__ |
460 | 470 |
461 def expect_exception(self, exc_type): #pylint: disable=R0201 | 471 def expect_exception(self, exc_type): #pylint: disable=R0201 |
462 ret = TestData(None) | 472 ret = TestData(None) |
463 ret.expect_exception(exc_type) | 473 ret.expect_exception(exc_type) |
464 return ret | 474 return ret |
475 | |
476 def depend_on(self, recipe, properties, result): | |
477 ret = TestData() | |
478 ret.depend_on(recipe, properties, result) | |
479 return ret | |
OLD | NEW |