Add method for setting test data for get_files_affected_by_patch.

The get_files_affected_by_patch method on the test API will return a
TestData object that determines the output of the "git diff" call. a
Test was added specifically for the get_files_affected_by_patch API
method to ensure that the test API operates as expected.

Change-Id: Ia1846700461757a72ed518894a5a38a8ca54fcc9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3422006
Auto-Submit: Garrett Beaty <gbeaty@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Garrett Beaty <gbeaty@google.com>
changes/06/3422006/2
Garrett Beaty 3 years ago committed by LUCI CQ
parent 0dc69c4e79
commit dd93ebcac8

@ -40,6 +40,7 @@
* [tryserver:tests/gerrit_change_fetch_ref_timeout](#recipes-tryserver_tests_gerrit_change_fetch_ref_timeout) (Python3 ✅) * [tryserver:tests/gerrit_change_fetch_ref_timeout](#recipes-tryserver_tests_gerrit_change_fetch_ref_timeout) (Python3 ✅)
* [tryserver:tests/gerrit_change_owner](#recipes-tryserver_tests_gerrit_change_owner) (Python3 ✅) * [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/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/require_is_tryserver](#recipes-tryserver_tests_require_is_tryserver) (Python3 ✅) * [tryserver:tests/require_is_tryserver](#recipes-tryserver_tests_require_is_tryserver) (Python3 ✅)
* [windows_sdk:examples/full](#recipes-windows_sdk_examples_full) (Python3 ✅) * [windows_sdk:examples/full](#recipes-windows_sdk_examples_full) (Python3 ✅)
## Recipe Modules ## Recipe Modules
@ -852,7 +853,7 @@ Args:
* report_files_via_property: name of the output property to report the * report_files_via_property: name of the output property to report the
list of the files. If None (default), do not report. list of the files. If None (default), do not report.
Returned paths will be relative to to patch_root. Returned paths will be relative to to api.path['root'].
&mdash; **def [get\_footer](/recipes/recipe_modules/tryserver/api.py#365)(self, tag, patch_text=None):** &mdash; **def [get\_footer](/recipes/recipe_modules/tryserver/api.py#365)(self, tag, patch_text=None):**
@ -1139,6 +1140,13 @@ PYTHON_VERSION_COMPATIBILITY: PY2+3
PYTHON_VERSION_COMPATIBILITY: PY2+3 PYTHON_VERSION_COMPATIBILITY: PY2+3
&mdash; **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py#18)(api):** &mdash; **def [RunSteps](/recipes/recipe_modules/tryserver/tests/gerrit_change_target_ref.py#18)(api):**
### *recipes* / [tryserver:tests/get\_files\_affected\_by\_patch](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py)
[DEPS](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py#9): [tryserver](#recipe_modules-tryserver), [recipe\_engine/assertions][recipe_engine/recipe_modules/assertions], [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: PY2+3
&mdash; **def [RunSteps](/recipes/recipe_modules/tryserver/tests/get_files_affected_by_patch.py#18)(api):**
### *recipes* / [tryserver:tests/require\_is\_tryserver](/recipes/recipe_modules/tryserver/tests/require_is_tryserver.py) ### *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] [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]

@ -233,7 +233,7 @@ class TryserverApi(recipe_api.RecipeApi):
* report_files_via_property: name of the output property to report the * report_files_via_property: name of the output property to report the
list of the files. If None (default), do not report. list of the files. If None (default), do not report.
Returned paths will be relative to to patch_root. Returned paths will be relative to to api.path['root'].
""" """
cwd = self.m.context.cwd or self.m.path['start_dir'].join(patch_root) cwd = self.m.context.cwd or self.m.path['start_dir'].join(patch_root)
with self.m.context(cwd=cwd): with self.m.context(cwd=cwd):

@ -232,35 +232,6 @@
"@@@STEP_LOG_END@json.output (exception)@@@" "@@@STEP_LOG_END@json.output (exception)@@@"
] ]
}, },
{
"cmd": [
"git",
"-c",
"core.quotePath=false",
"diff",
"--cached",
"--name-only"
],
"infra_step": true,
"luci_context": {
"realm": {
"name": "chromium:linux"
},
"resultdb": {
"current_invocation": {
"name": "invocations/build:8945511751514863184",
"update_token": "token"
},
"hostname": "rdbhost"
}
},
"name": "git diff to analyze patch",
"~followup_annotations": [
"@@@STEP_LOG_LINE@files@None/foo.cc@@@",
"@@@STEP_LOG_END@files@@@",
"@@@SET_BUILD_PROPERTY@affected_files@{\"first_100\": [\"None/foo.cc\"], \"total_count\": 1}@@@"
]
},
{ {
"cmd": [], "cmd": [],
"name": "TRYJOB SET SUBPROJECT_TAG", "name": "TRYJOB SET SUBPROJECT_TAG",

@ -232,35 +232,6 @@
"@@@STEP_LOG_END@json.output (exception)@@@" "@@@STEP_LOG_END@json.output (exception)@@@"
] ]
}, },
{
"cmd": [
"git",
"-c",
"core.quotePath=false",
"diff",
"--cached",
"--name-only"
],
"infra_step": true,
"luci_context": {
"realm": {
"name": "chromium:linux"
},
"resultdb": {
"current_invocation": {
"name": "invocations/build:8945511751514863184",
"update_token": "token"
},
"hostname": "rdbhost"
}
},
"name": "git diff to analyze patch",
"~followup_annotations": [
"@@@STEP_LOG_LINE@files@None/foo.cc@@@",
"@@@STEP_LOG_END@files@@@",
"@@@SET_BUILD_PROPERTY@affected_files@{\"first_100\": [\"None/foo.cc\"], \"total_count\": 1}@@@"
]
},
{ {
"cmd": [], "cmd": [],
"name": "TRYJOB SET SUBPROJECT_TAG", "name": "TRYJOB SET SUBPROJECT_TAG",

@ -1,21 +1,4 @@
[ [
{
"cmd": [
"git",
"-c",
"core.quotePath=false",
"diff",
"--cached",
"--name-only"
],
"infra_step": true,
"name": "git diff to analyze patch",
"~followup_annotations": [
"@@@STEP_LOG_LINE@files@foo.cc@@@",
"@@@STEP_LOG_END@files@@@",
"@@@SET_BUILD_PROPERTY@affected_files@{\"first_100\": [\"foo.cc\"], \"total_count\": 1}@@@"
]
},
{ {
"cmd": [ "cmd": [
"vpython", "vpython",

@ -1,22 +1,4 @@
[ [
{
"cmd": [
"git",
"-c",
"core.quotePath=false",
"diff",
"--cached",
"--name-only"
],
"cwd": "[START_DIR]\\sub\\project",
"infra_step": true,
"name": "git diff to analyze patch",
"~followup_annotations": [
"@@@STEP_LOG_LINE@files@sub/project/foo.cc@@@",
"@@@STEP_LOG_END@files@@@",
"@@@SET_BUILD_PROPERTY@affected_files@{\"first_100\": [\"sub/project/foo.cc\"], \"total_count\": 1}@@@"
]
},
{ {
"cmd": [ "cmd": [
"vpython", "vpython",

@ -45,10 +45,6 @@ def RunSteps(api):
if api.tryserver.is_gerrit_issue: if api.tryserver.is_gerrit_issue:
api.tryserver.get_footers() api.tryserver.get_footers()
api.tryserver.get_footer('testfooter') api.tryserver.get_footer('testfooter')
api.tryserver.get_files_affected_by_patch(
api.properties.get('test_patch_root'),
report_files_via_property='affected_files',
)
if api.tryserver.is_tryserver: if api.tryserver.is_tryserver:
api.tryserver.set_subproject_tag('v8') api.tryserver.set_subproject_tag('v8')

@ -12,3 +12,22 @@ class TryserverTestApi(recipe_test_api.RecipeTestApi):
def gerrit_change_target_ref(target_ref): def gerrit_change_target_ref(target_ref):
assert target_ref.startswith('refs/') assert target_ref.startswith('refs/')
return target_ref return target_ref
def get_files_affected_by_patch(self,
files,
step_name='git diff to analyze patch'):
"""Override test data for the `get_files_affected_by_patch` method.
Args:
files: The files that git should report as changed as paths
relative to the root of the repo.
Example:
yield api.test(
'my_test',
api.tryserver.get_files_affected_by_patch('foo.cc',
'bar/baz.cc'),
)
"""
output = self.m.raw_io.stream_output('\n'.join(files))
return self.override_step_data(step_name, output)

@ -0,0 +1,24 @@
[
{
"cmd": [
"git",
"-c",
"core.quotePath=false",
"diff",
"--cached",
"--name-only"
],
"cwd": "[START_DIR]/test/patch/root",
"infra_step": true,
"name": "git diff to analyze patch",
"~followup_annotations": [
"@@@STEP_LOG_LINE@files@test/patch/root/baz/shaz.cc@@@",
"@@@STEP_LOG_LINE@files@test/patch/root/foo/bar.cc@@@",
"@@@STEP_LOG_END@files@@@",
"@@@SET_BUILD_PROPERTY@affected-files@{\"first_100\": [\"test/patch/root/baz/shaz.cc\", \"test/patch/root/foo/bar.cc\"], \"total_count\": 2}@@@"
]
},
{
"name": "$result"
}
]

@ -0,0 +1,92 @@
# Copyright 2022 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/path',
'recipe_engine/platform',
'recipe_engine/properties',
]
def RunSteps(api):
files = api.tryserver.get_files_affected_by_patch(
api.properties['patch_root'],
report_files_via_property=api.properties.get('report_files_via_property'))
api.assertions.assertCountEqual(files, api.properties['expected_files'])
def GenTests(api):
def no_properties_set(check, steps, step_name):
check(not steps[step_name].output_properties)
yield api.test(
'basic',
api.properties(
patch_root='',
expected_files=['foo.cc'],
),
api.post_check(no_properties_set, 'git diff to analyze patch'),
api.post_check(post_process.StatusSuccess),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'patch_root',
api.properties(
patch_root='test/patch/root',
expected_files=['test/patch/root/foo.cc'],
),
api.post_check(post_process.StatusSuccess),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'test-data',
api.tryserver.get_files_affected_by_patch(['foo/bar.cc', 'baz/shaz.cc']),
api.properties(
patch_root='test/patch/root',
expected_files=[
'test/patch/root/foo/bar.cc',
'test/patch/root/baz/shaz.cc',
],
),
api.post_check(post_process.StatusSuccess),
api.post_process(post_process.DropExpectation),
)
yield api.test(
'report-files-via-property',
api.tryserver.get_files_affected_by_patch(['foo/bar.cc', 'baz/shaz.cc']),
api.properties(
patch_root='test/patch/root',
report_files_via_property='affected-files',
expected_files=[
'test/patch/root/foo/bar.cc',
'test/patch/root/baz/shaz.cc',
],
),
api.post_check(post_process.StatusSuccess),
)
yield api.test(
'windows',
api.tryserver.get_files_affected_by_patch(['foo/bar.cc', 'baz/shaz.cc']),
api.platform('win', 32),
api.properties(
patch_root='test\\patch\\root',
report_files_via_property='affected-files',
expected_files=[
'test/patch/root/foo/bar.cc',
'test/patch/root/baz/shaz.cc',
],
),
api.post_check(post_process.StatusSuccess),
api.post_process(post_process.DropExpectation),
)
Loading…
Cancel
Save