PRESUBMIT.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) 2017 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. """Top-level presubmit script for checkteamtags
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
  6. details on the presubmit API.
  7. """
  8. USE_PYTHON3 = True
  9. def CheckChangeOnUpload(input_api, output_api):
  10. return _CommonChecks(input_api, output_api)
  11. def CheckChangeOnCommit(input_api, output_api):
  12. return _CommonChecks(input_api, output_api)
  13. def _CommonChecks(input_api, output_api):
  14. """Does all presubmit checks for chekteamtags."""
  15. results = []
  16. results.extend(_RunUnitTests(input_api, output_api))
  17. results.extend(_RunPyLint(input_api, output_api))
  18. return results
  19. def _RunUnitTests(input_api, output_api):
  20. """Runs unit tests for checkteamtags."""
  21. repo_root = input_api.change.RepositoryRoot()
  22. checkteamtags_dir = input_api.os_path.join(repo_root, 'tools',
  23. 'checkteamtags')
  24. test_runner = input_api.os_path.join(checkteamtags_dir, 'run_tests')
  25. return_code = input_api.subprocess.call(
  26. [input_api.python3_executable, test_runner])
  27. if return_code:
  28. message = 'Checkteamtags unit tests did not all pass.'
  29. return [output_api.PresubmitError(message)]
  30. return []
  31. def _RunPyLint(input_api, output_api):
  32. """Runs unit tests for checkteamtags."""
  33. tests = input_api.canned_checks.GetPylint(input_api,
  34. output_api,
  35. version='2.7')
  36. return input_api.RunTests(tests)