OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 'properties', | 6 'recipe_engine/properties', |
7 'step', | 7 'recipe_engine/step', |
8 ] | 8 ] |
9 | 9 |
10 from recipe_engine import recipe_api | 10 from recipe_engine import recipe_api |
11 | 11 |
12 def RunSteps(api): | 12 def RunSteps(api): |
13 # TODO(martinis) change this | 13 # TODO(martinis) change this |
14 # The api.step object is directly callable. | 14 # The api.step object is directly callable. |
15 api.step('hello', ['echo', 'Hello World']) | 15 api.step('hello', ['echo', 'Hello World']) |
16 api.step('hello', ['echo', 'Why hello, there.']) | 16 api.step('hello', ['echo', 'Why hello, there.']) |
17 | 17 |
(...skipping 10 matching lines...) Expand all Loading... |
28 # We can manipulate the step presentation arbitrarily until we run | 28 # We can manipulate the step presentation arbitrarily until we run |
29 # the next step. | 29 # the next step. |
30 step_result = api.step('hello', ['echo', 'hello']) | 30 step_result = api.step('hello', ['echo', 'hello']) |
31 step_result.presentation.status = api.step.EXCEPTION | 31 step_result.presentation.status = api.step.EXCEPTION |
32 step_result.presentation.logs['the reason'] = ['The reason\nit failed'] | 32 step_result.presentation.logs['the reason'] = ['The reason\nit failed'] |
33 | 33 |
34 try: | 34 try: |
35 api.step('goodbye', ['echo', 'goodbye']) | 35 api.step('goodbye', ['echo', 'goodbye']) |
36 # Modifying step_result now would raise an AssertionError. | 36 # Modifying step_result now would raise an AssertionError. |
37 except api.step.StepFailure: | 37 except api.step.StepFailure: |
38 # Raising anything besides StepFailure causes the build to go purple. | 38 # Raising anything besides StepFailure or StepWarning causes the build to go
|
| 39 # purple. |
39 raise ValueError('goodbye must exit 0!') | 40 raise ValueError('goodbye must exit 0!') |
40 | 41 |
| 42 try: |
| 43 api.step('warning', ['echo', 'warning']) |
| 44 except api.step.StepFailure as e: |
| 45 e.result.presentation.status = api.step.WARNING |
| 46 raise api.step.StepWarning(e.message) |
| 47 |
| 48 |
41 # Aggregate failures from tests! | 49 # Aggregate failures from tests! |
42 try: | 50 try: |
43 with recipe_api.defer_results(): | 51 with recipe_api.defer_results(): |
44 api.step('testa', ['echo', 'testa']) | 52 api.step('testa', ['echo', 'testa']) |
45 api.step('testb', ['echo', 'testb']) | 53 api.step('testb', ['echo', 'testb']) |
46 except recipe_api.AggregatedStepFailure as f: | 54 except recipe_api.AggregatedStepFailure as f: |
47 raise api.step.StepFailure("You can catch step failures.") | 55 raise api.step.StepFailure("You can catch step failures.") |
48 | 56 |
49 # Some steps are needed from an infrastructure point of view. If these | 57 # Some steps are needed from an infrastructure point of view. If these |
50 # steps fail, the build stops, but doesn't get turned red because it's | 58 # steps fail, the build stops, but doesn't get turned red because it's |
51 # not the developers' fault. | 59 # not the developers' fault. |
52 try: | 60 try: |
53 api.step('cleanup', ['echo', 'cleaning', 'up', 'build'], infra_step=True) | 61 api.step('cleanup', ['echo', 'cleaning', 'up', 'build'], infra_step=True) |
54 except api.step.InfraFailure as f: | 62 except api.step.InfraFailure as f: |
55 assert f.result.presentation.status == api.step.EXCEPTION | 63 assert f.result.presentation.status == api.step.EXCEPTION |
56 | 64 |
57 # Run a step through a made-up wrapper program. | 65 # Run a step through a made-up wrapper program. |
58 api.step('application', ['echo', 'main', 'application'], | 66 api.step('application', ['echo', 'main', 'application'], |
59 wrapper=['python', 'test-wrapper.py', '-v', '--']) | 67 wrapper=['python', '-c', 'import sys; print sys.argv']) |
60 | 68 |
61 if api.properties.get('access_invalid_data'): | 69 if api.properties.get('access_invalid_data'): |
62 result = api.step('no-op', ['echo', 'I', 'do', 'nothing']) | 70 result = api.step('no-op', ['echo', 'I', 'do', 'nothing']) |
63 # Trying to access non-existent attributes on the result should raise. | 71 # Trying to access non-existent attributes on the result should raise. |
64 _ = result.json.output | 72 _ = result.json.output |
65 | 73 |
66 # You can also raise a warning, which will act like a step failure, but | |
67 # will turn the build yellow, and stop the build. | |
68 raise api.step.StepWarning("Warning, robots approaching!") | |
69 | |
70 | 74 |
71 def GenTests(api): | 75 def GenTests(api): |
72 yield ( | 76 yield ( |
73 api.test('basic') + | 77 api.test('basic') + |
74 api.step_data('anything is cool', retcode=3) | 78 api.step_data('anything is cool', retcode=3) |
75 ) | 79 ) |
76 | 80 |
77 # If you don't have the expect_exception in this test, you will get something | 81 # If you don't have the expect_exception in this test, you will get something |
78 # like this output. | 82 # like this output. |
79 # ====================================================================== | 83 # ====================================================================== |
80 # ERROR: step:example.exceptional (..../exceptional.json) | 84 # ERROR: step:example.exceptional (..../exceptional.json) |
81 # ---------------------------------------------------------------------- | 85 # ---------------------------------------------------------------------- |
82 # Traceback (most recent call last): | 86 # Traceback (most recent call last): |
83 # <full stack trace ommitted> | 87 # <full stack trace ommitted> |
84 # File "annotated_run.py", line 537, in run | 88 # File "annotated_run.py", line 537, in run |
85 # retcode = steps_function(api) | 89 # retcode = steps_function(api) |
86 # File "recipe_modules/step/example.py", line 39, in RunSteps | 90 # File "recipe_modules/step/example.py", line 39, in RunSteps |
87 # raise ValueError('goodbye must exit 0!') | 91 # raise ValueError('goodbye must exit 0!') |
88 # ValueError: goodbye must exit 0! | 92 # ValueError: goodbye must exit 0! |
89 | 93 |
90 yield ( | 94 yield ( |
91 api.test('exceptional') + | 95 api.test('exceptional') + |
92 api.step_data('goodbye (2)', retcode=1) + | 96 api.step_data('goodbye (2)', retcode=1) + |
93 api.expect_exception('ValueError') | 97 api.expect_exception('ValueError') |
94 ) | 98 ) |
95 | 99 |
96 yield ( | 100 yield ( |
| 101 api.test('warning') + |
| 102 api.step_data('warning', retcode=1) + |
| 103 api.expect_exception('StepWarning') |
| 104 ) |
| 105 |
| 106 yield ( |
97 api.test('defer_results') + | 107 api.test('defer_results') + |
98 api.step_data('testa', retcode=1) | 108 api.step_data('testa', retcode=1) |
99 ) | 109 ) |
100 | 110 |
101 yield ( | 111 yield ( |
102 api.test('invalid_access') + | 112 api.test('invalid_access') + |
103 api.properties(access_invalid_data=True) + | 113 api.properties(access_invalid_data=True) + |
104 api.expect_exception('StepDataAttributeError') | 114 api.expect_exception('StepDataAttributeError') |
105 ) | 115 ) |
106 | 116 |
107 yield ( | 117 yield ( |
108 api.test('infra_failure') + | 118 api.test('infra_failure') + |
109 api.properties(raise_infra_failure=True) + | 119 api.properties(raise_infra_failure=True) + |
110 api.step_data('cleanup', retcode=1) | 120 api.step_data('cleanup', retcode=1) |
111 ) | 121 ) |
OLD | NEW |