| OLD | NEW |
| 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', |
| 11 ] | 11 ] |
| 12 | 12 |
| 13 FULLWIDTH_Z = u'\ufeff\uff5a' | 13 FULLWIDTH_Z = u'\ufeff\uff5a' |
| 14 | 14 |
| 15 def RunSteps(api): | 15 def RunSteps(api): |
| 16 step_result = api.step('echo1', ['echo', '[1, 2, 3]'], | 16 step_result = api.step('echo1', ['echo', '[1, 2, 3]'], |
| 17 stdout=api.json.output()) | 17 stdout=api.json.output()) |
| 18 assert step_result.stdout == [1, 2, 3], step_result.stdout | 18 assert step_result.stdout == [1, 2, 3], step_result.stdout |
| 19 | 19 |
| 20 # Example demonstrating the usage of step_test_data for json stdout. | 20 # Example demonstrating the usage of step_test_data for json stdout. |
| 21 step_result = api.step('echo2', ['echo', '[2, 3, 4]'], | 21 step_result = api.step('echo2', ['echo', '[2, 3, 4]'], |
| 22 step_test_data=lambda: api.json.test_api.output_stream([2, 3, 4]), | 22 step_test_data=lambda: api.json.test_api.output_stream([2, 3, 4]), |
| 23 stdout=api.json.output()) | 23 stdout=api.json.output()) |
| 24 assert step_result.stdout == [2, 3, 4] | 24 assert step_result.stdout == [2, 3, 4] |
| 25 | 25 |
| 26 assert api.json.is_serializable('foo') | 26 assert api.json.is_serializable('foo') |
| 27 assert not api.json.is_serializable(set(['foo', 'bar', 'baz'])) | 27 assert not api.json.is_serializable(set(['foo', 'bar', 'baz'])) |
| 28 | 28 |
| 29 # Example demonstrating multiple json output files. | 29 # Example demonstrating multiple named json output files. |
| 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] |
| 44 assert not hasattr(result.json, 'output') |
| 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], name='1') + |
| 70 api.json.output(['x', 'y', FULLWIDTH_Z]), | 72 api.json.output(['x', 'y', FULLWIDTH_Z], name='2'), |
| 71 )) | 73 )) |
| OLD | NEW |