|
@@ -10,7 +10,6 @@ import io as _io
|
|
|
import os as _os
|
|
|
import zlib
|
|
|
|
|
|
-from warnings import warn
|
|
|
_HERE = _os.path.dirname(_os.path.abspath(__file__))
|
|
|
|
|
|
# These filters will be disabled if callers do not explicitly supply a
|
|
@@ -837,16 +836,22 @@ def GetUnitTestsInDirectory(input_api,
|
|
|
files_to_check=None,
|
|
|
files_to_skip=None,
|
|
|
env=None,
|
|
|
- run_on_python2=True,
|
|
|
+ run_on_python2=False,
|
|
|
run_on_python3=True,
|
|
|
- skip_shebang_check=False,
|
|
|
+ skip_shebang_check=True,
|
|
|
allowlist=None,
|
|
|
blocklist=None):
|
|
|
"""Lists all files in a directory and runs them. Doesn't recurse.
|
|
|
|
|
|
It's mainly a wrapper for RunUnitTests. Use allowlist and blocklist to filter
|
|
|
- tests accordingly.
|
|
|
+ tests accordingly. run_on_python2, run_on_python3, and skip_shebang_check are
|
|
|
+ no longer used but have to be retained because of the many callers in other
|
|
|
+ repos that pass them in.
|
|
|
"""
|
|
|
+ del run_on_python2
|
|
|
+ del run_on_python3
|
|
|
+ del skip_shebang_check
|
|
|
+
|
|
|
unit_tests = []
|
|
|
test_path = input_api.os_path.abspath(
|
|
|
input_api.os_path.join(input_api.PresubmitLocalPath(), directory))
|
|
@@ -874,27 +879,26 @@ def GetUnitTestsInDirectory(input_api,
|
|
|
'Out of %d files, found none that matched c=%r, s=%r in directory %s'
|
|
|
% (found, files_to_check, files_to_skip, directory))
|
|
|
]
|
|
|
- return GetUnitTests(input_api, output_api, unit_tests, env, run_on_python2,
|
|
|
- run_on_python3, skip_shebang_check)
|
|
|
+ return GetUnitTests(input_api, output_api, unit_tests, env)
|
|
|
|
|
|
|
|
|
def GetUnitTests(input_api,
|
|
|
output_api,
|
|
|
unit_tests,
|
|
|
env=None,
|
|
|
- run_on_python2=True,
|
|
|
+ run_on_python2=False,
|
|
|
run_on_python3=True,
|
|
|
- skip_shebang_check=False):
|
|
|
+ skip_shebang_check=True):
|
|
|
"""Runs all unit tests in a directory.
|
|
|
|
|
|
On Windows, sys.executable is used for unit tests ending with ".py".
|
|
|
+ run_on_python2, run_on_python3, and skip_shebang_check are no longer used but
|
|
|
+ have to be retained because of the many callers in other repos that pass them
|
|
|
+ in.
|
|
|
"""
|
|
|
- assert run_on_python3 or run_on_python2, (
|
|
|
- 'At least one of "run_on_python2" or "run_on_python3" must be set.')
|
|
|
- def has_py3_shebang(test):
|
|
|
- with _io.open(test, encoding='utf-8') as f:
|
|
|
- maybe_shebang = f.readline()
|
|
|
- return maybe_shebang.startswith('#!') and 'python3' in maybe_shebang
|
|
|
+ del run_on_python2
|
|
|
+ del run_on_python3
|
|
|
+ del skip_shebang_check
|
|
|
|
|
|
# We don't want to hinder users from uploading incomplete patches, but we do
|
|
|
# want to report errors as errors when doing presubmit --all testing.
|
|
@@ -918,31 +922,11 @@ def GetUnitTests(input_api,
|
|
|
kwargs=kwargs,
|
|
|
message=message_type))
|
|
|
else:
|
|
|
- test_run = False
|
|
|
- # TODO(crbug.com/1223478): The intent for this line was to run the test
|
|
|
- # on python3 if the file has a shebang OR if it was explicitly requested
|
|
|
- # to run on python3. Since tests have been broken since this landed, we
|
|
|
- # introduced the |skip_shebang_check| argument to work around the issue
|
|
|
- # until every caller in Chromium has been fixed.
|
|
|
- if (skip_shebang_check or has_py3_shebang(unit_test)) and run_on_python3:
|
|
|
- results.append(input_api.Command(
|
|
|
- name=unit_test,
|
|
|
- cmd=cmd,
|
|
|
- kwargs=kwargs,
|
|
|
- message=message_type,
|
|
|
- python3=True))
|
|
|
- test_run = True
|
|
|
- if run_on_python2:
|
|
|
- results.append(input_api.Command(
|
|
|
- name=unit_test,
|
|
|
- cmd=cmd,
|
|
|
- kwargs=kwargs,
|
|
|
- message=message_type))
|
|
|
- test_run = True
|
|
|
- if not test_run:
|
|
|
- results.append(output_api.PresubmitError(
|
|
|
- "The %s test was not run. You may need to add\n"
|
|
|
- "skip_shebang_check=True for python3 tests." % unit_test))
|
|
|
+ results.append(
|
|
|
+ input_api.Command(name=unit_test,
|
|
|
+ cmd=cmd,
|
|
|
+ kwargs=kwargs,
|
|
|
+ message=message_type))
|
|
|
return results
|
|
|
|
|
|
|
|
@@ -951,14 +935,20 @@ def GetUnitTestsRecursively(input_api,
|
|
|
directory,
|
|
|
files_to_check,
|
|
|
files_to_skip,
|
|
|
- run_on_python2=True,
|
|
|
+ run_on_python2=False,
|
|
|
run_on_python3=True,
|
|
|
- skip_shebang_check=False):
|
|
|
+ skip_shebang_check=True):
|
|
|
"""Gets all files in the directory tree (git repo) that match files_to_check.
|
|
|
|
|
|
Restricts itself to only find files within the Change's source repo, not
|
|
|
- dependencies.
|
|
|
+ dependencies. run_on_python2, run_on_python3, and skip_shebang_check are no
|
|
|
+ longer used but have to be retained because of the many callers in other repos
|
|
|
+ that pass them in.
|
|
|
"""
|
|
|
+ del run_on_python2
|
|
|
+ del run_on_python3
|
|
|
+ del skip_shebang_check
|
|
|
+
|
|
|
def check(filename):
|
|
|
return (any(input_api.re.match(f, filename) for f in files_to_check) and
|
|
|
not any(input_api.re.match(f, filename) for f in files_to_skip))
|
|
@@ -979,12 +969,7 @@ def GetUnitTestsRecursively(input_api,
|
|
|
% (found, files_to_check, files_to_skip, directory))
|
|
|
]
|
|
|
|
|
|
- return GetUnitTests(input_api,
|
|
|
- output_api,
|
|
|
- tests,
|
|
|
- run_on_python2=run_on_python2,
|
|
|
- run_on_python3=run_on_python3,
|
|
|
- skip_shebang_check=skip_shebang_check)
|
|
|
+ return GetUnitTests(input_api, output_api, tests)
|
|
|
|
|
|
|
|
|
def GetPythonUnitTests(input_api, output_api, unit_tests, python3=False):
|
|
@@ -1026,10 +1011,7 @@ def GetPythonUnitTests(input_api, output_api, unit_tests, python3=False):
|
|
|
backpath.append(env.get('PYTHONPATH'))
|
|
|
env['PYTHONPATH'] = input_api.os_path.pathsep.join((backpath))
|
|
|
env.pop('VPYTHON_CLEAR_PYTHONPATH', None)
|
|
|
- if python3:
|
|
|
- cmd = [input_api.python3_executable, '-m', '%s' % unit_test]
|
|
|
- else:
|
|
|
- cmd = [input_api.python_executable, '-m', '%s' % unit_test]
|
|
|
+ cmd = [input_api.python3_executable, '-m', '%s' % unit_test]
|
|
|
results.append(input_api.Command(
|
|
|
name=unit_test_name,
|
|
|
cmd=cmd,
|
|
@@ -1116,8 +1098,7 @@ def GetPylint(input_api,
|
|
|
files_to_skip = tuple(files_to_skip or input_api.DEFAULT_FILES_TO_SKIP)
|
|
|
extra_paths_list = extra_paths_list or []
|
|
|
|
|
|
- assert version in ('2.6', '2.7'), \
|
|
|
- 'Unsupported pylint version: %s' % version
|
|
|
+ assert version in ('2.6', '2.7'), 'Unsupported pylint version: %s' % version
|
|
|
|
|
|
if input_api.is_committing or input_api.no_diffs:
|
|
|
error_type = output_api.PresubmitError
|