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

Side by Side Diff: recipe_modules/json/tests/add_json_log.py

Issue 2989423002: Add add_json_log='on_failure' to json module. (Closed)
Patch Set: Add unittests Created 3 years, 4 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
(Empty)
1 # Copyright 2017 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file.
4
5 DEPS = [
6 'json',
7 'step',
8 ]
9
10 def RunSteps(api):
11 example_dict = {'x': 1, 'y': 2}
12
13 # not add a log for success
14 step_result = api.step('no log on success',
15 ['cat', '{"x":1,"y":2}'],
16 stdout=api.json.output(add_json_log='on_failure', name='log1'),
17 )
18 assert step_result.stdout == example_dict
19 assert 'json.output[log1]' not in step_result.presentation.logs
20
21 # add a log for failure
22 try:
23 api.step('add log on failure',
24 ['cat', '{"x":1,"y":2}'],
25 stdout=api.json.output(add_json_log='on_failure', name='log2'),
26 )
27 except api.step.StepFailure:
28 pass # This step is expected to fail.
29 finally:
30 step_result = api.step.active_result
31 assert step_result.stdout == example_dict
32 assert 'json.output[log2]' in step_result.presentation.logs
33 actual_log_dict = api.json.loads(
34 '\n'.join(step_result.presentation.logs['json.output[log2]']))
35 assert actual_log_dict == example_dict
36
37
38 def GenTests(api):
39 yield (
40 api.test('add_json_log')
41 + api.step_data(
42 'no log on success',
43 stdout=api.json.output({'x': 1, 'y': 2}, name='log1'),
44 )
45 + api.step_data(
46 'add log on failure',
47 stdout=api.json.output({'x': 1, 'y': 2}, name='log2'),
48 retcode=1,
49 )
50 )
OLDNEW
« no previous file with comments | « recipe_modules/json/api.py ('k') | recipe_modules/json/tests/add_json_log.expected/add_json_log.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698