PRESUBMIT.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright 2018 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 media/test/.
  5. See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
  6. for more details about the presubmit API built into depot_tools.
  7. """
  8. # This line is 'magic' in that git-cl looks for it to decide whether to
  9. # use Python3 instead of Python2 when running the code in this file.
  10. USE_PYTHON3 = True
  11. def _CheckTestDataReadmeUpdated(input_api, output_api):
  12. """
  13. Checks to make sure the README.md file is updated when changing test files.
  14. """
  15. test_data_dir = input_api.os_path.join('media', 'test', 'data')
  16. readme_path = input_api.os_path.join('media', 'test', 'data', 'README.md')
  17. test_files = []
  18. readme_updated = False
  19. errors = []
  20. for f in input_api.AffectedFiles():
  21. local_path = f.LocalPath()
  22. if input_api.os_path.dirname(local_path) == test_data_dir:
  23. test_files.append(f)
  24. if local_path == readme_path:
  25. readme_updated = True
  26. break
  27. if test_files and not readme_updated:
  28. errors.append(output_api.PresubmitPromptWarning(
  29. 'When updating files in ' + test_data_dir + ', please also update '
  30. + readme_path + ':', test_files))
  31. return errors
  32. def CheckChangeOnUpload(input_api, output_api):
  33. return _CheckTestDataReadmeUpdated(input_api, output_api)