Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Side by Side Diff: recipe_modules/json/test_api.py

Issue 2750793002: [json] improve output to get leak_to and better logging. (Closed)
Patch Set: fixit Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « recipe_modules/json/example.resources/cool_script.py ('k') | recipe_modules/raw_io/api.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.
16 """
13 return json.dumps(data), retcode, name 17 return json.dumps(data), retcode, name
14 18
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
21 string rather than a json object."""
22 ret = recipe_test_api.StepTestData()
23 ret.retcode=retcode
24 placeholder_data = recipe_test_api.PlaceholderTestData(
25 data=raw_data_str, name=name)
26 ret.placeholder_data[(self._module.NAME, 'output', name)] = placeholder_data
27 return ret
28
15 def output_stream(self, data, stream='stdout', retcode=None, name=None): 29 def output_stream(self, data, stream='stdout', retcode=None, name=None):
16 assert stream in ('stdout', 'stderr') 30 assert stream in ('stdout', 'stderr')
17 ret = recipe_test_api.StepTestData() 31 ret = recipe_test_api.StepTestData()
18 step_data = self.output(data, retcode=retcode, name=name) 32 step_data = self.output(data, retcode=retcode, name=name)
19 setattr(ret, stream, step_data.unwrap_placeholder()) 33 setattr(ret, stream, step_data.unwrap_placeholder())
20 return ret 34 return ret
OLDNEW
« no previous file with comments | « recipe_modules/json/example.resources/cool_script.py ('k') | recipe_modules/raw_io/api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698