blob: 7325f762dd5dface9b452ce4119f84163507e58d [file] [log] [blame]
Marc-Antoine Ruel8add1242013-11-05 17:28:27 -05001# Copyright 2012 The Swarming Authors. All rights reserved.
Marc-Antoine Ruele98b1122013-11-05 20:27:57 -05002# Use of this source code is governed under the Apache License, Version 2.0 that
3# can be found in the LICENSE file.
maruel@chromium.orgfb155e92012-09-28 20:36:54 +00004
5"""Top-level presubmit script for swarm_client.
6
7See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8details on the presubmit API built into gcl.
9"""
10
11def CommonChecks(input_api, output_api):
maruel@chromium.org8b056ba2012-10-16 14:04:49 +000012 import sys
13 def join(*args):
14 return input_api.os_path.join(input_api.PresubmitLocalPath(), *args)
maruel@chromium.orgfb155e92012-09-28 20:36:54 +000015
maruel@chromium.org8b056ba2012-10-16 14:04:49 +000016 output = []
17 sys_path_backup = sys.path
18 try:
19 sys.path = [
maruel@chromium.org86681e92013-07-25 13:34:09 +000020 input_api.PresubmitLocalPath(),
21 join('googletest'),
maruel@chromium.org8b056ba2012-10-16 14:04:49 +000022 join('tests', 'gtest_fake'),
23 ] + sys.path
24 output.extend(input_api.canned_checks.RunPylint(input_api, output_api))
25 finally:
26 sys.path = sys_path_backup
27
maruel@chromium.org11f54112013-09-16 23:16:42 +000028 # These tests are touching the live infrastructure. It's a pain if your IP
29 # is not whitelisted so do not run them for now. They should use a local fake
30 # web service instead.
31 blacklist = [
32 r'.*isolateserver_smoke_test\.py$',
33 r'.*swarming_smoke_test\.py$',
34 ]
maruel@chromium.org14550042013-09-17 20:36:38 +000035 blacklist_googletest = []
36 if not input_api.is_committing:
37 # Remove all slow tests, e.g. the ones that take >1s to complete.
38 blacklist.extend([
39 r'.*isolate_smoke_test\.py$',
40 r'.*trace_inputs_smoke_test\.py$',
41 r'.*url_open_timeout_test\.py$',
42 ])
43 blacklist_googletest.extend([
44 r'.*fix_test_cases_smoke_test\.py$',
45 r'.*isolate_test_cases_smoke_test\.py$',
46 r'.*run_test_cases_smoke_test\.py$',
47 r'.*run_test_cases_test\.py$',
48 ])
maruel@chromium.org7a144f82013-05-28 14:46:07 +000049
maruel@chromium.orgfb155e92012-09-28 20:36:54 +000050 output.extend(
51 input_api.canned_checks.RunUnitTestsInDirectory(
52 input_api, output_api,
53 input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'),
maruel@chromium.org7a144f82013-05-28 14:46:07 +000054 whitelist=[r'.+_test\.py$'],
maruel@chromium.org11f54112013-09-16 23:16:42 +000055 blacklist=blacklist))
maruel@chromium.org86681e92013-07-25 13:34:09 +000056 output.extend(
57 input_api.canned_checks.RunUnitTestsInDirectory(
58 input_api, output_api,
59 input_api.os_path.join(
60 input_api.PresubmitLocalPath(), 'googletest', 'tests'),
maruel@chromium.org14550042013-09-17 20:36:38 +000061 whitelist=[r'.+_test\.py$'],
62 blacklist=blacklist_googletest))
maruel@chromium.orgfb155e92012-09-28 20:36:54 +000063 return output
64
65
Marc-Antoine Ruel8add1242013-11-05 17:28:27 -050066def header(input_api):
67 """Returns the expected license header regexp for this project."""
68 current_year = int(input_api.time.strftime('%Y'))
69 allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1)))
70 years_re = '(' + '|'.join(allowed_years) + ')'
71 license_header = (
72 r'.*? Copyright %(year)s The Swarming Authors\. '
73 r'All rights reserved\.\n'
Marc-Antoine Ruele98b1122013-11-05 20:27:57 -050074 r'.*? Use of this source code is governed under the Apache License, '
75 r'Version 2\.0 that\n'
76 r'.*? can be found in the LICENSE file\.(?: \*/)?\n'
Marc-Antoine Ruel8add1242013-11-05 17:28:27 -050077 ) % {
78 'year': years_re,
79 }
80 return license_header
81
82
maruel@chromium.orgfb155e92012-09-28 20:36:54 +000083def CheckChangeOnUpload(input_api, output_api):
84 return CommonChecks(input_api, output_api)
85
86
87def CheckChangeOnCommit(input_api, output_api):
Marc-Antoine Ruel8add1242013-11-05 17:28:27 -050088 output = CommonChecks(input_api, output_api)
89 output.extend(input_api.canned_checks.PanProjectChecks(
90 input_api, output_api,
91 owners_check=False,
92 license_header=header(input_api)))
93 return output