PRESUBMIT.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright 2019 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. import re
  5. """Presubmit for build/util"""
  6. USE_PYTHON3 = True
  7. def _GetFilesToSkip(input_api):
  8. files_to_skip = []
  9. affected_files = input_api.change.AffectedFiles()
  10. version_script_change = next(
  11. (f for f in affected_files
  12. if re.search('\\/version\\.py$|\\/version_test\\.py$', f.LocalPath())),
  13. None)
  14. if version_script_change is None:
  15. files_to_skip.append('version_test\\.py$')
  16. android_chrome_version_script_change = next(
  17. (f for f in affected_files if re.search(
  18. '\\/android_chrome_version\\.py$|'
  19. '\\/android_chrome_version_test\\.py$', f.LocalPath())), None)
  20. if android_chrome_version_script_change is None:
  21. files_to_skip.append('android_chrome_version_test\\.py$')
  22. return files_to_skip
  23. def _GetPythonUnitTests(input_api, output_api):
  24. # No need to test if files are unchanged
  25. files_to_skip = _GetFilesToSkip(input_api)
  26. return input_api.canned_checks.GetUnitTestsRecursively(
  27. input_api,
  28. output_api,
  29. input_api.PresubmitLocalPath(),
  30. files_to_check=['.*_test\\.py$'],
  31. files_to_skip=files_to_skip,
  32. run_on_python2=False,
  33. run_on_python3=True,
  34. skip_shebang_check=True)
  35. def CommonChecks(input_api, output_api):
  36. """Presubmit checks run on both upload and commit.
  37. """
  38. checks = []
  39. checks.extend(_GetPythonUnitTests(input_api, output_api))
  40. return input_api.RunTests(checks, False)
  41. def CheckChangeOnUpload(input_api, output_api):
  42. """Presubmit checks on CL upload."""
  43. return CommonChecks(input_api, output_api)
  44. def CheckChangeOnCommit(input_api, output_api):
  45. """Presubmit checks on commit."""
  46. return CommonChecks(input_api, output_api)