Commit 9ebcfa6b authored by Fabrice de Gans's avatar Fabrice de Gans Committed by LUCI CQ

[code-health] Run CheckVPythonSpec under python3

This change also makes CheckVPythonSpec() look for .vpython3 files.

Bug: 1336295
Change-Id: I4bbec48debe42748811a8cfcef6da9602017d4bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3891974Reviewed-by: 's avatarJosip Sokcevic <sokcevic@google.com>
Commit-Queue: Fabrice de Gans <fdegans@chromium.org>
parent 635383fb
......@@ -1675,7 +1675,8 @@ def CheckForCommitObjects(input_api, output_api):
def CheckVPythonSpec(input_api, output_api, file_filter=None):
"""Validates any changed .vpython files with vpython verification tool.
"""Validates any changed .vpython and .vpython3 files with vpython
verification tool.
Args:
input_api: Bag of input related interfaces.
......@@ -1688,17 +1689,18 @@ def CheckVPythonSpec(input_api, output_api, file_filter=None):
Returns:
A list of input_api.Command objects containing verification commands.
"""
file_filter = file_filter or (lambda f: f.LocalPath().endswith('.vpython'))
file_filter = file_filter or (lambda f: f.LocalPath().endswith('.vpython') or
f.LocalPath().endswith('.vpython3'))
affected_files = input_api.AffectedTestableFiles(file_filter=file_filter)
affected_files = map(lambda f: f.AbsoluteLocalPath(), affected_files)
commands = []
for f in affected_files:
commands.append(input_api.Command(
'Verify %s' % f,
['vpython', '-vpython-spec', f, '-vpython-tool', 'verify'],
{'stderr': input_api.subprocess.STDOUT},
output_api.PresubmitError))
commands.append(
input_api.Command('Verify %s' % f, [
input_api.python3_executable, '-vpython-spec', f, '-vpython-tool',
'verify'
], {'stderr': input_api.subprocess.STDOUT}, output_api.PresubmitError))
return commands
......
......@@ -1785,6 +1785,7 @@ class CannedChecksUnittest(PresubmitTestsBase):
input_api.tbr = False
input_api.dry_run = None
input_api.python_executable = 'pyyyyython'
input_api.python3_executable = 'pyyyyython3'
input_api.platform = sys.platform
input_api.cpu_count = 2
input_api.time = time
......@@ -3046,29 +3047,33 @@ the current line as well!
def testCannedCheckVPythonSpec(self):
change = presubmit.Change('a', 'b', self.fake_root_dir, None, 0, 0, None)
input_api = self.MockInputApi(change, False)
affected_filenames = ['/path1/to/.vpython', '/path1/to/.vpython3']
affected_files = []
affected_file = mock.MagicMock(presubmit.GitAffectedFile)
affected_file.AbsoluteLocalPath.return_value = '/path1/to/.vpython'
input_api.AffectedTestableFiles.return_value = [affected_file]
for filename in affected_filenames:
affected_file = mock.MagicMock(presubmit.GitAffectedFile)
affected_file.AbsoluteLocalPath.return_value = filename
affected_files.append(affected_file)
input_api.AffectedTestableFiles.return_value = affected_files
commands = presubmit_canned_checks.CheckVPythonSpec(
input_api, presubmit.OutputApi)
self.assertEqual(len(commands), 1)
self.assertEqual(commands[0].name, 'Verify /path1/to/.vpython')
self.assertEqual(commands[0].cmd, [
'vpython',
'-vpython-spec', '/path1/to/.vpython',
'-vpython-tool', 'verify'
])
self.assertDictEqual(
commands[0].kwargs,
{
'stderr': input_api.subprocess.STDOUT,
'stdout': input_api.subprocess.PIPE,
'stdin': input_api.subprocess.PIPE,
})
self.assertEqual(commands[0].message, presubmit.OutputApi.PresubmitError)
self.assertIsNone(commands[0].info)
self.assertEqual(len(commands), len(affected_filenames))
for i in range(0, len(commands)):
self.assertEqual(commands[i].name, 'Verify ' + affected_filenames[i])
self.assertEqual(commands[i].cmd, [
input_api.python3_executable, '-vpython-spec', affected_filenames[i],
'-vpython-tool', 'verify'
])
self.assertDictEqual(
commands[0].kwargs, {
'stderr': input_api.subprocess.STDOUT,
'stdout': input_api.subprocess.PIPE,
'stdin': input_api.subprocess.PIPE,
})
self.assertEqual(commands[0].message, presubmit.OutputApi.PresubmitError)
self.assertIsNone(commands[0].info)
class ThreadPoolTest(unittest.TestCase):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment