| # Copyright 2021 The Pigweed Authors |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| # use this file except in compliance with the License. You may obtain a copy of |
| # the License at |
| # |
| # https://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| # License for the specific language governing permissions and limitations under |
| # the License. |
| """Full test of util module.""" |
| |
| from __future__ import annotations |
| |
| import re |
| from collections.abc import Iterator |
| |
| from recipe_engine import recipe_api, recipe_test_api |
| |
| from PB.recipe_modules.pigweed.util.tests.full import InputProperties |
| |
| DEPS = [ |
| 'pigweed/util', |
| 'recipe_engine/buildbucket', |
| 'recipe_engine/file', |
| 'recipe_engine/path', |
| 'recipe_engine/properties', |
| 'recipe_engine/step', |
| ] |
| |
| INLINE_PROPERTIES_PROTO = """ |
| message InputProperties { |
| string regex = 1; |
| repeated string comments = 2; |
| } |
| """ |
| |
| PROPERTIES = InputProperties |
| |
| |
| def RunSteps(api: recipe_api.RecipeScriptApi, props: InputProperties): |
| with api.step.nest('gerrit'): |
| api.util.get_change_with_comments() |
| if not api.util.find_matching_comment( |
| re.compile(props.regex), |
| props.comments, |
| ): |
| raise api.step.StepFailure('failure') |
| api.file.write_json( |
| 'write metadata', |
| api.path.start_dir / 'metadata.json', |
| api.util.build_metadata(), |
| ) |
| |
| api.util.on_last_iteration(60, debug=True) |
| |
| |
| def GenTests(api) -> Iterator[recipe_test_api.TestData]: |
| yield ( |
| api.test('found') |
| + api.buildbucket.try_build() |
| + api.properties(regex=r'foo', comments=['', 'foobar']) |
| + api.util.change_comment('comment') |
| ) |
| |
| yield ( |
| api.test( |
| 'not_found', |
| status='FAILURE', |
| ) |
| + api.buildbucket.try_build() |
| + api.properties(regex=r'foo', comments=['', 'fubar']) |
| ) |