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

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

Issue 1773273003: Make output placeholders like json.output index-able by name. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/recipes-py@master
Patch Set: Rebase uppon https://codereview.chromium.org/1785543004/ Created 4 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 Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # 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 19 matching lines...) Expand all
30 result = api.python.inline( 30 result = api.python.inline(
31 'foo', 31 'foo',
32 """ 32 """
33 import json 33 import json
34 import sys 34 import sys
35 with open(sys.argv[1], 'w') as f: 35 with open(sys.argv[1], 'w') as f:
36 f.write(json.dumps([1, 2, 3])) 36 f.write(json.dumps([1, 2, 3]))
37 with open(sys.argv[2], 'w') as f: 37 with open(sys.argv[2], 'w') as f:
38 f.write(json.dumps(['x', 'y', %s])) 38 f.write(json.dumps(['x', 'y', %s]))
39 """ % repr(FULLWIDTH_Z), 39 """ % repr(FULLWIDTH_Z),
40 args=[api.json.output(), api.json.output()], 40 args=[api.json.output(name='1'), api.json.output(name='2')],
41 ) 41 )
42 assert result.json.output_all == [[1, 2, 3], ['x', 'y', FULLWIDTH_Z]] 42 assert result.json.outputs['1'] == [1, 2, 3]
43 assert result.json.outputs['2'] == ['x', 'y', FULLWIDTH_Z]
43 44
44 example_dict = {'x': 1, 'y': 2} 45 example_dict = {'x': 1, 'y': 2}
45 46
46 # json.input(json_data) expands to a path containing that rendered json 47 # json.input(json_data) expands to a path containing that rendered json
47 step_result = api.step('json through', 48 step_result = api.step('json through',
48 ['cat', api.json.input(example_dict)], 49 ['cat', api.json.input(example_dict)],
49 stdout=api.json.output(), 50 stdout=api.json.output(),
50 step_test_data=lambda: api.json.test_api.output_stream(example_dict)) 51 step_test_data=lambda: api.json.test_api.output_stream(example_dict))
51 assert step_result.stdout == example_dict 52 assert step_result.stdout == example_dict
52 53
53 # json.read reads a file containing json data. 54 # json.read reads a file containing json data.
54 leak_path = api.path['slave_build'].join('temp.json') 55 leak_path = api.path['slave_build'].join('temp.json')
55 api.step('write json to file', 56 api.step('write json to file',
56 ['cat', api.json.input(example_dict)], 57 ['cat', api.json.input(example_dict)],
57 stdout=api.raw_io.output(leak_to=leak_path)) 58 stdout=api.raw_io.output(leak_to=leak_path))
58 step_result = api.json.read( 59 step_result = api.json.read(
59 'read json from file we just wrote', leak_path, 60 'read json from file we just wrote', leak_path,
60 step_test_data=lambda: api.json.test_api.output(example_dict)) 61 step_test_data=lambda: api.json.test_api.output(example_dict))
61 assert step_result.json.output == example_dict 62 assert step_result.json.output == example_dict
62 63
63 64
64 def GenTests(api): 65 def GenTests(api):
65 yield (api.test('basic') + 66 yield (api.test('basic') +
66 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) + 67 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) +
67 api.step_data( 68 api.step_data(
68 'foo', 69 'foo',
69 api.json.output([1, 2, 3]) + 70 api.json.output([1, 2, 3], name='1') +
70 api.json.output(['x', 'y', FULLWIDTH_Z]), 71 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'),
71 )) 72 ))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698