OLD | NEW |
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 Loading... |
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 ) |
OLD | NEW |