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

Side by Side Diff: recipe_modules/json/example.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/api.py ('k') | recipe_modules/json/example.expected/basic.json » ('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 2014 The LUCI Authors. All rights reserved. 1 # Copyright 2014 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 DEPS = [ 5 DEPS = [
6 'json', 6 'json',
7 'path', 7 'path',
8 'python', 8 'python',
9 'raw_io', 9 'raw_io',
10 'step', 10 'step',
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 # json.read reads a file containing json data. 55 # json.read reads a file containing json data.
56 leak_path = api.path['tmp_base'].join('temp.json') 56 leak_path = api.path['tmp_base'].join('temp.json')
57 api.step('write json to file', 57 api.step('write json to file',
58 ['cat', api.json.input(example_dict)], 58 ['cat', api.json.input(example_dict)],
59 stdout=api.raw_io.output(leak_to=leak_path)) 59 stdout=api.raw_io.output(leak_to=leak_path))
60 step_result = api.json.read( 60 step_result = api.json.read(
61 'read json from file we just wrote', leak_path, 61 'read json from file we just wrote', leak_path,
62 step_test_data=lambda: api.json.test_api.output(example_dict)) 62 step_test_data=lambda: api.json.test_api.output(example_dict))
63 assert step_result.json.output == example_dict 63 assert step_result.json.output == example_dict
64 64
65 # can leak directly to a file
66 step_result = api.step('leaking json', [
67 'python', api.resource('cool_script.py'),
68 '{"x":1,"y":2}',
69 api.json.output(leak_to=api.path['tmp_base'].join('leak.json')),
70 ])
71 assert step_result.json.output == example_dict
72
73 # invalid data gets rendered
74 step_result = api.step('invalid json', [
75 'python', api.resource('cool_script.py'),
76 '{"here is some total\ngarbage',
77 api.json.output(),
78 ])
79 assert step_result.json.output is None
80
65 81
66 def GenTests(api): 82 def GenTests(api):
67 yield (api.test('basic') + 83 yield (
68 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) + 84 api.test('basic')
69 api.step_data( 85 + api.step_data('echo1', stdout=api.json.output([1, 2, 3]))
70 'foo', 86 + api.step_data(
71 api.json.output([1, 2, 3], name='1') + 87 'foo',
72 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'), 88 api.json.output([1, 2, 3], name='1') +
73 )) 89 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'),
90 )
91 + api.step_data(
92 'leaking json',
93 api.json.output({'x': 1, 'y': 2}),
94 )
95 + api.step_data(
96 'invalid json',
97 api.json.invalid('{"here is some total\ngarbage'),
98 )
99 )
OLDNEW
« no previous file with comments | « recipe_modules/json/api.py ('k') | recipe_modules/json/example.expected/basic.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698