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

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

Issue 2750793002: [json] improve output to get leak_to and better logging. (Closed)
Patch Set: update comment 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
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', 'cool_script.py',
68 api.json.output(leak_to=api.path['tmp_base'].join('leak.json')),
69 ])
70 assert step_result.json.output == example_dict
71
72 # invalid data gets rendered
73 api.step('invalid json', [
74 'python', 'garbage.py', api.json.output(),
75 ])
76
65 77
66 def GenTests(api): 78 def GenTests(api):
67 yield (api.test('basic') + 79 yield (
68 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) + 80 api.test('basic')
69 api.step_data( 81 + api.step_data('echo1', stdout=api.json.output([1, 2, 3]))
70 'foo', 82 + api.step_data(
71 api.json.output([1, 2, 3], name='1') + 83 'foo',
72 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'), 84 api.json.output([1, 2, 3], name='1') +
73 )) 85 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'),
86 )
87 + api.step_data(
88 'leaking json',
89 api.json.output({'x': 1, 'y': 2}),
90 )
91 + api.step_data(
92 'invalid json',
93 api.json.invalid('here is some total\ngarbage'),
94 )
95 )
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698