Marc-Antoine Ruel | 8add124 | 2013-11-05 17:28:27 -0500 | [diff] [blame] | 1 | # Copyright 2012 The Swarming Authors. All rights reserved. |
Marc-Antoine Ruel | e98b112 | 2013-11-05 20:27:57 -0500 | [diff] [blame] | 2 | # 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.org | fb155e9 | 2012-09-28 20:36:54 +0000 | [diff] [blame] | 4 | |
| 5 | """Top-level presubmit script for swarm_client. |
| 6 | |
| 7 | See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for |
| 8 | details on the presubmit API built into gcl. |
| 9 | """ |
| 10 | |
| 11 | def CommonChecks(input_api, output_api): |
maruel@chromium.org | 8b056ba | 2012-10-16 14:04:49 +0000 | [diff] [blame] | 12 | import sys |
| 13 | def join(*args): |
| 14 | return input_api.os_path.join(input_api.PresubmitLocalPath(), *args) |
maruel@chromium.org | fb155e9 | 2012-09-28 20:36:54 +0000 | [diff] [blame] | 15 | |
maruel@chromium.org | 8b056ba | 2012-10-16 14:04:49 +0000 | [diff] [blame] | 16 | output = [] |
| 17 | sys_path_backup = sys.path |
| 18 | try: |
| 19 | sys.path = [ |
maruel@chromium.org | 86681e9 | 2013-07-25 13:34:09 +0000 | [diff] [blame] | 20 | input_api.PresubmitLocalPath(), |
| 21 | join('googletest'), |
maruel@chromium.org | 8b056ba | 2012-10-16 14:04:49 +0000 | [diff] [blame] | 22 | join('tests', 'gtest_fake'), |
Marc-Antoine Ruel | 5906fcd | 2013-11-08 21:02:24 -0500 | [diff] [blame] | 23 | join('tests'), |
Marc-Antoine Ruel | 3525b33 | 2013-11-12 13:51:20 -0500 | [diff] [blame^] | 24 | join('third_party'), |
maruel@chromium.org | 8b056ba | 2012-10-16 14:04:49 +0000 | [diff] [blame] | 25 | ] + sys.path |
| 26 | output.extend(input_api.canned_checks.RunPylint(input_api, output_api)) |
| 27 | finally: |
| 28 | sys.path = sys_path_backup |
| 29 | |
maruel@chromium.org | 11f5411 | 2013-09-16 23:16:42 +0000 | [diff] [blame] | 30 | # These tests are touching the live infrastructure. It's a pain if your IP |
| 31 | # is not whitelisted so do not run them for now. They should use a local fake |
| 32 | # web service instead. |
| 33 | blacklist = [ |
| 34 | r'.*isolateserver_smoke_test\.py$', |
| 35 | r'.*swarming_smoke_test\.py$', |
| 36 | ] |
maruel@chromium.org | 1455004 | 2013-09-17 20:36:38 +0000 | [diff] [blame] | 37 | blacklist_googletest = [] |
| 38 | if not input_api.is_committing: |
| 39 | # Remove all slow tests, e.g. the ones that take >1s to complete. |
| 40 | blacklist.extend([ |
| 41 | r'.*isolate_smoke_test\.py$', |
| 42 | r'.*trace_inputs_smoke_test\.py$', |
| 43 | r'.*url_open_timeout_test\.py$', |
| 44 | ]) |
| 45 | blacklist_googletest.extend([ |
| 46 | r'.*fix_test_cases_smoke_test\.py$', |
| 47 | r'.*isolate_test_cases_smoke_test\.py$', |
| 48 | r'.*run_test_cases_smoke_test\.py$', |
| 49 | r'.*run_test_cases_test\.py$', |
| 50 | ]) |
maruel@chromium.org | 7a144f8 | 2013-05-28 14:46:07 +0000 | [diff] [blame] | 51 | |
maruel@chromium.org | fb155e9 | 2012-09-28 20:36:54 +0000 | [diff] [blame] | 52 | output.extend( |
| 53 | input_api.canned_checks.RunUnitTestsInDirectory( |
| 54 | input_api, output_api, |
| 55 | input_api.os_path.join(input_api.PresubmitLocalPath(), 'tests'), |
maruel@chromium.org | 7a144f8 | 2013-05-28 14:46:07 +0000 | [diff] [blame] | 56 | whitelist=[r'.+_test\.py$'], |
maruel@chromium.org | 11f5411 | 2013-09-16 23:16:42 +0000 | [diff] [blame] | 57 | blacklist=blacklist)) |
maruel@chromium.org | 86681e9 | 2013-07-25 13:34:09 +0000 | [diff] [blame] | 58 | output.extend( |
| 59 | input_api.canned_checks.RunUnitTestsInDirectory( |
| 60 | input_api, output_api, |
| 61 | input_api.os_path.join( |
| 62 | input_api.PresubmitLocalPath(), 'googletest', 'tests'), |
maruel@chromium.org | 1455004 | 2013-09-17 20:36:38 +0000 | [diff] [blame] | 63 | whitelist=[r'.+_test\.py$'], |
| 64 | blacklist=blacklist_googletest)) |
maruel@chromium.org | fb155e9 | 2012-09-28 20:36:54 +0000 | [diff] [blame] | 65 | return output |
| 66 | |
| 67 | |
Marc-Antoine Ruel | 8add124 | 2013-11-05 17:28:27 -0500 | [diff] [blame] | 68 | def header(input_api): |
| 69 | """Returns the expected license header regexp for this project.""" |
| 70 | current_year = int(input_api.time.strftime('%Y')) |
| 71 | allowed_years = (str(s) for s in reversed(xrange(2011, current_year + 1))) |
| 72 | years_re = '(' + '|'.join(allowed_years) + ')' |
| 73 | license_header = ( |
| 74 | r'.*? Copyright %(year)s The Swarming Authors\. ' |
| 75 | r'All rights reserved\.\n' |
Marc-Antoine Ruel | e98b112 | 2013-11-05 20:27:57 -0500 | [diff] [blame] | 76 | r'.*? Use of this source code is governed under the Apache License, ' |
| 77 | r'Version 2\.0 that\n' |
| 78 | r'.*? can be found in the LICENSE file\.(?: \*/)?\n' |
Marc-Antoine Ruel | 8add124 | 2013-11-05 17:28:27 -0500 | [diff] [blame] | 79 | ) % { |
| 80 | 'year': years_re, |
| 81 | } |
| 82 | return license_header |
| 83 | |
| 84 | |
maruel@chromium.org | fb155e9 | 2012-09-28 20:36:54 +0000 | [diff] [blame] | 85 | def CheckChangeOnUpload(input_api, output_api): |
| 86 | return CommonChecks(input_api, output_api) |
| 87 | |
| 88 | |
| 89 | def CheckChangeOnCommit(input_api, output_api): |
Marc-Antoine Ruel | 8add124 | 2013-11-05 17:28:27 -0500 | [diff] [blame] | 90 | output = CommonChecks(input_api, output_api) |
| 91 | output.extend(input_api.canned_checks.PanProjectChecks( |
| 92 | input_api, output_api, |
| 93 | owners_check=False, |
| 94 | license_header=header(input_api))) |
| 95 | return output |