Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The LUCI Authors. All rights reserved. | 1 # Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import json | 5 import json |
| 6 | 6 |
| 7 from recipe_engine import recipe_test_api | 7 from recipe_engine import recipe_test_api |
| 8 | 8 |
| 9 class JsonTestApi(recipe_test_api.RecipeTestApi): | 9 class JsonTestApi(recipe_test_api.RecipeTestApi): |
| 10 @recipe_test_api.placeholder_step_data | 10 @recipe_test_api.placeholder_step_data |
| 11 @staticmethod | 11 @staticmethod |
| 12 def output(data, retcode=None, name=None): | 12 def output(data, retcode=None, name=None): |
| 13 """Supplies placeholder data for a json.output. `data` should be a jsonish | 13 """Supplies placeholder data for a json.output. `data` should be a jsonish |
| 14 python object (e.g. dict, list, str, bool, int, etc). It will be dumped out | 14 python object (e.g. dict, list, str, bool, int, etc). It will be dumped out |
| 15 with json.dumps and the step will be observed to return that dumped value. | 15 with json.dumps and the step will be observed to return that dumped value. |
| 16 """ | 16 """ |
| 17 return json.dumps(data), retcode, name | 17 return json.dumps(data), retcode, name |
| 18 | 18 |
| 19 def invalid(self, raw_data_str, retcode=None, name=None): | 19 def invalid(self, raw_data_str, retcode=None, name=None): |
| 20 """Can be used to supply data for a json.output, except that it takes a raw | 20 """Can be used to supply data for a json.output, except that it takes a raw |
| 21 string rather than a json object.""" | 21 string rather than a json object.""" |
| 22 ret = recipe_test_api.StepTestData() | 22 ret = recipe_test_api.StepTestData() |
| 23 ret.retcode=retcode | 23 ret.retcode=retcode |
| 24 placeholder_data = recipe_test_api.PlaceholderTestData( | 24 placeholder_data = recipe_test_api.PlaceholderTestData( |
| 25 data=raw_data_str, name=name) | 25 data=raw_data_str, name=name) |
| 26 ret.placeholder_data[(self._module.NAME, 'output', name)] = placeholder_data | 26 ret.placeholder_data[(self._module.NAME, 'output', name)] = placeholder_data |
| 27 return ret | 27 return ret |
| 28 | 28 |
| 29 def not_found(self, retcode=None, name=None): | |
| 30 """Can be used to have the json.output file be missing.""" | |
| 31 ret = recipe_test_api.StepTestData() | |
| 32 ret.retcode=retcode | |
| 33 # FIXME: How do I get None into the data? | |
|
Paweł Hajdan Jr.
2017/03/23 12:22:12
What happens if you just use None below instead of
iannucci
2017/03/23 19:44:13
That's what I would expect as well... however I wo
| |
| 34 ret.placeholder_data[(self._module.NAME, 'output', name)] = '' | |
| 35 return ret | |
| 36 | |
| 29 def output_stream(self, data, stream='stdout', retcode=None, name=None): | 37 def output_stream(self, data, stream='stdout', retcode=None, name=None): |
| 30 assert stream in ('stdout', 'stderr') | 38 assert stream in ('stdout', 'stderr') |
| 31 ret = recipe_test_api.StepTestData() | 39 ret = recipe_test_api.StepTestData() |
| 32 step_data = self.output(data, retcode=retcode, name=name) | 40 step_data = self.output(data, retcode=retcode, name=name) |
| 33 setattr(ret, stream, step_data.unwrap_placeholder()) | 41 setattr(ret, stream, step_data.unwrap_placeholder()) |
| 34 return ret | 42 return ret |
| OLD | NEW |