From 4756d7c420fa4b6ecd8f9776638de7c7301f021b Mon Sep 17 00:00:00 2001 From: Brian Sheedy Date: Wed, 22 Feb 2023 01:44:09 +0000 Subject: [PATCH] Add tryserver test_api method Updates the tryserver recipe module's test_api to support overriding get_footers data. Bug: angleproject:7985 Change-Id: Ie571bc8d1c77cbb1cd4f18955b50d56e377ca903 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4278466 Reviewed-by: Robbie Iannucci Auto-Submit: Brian Sheedy Commit-Queue: Robbie Iannucci Commit-Queue: Brian Sheedy --- recipes/README.recipes.md | 8 +++ recipes/recipe_modules/tryserver/test_api.py | 15 +++++ .../tryserver/tests/get_footers.py | 65 +++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 recipes/recipe_modules/tryserver/tests/get_footers.py diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 12d47d69c..b07be7d05 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -43,6 +43,7 @@ * [tryserver:tests/gerrit_change_owner](#recipes-tryserver_tests_gerrit_change_owner) (Python3 ✅) * [tryserver:tests/gerrit_change_target_ref](#recipes-tryserver_tests_gerrit_change_target_ref) (Python3 ✅) * [tryserver:tests/get_files_affected_by_patch](#recipes-tryserver_tests_get_files_affected_by_patch) (Python3 ✅) + * [tryserver:tests/get_footers](#recipes-tryserver_tests_get_footers) (Python3 ✅) * [tryserver:tests/require_is_tryserver](#recipes-tryserver_tests_require_is_tryserver) (Python3 ✅) * [windows_sdk:examples/full](#recipes-windows_sdk_examples_full) (Python3 ✅) ## Recipe Modules @@ -1182,6 +1183,13 @@ PYTHON_VERSION_COMPATIBILITY: PY3 PYTHON_VERSION_COMPATIBILITY: PY3 — **def [RunSteps](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py#18)(api):** +### *recipes* / [tryserver:tests/get\_footers](/recipes/recipe_modules/tryserver/tests/get_footers.py) + +[DEPS](/recipes/recipe_modules/tryserver/tests/get_footers.py#9): [tryserver](#recipe_modules-tryserver), [recipe\_engine/assertions][recipe_engine/recipe_modules/assertions], [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/path][recipe_engine/recipe_modules/path], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/properties][recipe_engine/recipe_modules/properties] + +PYTHON_VERSION_COMPATIBILITY: PY3 + +— **def [RunSteps](/recipes/recipe_modules/tryserver/tests/get_footers.py#19)(api):** ### *recipes* / [tryserver:tests/require\_is\_tryserver](/recipes/recipe_modules/tryserver/tests/require_is_tryserver.py) [DEPS](/recipes/recipe_modules/tryserver/tests/require_is_tryserver.py#12): [tryserver](#recipe_modules-tryserver), [recipe\_engine/buildbucket][recipe_engine/recipe_modules/buildbucket], [recipe\_engine/properties][recipe_engine/recipe_modules/properties] diff --git a/recipes/recipe_modules/tryserver/test_api.py b/recipes/recipe_modules/tryserver/test_api.py index 54e87b06c..a901b7e76 100644 --- a/recipes/recipe_modules/tryserver/test_api.py +++ b/recipes/recipe_modules/tryserver/test_api.py @@ -31,3 +31,18 @@ class TryserverTestApi(recipe_test_api.RecipeTestApi): """ output = self.m.raw_io.stream_output('\n'.join(files)) return self.override_step_data(step_name, output) + + def get_footers(self, footers, step_name='parse description'): + """Override test data for the `get_footers` method. + + Args: + footers: A dict containing key/value pairs for footers to return. To be + accurate to git_footers.py's actual behavior, values should be lists. + + Example: + yield api.test( + 'my_test', + api.tryserver.get_footers({'Footer-Key': ['footer_value']})) + """ + output = self.m.json.output(footers) + return self.override_step_data(step_name, output) diff --git a/recipes/recipe_modules/tryserver/tests/get_footers.py b/recipes/recipe_modules/tryserver/tests/get_footers.py new file mode 100644 index 000000000..070bbf677 --- /dev/null +++ b/recipes/recipe_modules/tryserver/tests/get_footers.py @@ -0,0 +1,65 @@ +# Copyright 2023 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +from recipe_engine import post_process + +PYTHON_VERSION_COMPATIBILITY = 'PY2+3' + +DEPS = [ + 'tryserver', + 'recipe_engine/assertions', + 'recipe_engine/buildbucket', + 'recipe_engine/path', + 'recipe_engine/platform', + 'recipe_engine/properties', +] + + +def RunSteps(api): + footers = api.tryserver.get_footers() + api.assertions.assertCountEqual(footers, api.properties['expected_footers']) + + +def GenTests(api): + yield api.test( + 'no-footers', + api.buildbucket.try_build( + 'chromium', + 'linux', + ), + api.properties(expected_footers={}), + api.tryserver.get_footers({}), + api.post_check(post_process.StatusSuccess), + api.post_process(post_process.DropExpectation), + ) + + yield api.test( + 'single-footer', + api.buildbucket.try_build( + 'chromium', + 'linux', + ), + api.properties(expected_footers={'Some-Footer': ['True']}), + api.tryserver.get_footers({'Some-Footer': ['True']}), + api.post_check(post_process.StatusSuccess), + api.post_process(post_process.DropExpectation), + ) + + yield api.test( + 'multiple-footers', + api.buildbucket.try_build( + 'chromium', + 'linux', + ), + api.properties(expected_footers={ + 'Some-Footer': ['True'], + 'Another-Footer': ['Foo', 'Bar'] + }), + api.tryserver.get_footers({ + 'Some-Footer': ['True'], + 'Another-Footer': ['Foo', 'Bar'] + }), + api.post_check(post_process.StatusSuccess), + api.post_process(post_process.DropExpectation), + )