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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/json/tests/add_json_log.py
diff --git a/recipe_modules/json/tests/add_json_log.py b/recipe_modules/json/tests/add_json_log.py
new file mode 100644
index 0000000000000000000000000000000000000000..66b8fcd7af681c92ed1db4660e3648e3cb2a91d4
--- /dev/null
+++ b/recipe_modules/json/tests/add_json_log.py
@@ -0,0 +1,50 @@
+# Copyright 2017 The LUCI Authors. All rights reserved.
+# Use of this source code is governed under the Apache License, Version 2.0
+# that can be found in the LICENSE file.
+
+DEPS = [
+ 'json',
+ 'step',
+]
+
+def RunSteps(api):
+ example_dict = {'x': 1, 'y': 2}
+
+ # not add a log for success
+ step_result = api.step('no log on success',
+ ['cat', '{"x":1,"y":2}'],
+ stdout=api.json.output(add_json_log='on_failure', name='log1'),
+ )
+ assert step_result.stdout == example_dict
+ assert 'json.output[log1]' not in step_result.presentation.logs
+
+ # add a log for failure
+ try:
+ api.step('add log on failure',
+ ['cat', '{"x":1,"y":2}'],
+ stdout=api.json.output(add_json_log='on_failure', name='log2'),
+ )
+ except api.step.StepFailure:
+ pass # This step is expected to fail.
+ finally:
+ step_result = api.step.active_result
+ assert step_result.stdout == example_dict
+ assert 'json.output[log2]' in step_result.presentation.logs
+ actual_log_dict = api.json.loads(
+ '\n'.join(step_result.presentation.logs['json.output[log2]']))
+ assert actual_log_dict == example_dict
+
+
+def GenTests(api):
+ yield (
+ api.test('add_json_log')
+ + api.step_data(
+ 'no log on success',
+ stdout=api.json.output({'x': 1, 'y': 2}, name='log1'),
+ )
+ + api.step_data(
+ 'add log on failure',
+ stdout=api.json.output({'x': 1, 'y': 2}, name='log2'),
+ retcode=1,
+ )
+ )
« 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