OLD | NEW |
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 imp | 5 import imp |
6 import inspect | 6 import inspect |
7 import os | 7 import os |
8 import sys | 8 import sys |
| 9 import tempfile |
9 | 10 |
10 | 11 |
11 class Placeholder(object): | 12 class Placeholder(object): |
12 """Base class for json placeholders. Do not use directly.""" | 13 """Base class for json placeholders. Do not use directly.""" |
13 def render(self, test_data): # pragma: no cover | 14 def render(self, test_data): # pragma: no cover |
14 """Return [cmd items]*""" | 15 """Return [cmd items]*""" |
15 raise NotImplementedError | 16 raise NotImplementedError |
16 | 17 |
17 def step_finished(self, stream, step_result, test_data): # pragma: no cover | 18 def step_finished(self, stream, step_result, test_data): # pragma: no cover |
18 """Called after step completion. Intended to modify step_result.""" | 19 """Called after step completion. Intended to modify step_result.""" |
19 pass | 20 pass |
20 | 21 |
21 | 22 |
| 23 class InputDataPlaceholder(Placeholder): |
| 24 def __init__(self, data, suffix): |
| 25 assert isinstance(data, basestring) |
| 26 self.data = data |
| 27 self.suffix = suffix |
| 28 self.input_file = None |
| 29 super(InputDataPlaceholder, self).__init__() |
| 30 |
| 31 def render(self, test_data): |
| 32 if test_data is not None: |
| 33 # cheat and pretend like we're going to pass the data on the |
| 34 # cmdline for test expectation purposes. |
| 35 return [self.data] |
| 36 else: # pragma: no cover |
| 37 input_fd, self.input_file = tempfile.mkstemp(suffix=self.suffix) |
| 38 os.write(input_fd, self.data) |
| 39 os.close(input_fd) |
| 40 return [self.input_file] |
| 41 |
| 42 def step_finished(self, stream, step_result, test_data): |
| 43 if test_data is None: # pragma: no cover |
| 44 os.unlink(self.input_file) |
| 45 |
| 46 |
22 class ModuleInjectionSite(object): | 47 class ModuleInjectionSite(object): |
23 pass | 48 pass |
24 | 49 |
25 | 50 |
26 class RecipeApi(object): | 51 class RecipeApi(object): |
27 """ | 52 """ |
28 Framework class for handling recipe_modules. | 53 Framework class for handling recipe_modules. |
29 | 54 |
30 Inherit from this in your recipe_modules/<name>/api.py . This class provides | 55 Inherit from this in your recipe_modules/<name>/api.py . This class provides |
31 wiring for your config context (in self.c and methods, and for dependency | 56 wiring for your config context (in self.c and methods, and for dependency |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 to_remove.append(dep) | 252 to_remove.append(dep) |
228 did_something = True | 253 did_something = True |
229 map(deps.remove, to_remove) | 254 map(deps.remove, to_remove) |
230 if not deps: | 255 if not deps: |
231 to_pop.append(api_name) | 256 to_pop.append(api_name) |
232 did_something = True | 257 did_something = True |
233 map(dep_map.pop, to_pop) | 258 map(dep_map.pop, to_pop) |
234 assert did_something, 'Did nothing on this loop. %s' % dep_map | 259 assert did_something, 'Did nothing on this loop. %s' % dep_map |
235 | 260 |
236 return inst_map[None] | 261 return inst_map[None] |
OLD | NEW |