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

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: 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(id='1'), api.json.output(id='2')],
41 ) 41 )
42 assert result.json.output_all == [[1, 2, 3], ['x', 'y', FULLWIDTH_Z]] 42 assert result.json.output_all == [[1, 2, 3], ['x', 'y', FULLWIDTH_Z]]
martiniss 2016/03/10 02:02:30 Add a TODO here to delete when the bug is closed?
stgao 2016/03/10 20:34:23 Remove in this CL directly.
43 assert result.json.outputs['1'] == [1, 2, 3]
44 assert result.json.outputs['2'] == ['x', 'y', FULLWIDTH_Z]
iannucci 2016/03/10 03:17:42 awesome :)
43 45
44 example_dict = {'x': 1, 'y': 2} 46 example_dict = {'x': 1, 'y': 2}
45 47
46 # json.input(json_data) expands to a path containing that rendered json 48 # json.input(json_data) expands to a path containing that rendered json
47 step_result = api.step('json through', 49 step_result = api.step('json through',
48 ['cat', api.json.input(example_dict)], 50 ['cat', api.json.input(example_dict)],
49 stdout=api.json.output(), 51 stdout=api.json.output(),
50 step_test_data=lambda: api.json.test_api.output_stream(example_dict)) 52 step_test_data=lambda: api.json.test_api.output_stream(example_dict))
51 assert step_result.stdout == example_dict 53 assert step_result.stdout == example_dict
52 54
53 # json.read reads a file containing json data. 55 # json.read reads a file containing json data.
54 leak_path = api.path['slave_build'].join('temp.json') 56 leak_path = api.path['slave_build'].join('temp.json')
55 api.step('write json to file', 57 api.step('write json to file',
56 ['cat', api.json.input(example_dict)], 58 ['cat', api.json.input(example_dict)],
57 stdout=api.raw_io.output(leak_to=leak_path)) 59 stdout=api.raw_io.output(leak_to=leak_path))
58 step_result = api.json.read( 60 step_result = api.json.read(
59 'read json from file we just wrote', leak_path, 61 'read json from file we just wrote', leak_path,
60 step_test_data=lambda: api.json.test_api.output(example_dict)) 62 step_test_data=lambda: api.json.test_api.output(example_dict))
61 assert step_result.json.output == example_dict 63 assert step_result.json.output == example_dict
62 64
63 65
64 def GenTests(api): 66 def GenTests(api):
65 yield (api.test('basic') + 67 yield (api.test('basic') +
66 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) + 68 api.step_data('echo1', stdout=api.json.output([1, 2, 3])) +
67 api.step_data( 69 api.step_data(
68 'foo', 70 'foo',
69 api.json.output([1, 2, 3]) + 71 api.json.output([1, 2, 3]) +
70 api.json.output(['x', 'y', FULLWIDTH_Z]), 72 api.json.output(['x', 'y', FULLWIDTH_Z]),
71 )) 73 ))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698