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 5"""Top-level presubmit script for testing. 6 7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts 8for more details on the presubmit API built into depot_tools. 9""" 10 11PRESUBMIT_VERSION = '2.0.0' 12 13 14def _GetTestingEnv(input_api): 15 """Gets the common environment for running testing/ tests.""" 16 testing_env = dict(input_api.environ) 17 testing_path = input_api.PresubmitLocalPath() 18 # TODO(crbug.com/1358733): This is temporary till gpu code in 19 # flake_suppressor_commonis moved to gpu dir. 20 # Only common code will reside under /testing. 21 gpu_test_path = input_api.os_path.join( 22 input_api.PresubmitLocalPath(), '..', 'content', 'test', 'gpu') 23 testing_env.update({ 24 'PYTHONPATH': input_api.os_path.pathsep.join( 25 [testing_path, gpu_test_path]), 26 'PYTHONDONTWRITEBYTECODE': '1', 27 }) 28 return testing_env 29 30 31def CheckFlakeSuppressorCommonUnittests(input_api, output_api): 32 """Runs unittests in the testing/flake_suppressor_common/ directory.""" 33 return input_api.canned_checks.RunUnitTestsInDirectory( 34 input_api, 35 output_api, 36 input_api.os_path.join(input_api.PresubmitLocalPath(), 37 'flake_suppressor_common'), 38 [r'^.+_unittest\.py$'], 39 env=_GetTestingEnv(input_api)) 40 41 42def CheckUnexpectedPassesCommonUnittests(input_api, output_api): 43 """Runs unittests in the testing/unexpected_passes_common/ directory.""" 44 return input_api.canned_checks.RunUnitTestsInDirectory( 45 input_api, 46 output_api, 47 input_api.os_path.join(input_api.PresubmitLocalPath(), 48 'unexpected_passes_common'), 49 [r'^.+_unittest\.py$'], 50 env=_GetTestingEnv(input_api)) 51 52 53def CheckPylint(input_api, output_api): 54 """Runs pylint on all directory content and subdirectories.""" 55 files_to_skip = input_api.DEFAULT_FILES_TO_SKIP 56 if input_api.is_windows: 57 # These scripts don't run on Windows and should not be linted on Windows - 58 # trying to do so will lead to spurious errors. 59 files_to_skip += ('xvfb.py', '.*host_info.py') 60 pylint_checks = input_api.canned_checks.GetPylint( 61 input_api, 62 output_api, 63 files_to_skip=files_to_skip, 64 version='2.7') 65 return input_api.RunTests(pylint_checks) 66