• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2012 The Chromium Authors
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 testing.
5
6See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
7for more details on the presubmit API built into depot_tools.
8"""
9
10PRESUBMIT_VERSION = '2.0.0'
11
12
13def _GetChromiumSrcPath(input_api):
14  """Returns the path to the Chromium src directory."""
15  return input_api.os_path.realpath(
16      input_api.os_path.join(input_api.PresubmitLocalPath(), '..'))
17
18
19def _GetTestingEnv(input_api):
20  """Gets the common environment for running testing/ tests."""
21  testing_env = dict(input_api.environ)
22  testing_path = input_api.PresubmitLocalPath()
23  # TODO(crbug.com/40237086): This is temporary till gpu code in
24  # flake_suppressor_commonis moved to gpu dir.
25  # Only common code will reside under /testing.
26  gpu_test_path = input_api.os_path.join(input_api.PresubmitLocalPath(), '..',
27                                         'content', 'test', 'gpu')
28  testing_env.update({
29      'PYTHONPATH':
30      input_api.os_path.pathsep.join([testing_path, gpu_test_path]),
31      'PYTHONDONTWRITEBYTECODE':
32      '1',
33  })
34  return testing_env
35
36
37def CheckFlakeSuppressorCommonUnittests(input_api, output_api):
38  """Runs unittests in the testing/flake_suppressor_common/ directory."""
39  return input_api.canned_checks.RunUnitTestsInDirectory(
40      input_api,
41      output_api,
42      input_api.os_path.join(input_api.PresubmitLocalPath(),
43                             'flake_suppressor_common'), [r'^.+_unittest\.py$'],
44      env=_GetTestingEnv(input_api))
45
46
47def CheckUnexpectedPassesCommonUnittests(input_api, output_api):
48  """Runs unittests in the testing/unexpected_passes_common/ directory."""
49  return input_api.canned_checks.RunUnitTestsInDirectory(
50      input_api,
51      output_api,
52      input_api.os_path.join(input_api.PresubmitLocalPath(),
53                             'unexpected_passes_common'),
54      [r'^.+_unittest\.py$'],
55      env=_GetTestingEnv(input_api))
56
57
58def CheckPylint(input_api, output_api):
59  """Runs pylint on all directory content and subdirectories."""
60  files_to_skip = input_api.DEFAULT_FILES_TO_SKIP
61  chromium_src_path = _GetChromiumSrcPath(input_api)
62  extra_path_components = [('testing', )]
63  pylint_extra_paths = [
64      input_api.os_path.join(chromium_src_path, *component)
65      for component in extra_path_components
66  ]
67  if input_api.is_windows:
68    # These scripts don't run on Windows and should not be linted on Windows -
69    # trying to do so will lead to spurious errors.
70    files_to_skip += ('xvfb.py', '.*host_info.py')
71  pylint_checks = input_api.canned_checks.GetPylint(
72      input_api,
73      output_api,
74      extra_paths_list=pylint_extra_paths,
75      files_to_skip=files_to_skip,
76      # TODO(crbug.com/355016915): Remove this directory-specific pylintrc
77      # file as the default one gets its disable list cleaned up.
78      pylintrc='pylintrc',
79      version='2.7')
80  return input_api.RunTests(pylint_checks)
81
82
83def CheckPatchFormatted(input_api, output_api):
84  return input_api.canned_checks.CheckPatchFormatted(
85      input_api,
86      output_api,
87      result_factory=output_api.PresubmitError,
88  )
89