OLD | NEW |
(Empty) | |
| 1 from slave import recipe_api |
| 2 from slave import recipe_util |
| 3 |
| 4 import os |
| 5 import tempfile |
| 6 |
| 7 class InputDataPlaceholder(recipe_util.Placeholder): |
| 8 def __init__(self, data, suffix, mod_name): |
| 9 assert isinstance(data, basestring) |
| 10 self.data = data |
| 11 self.suffix = suffix |
| 12 self.input_file = None |
| 13 super(InputDataPlaceholder, self).__init__('input', mod_name) |
| 14 |
| 15 def render(self, test): |
| 16 if test.enabled: |
| 17 # cheat and pretend like we're going to pass the data on the |
| 18 # cmdline for test expectation purposes. |
| 19 return [self.data] |
| 20 else: # pragma: no cover |
| 21 input_fd, self.input_file = tempfile.mkstemp(suffix=self.suffix) |
| 22 os.write(input_fd, self.data) |
| 23 os.close(input_fd) |
| 24 return [self.input_file] |
| 25 |
| 26 def result(self, presentation, test): |
| 27 if not test.enabled: # pragma: no cover |
| 28 os.unlink(self.input_file) |
| 29 |
| 30 |
| 31 class RawApi(recipe_api.RecipeApi): |
| 32 def input(self, data, suffix, mod_name=None): |
| 33 return InputDataPlaceholder(data, suffix, mod_name or self.name) |
OLD | NEW |