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 import contextlib | 6 import contextlib |
7 | 7 |
8 from .util import ModuleInjectionSite, static_call, static_wraps | 8 from .util import ModuleInjectionSite, static_call, static_wraps |
| 9 from .types import freeze |
9 | 10 |
10 def combineify(name, dest, a, b): | 11 def combineify(name, dest, a, b): |
11 """ | 12 """ |
12 Combines dictionary members in two objects into a third one using addition. | 13 Combines dictionary members in two objects into a third one using addition. |
13 | 14 |
14 Args: | 15 Args: |
15 name - the name of the member | 16 name - the name of the member |
16 dest - the destination object | 17 dest - the destination object |
17 a - the first source object | 18 a - the first source object |
18 b - the second source object | 19 b - the second source object |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__() | 154 return "ModuleTestData(%r)" % super(ModuleTestData, self).__repr__() |
154 | 155 |
155 | 156 |
156 class TestData(BaseTestData): | 157 class TestData(BaseTestData): |
157 def __init__(self, name=None): | 158 def __init__(self, name=None): |
158 super(TestData, self).__init__() | 159 super(TestData, self).__init__() |
159 self.name = name | 160 self.name = name |
160 self.properties = {} # key -> val | 161 self.properties = {} # key -> val |
161 self.mod_data = collections.defaultdict(ModuleTestData) | 162 self.mod_data = collections.defaultdict(ModuleTestData) |
162 self.step_data = collections.defaultdict(StepTestData) | 163 self.step_data = collections.defaultdict(StepTestData) |
| 164 self.depend_on_data = {} |
163 self.expected_exception = None | 165 self.expected_exception = None |
164 | 166 |
165 def __add__(self, other): | 167 def __add__(self, other): |
166 assert isinstance(other, TestData) | 168 assert isinstance(other, TestData) |
167 ret = TestData(self.name or other.name) | 169 ret = TestData(self.name or other.name) |
168 | 170 |
169 ret.properties.update(self.properties) | 171 ret.properties.update(self.properties) |
170 ret.properties.update(other.properties) | 172 ret.properties.update(other.properties) |
171 | 173 |
172 combineify('mod_data', ret, self, other) | 174 combineify('mod_data', ret, self, other) |
173 combineify('step_data', ret, self, other) | 175 combineify('step_data', ret, self, other) |
| 176 combineify('depend_on_data', ret, self, other) |
174 ret.expected_exception = self.expected_exception | 177 ret.expected_exception = self.expected_exception |
175 if other.expected_exception: | 178 if other.expected_exception: |
176 ret.expected_exception = other.expected_exception | 179 ret.expected_exception = other.expected_exception |
177 | 180 |
178 return ret | 181 return ret |
179 | 182 |
180 @property | 183 @property |
181 def consumed(self): | 184 def consumed(self): |
182 return not (self.step_data or self.expected_exception) | 185 return not (self.step_data or self.expected_exception) |
183 | 186 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 raise | 226 raise |
224 """ | 227 """ |
225 name = exception.__class__.__name__ | 228 name = exception.__class__.__name__ |
226 should_raise = not (self.enabled and name == self.expected_exception) | 229 should_raise = not (self.enabled and name == self.expected_exception) |
227 | 230 |
228 yield should_raise | 231 yield should_raise |
229 | 232 |
230 if not should_raise: | 233 if not should_raise: |
231 self.expected_exception = None | 234 self.expected_exception = None |
232 | 235 |
| 236 def depend_on(self, recipe, properties, result): |
| 237 tup = freeze((recipe, properties)) |
| 238 assert tup not in self.depend_on_data, ( |
| 239 'Already gave test data for recipe %s with properties %r' % tup) |
| 240 self.depend_on_data[tup] = freeze(result) |
| 241 |
233 def __repr__(self): | 242 def __repr__(self): |
234 return "TestData(%r)" % ({ | 243 return "TestData(%r)" % ({ |
235 'name': self.name, | 244 'name': self.name, |
236 'properties': self.properties, | 245 'properties': self.properties, |
237 'mod_data': dict(self.mod_data.iteritems()), | 246 'mod_data': dict(self.mod_data.iteritems()), |
238 'step_data': dict(self.step_data.iteritems()), | 247 'step_data': dict(self.step_data.iteritems()), |
239 'expected_exception': self.expected_exception, | 248 'expected_exception': self.expected_exception, |
| 249 'depend_on_data': self.depend_on_data, |
240 },) | 250 },) |
241 | 251 |
242 | 252 |
243 class DisabledTestData(BaseTestData): | 253 class DisabledTestData(BaseTestData): |
244 def __init__(self): | 254 def __init__(self): |
245 super(DisabledTestData, self).__init__(False) | 255 super(DisabledTestData, self).__init__(False) |
246 | 256 |
247 def __getattr__(self, name): | 257 def __getattr__(self, name): |
248 return self | 258 return self |
249 | 259 |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 def override_step_data(self, name, *data, **kwargs): | 497 def override_step_data(self, name, *data, **kwargs): |
488 """See _step_data()""" | 498 """See _step_data()""" |
489 kwargs['override'] = True | 499 kwargs['override'] = True |
490 return self._step_data(name, *data, **kwargs) | 500 return self._step_data(name, *data, **kwargs) |
491 override_step_data.__doc__ = _step_data.__doc__ | 501 override_step_data.__doc__ = _step_data.__doc__ |
492 | 502 |
493 def expect_exception(self, exc_type): #pylint: disable=R0201 | 503 def expect_exception(self, exc_type): #pylint: disable=R0201 |
494 ret = TestData(None) | 504 ret = TestData(None) |
495 ret.expect_exception(exc_type) | 505 ret.expect_exception(exc_type) |
496 return ret | 506 return ret |
| 507 |
| 508 def depend_on(self, recipe, properties, result): |
| 509 ret = TestData() |
| 510 ret.depend_on(recipe, properties, result) |
| 511 return ret |
OLD | NEW |