| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2013 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 | |
| 5 """Top-level presubmit script for reviewbot. | |
| 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 GetUnitTests(input_api, output_api, pythonpath): | |
| 12 """Finds all unit tests to run within the source tree.""" | |
| 13 tests = [] | |
| 14 for root, dirs, files in input_api.os_walk(input_api.PresubmitLocalPath()): | |
| 15 # Don't recurse in blacklisted directories. | |
| 16 blacklist = ['.svn', '.git', 'third_party'] | |
| 17 dirs[:] = filter(lambda d : d not in blacklist, dirs) | |
| 18 | |
| 19 # Add all files ending in _test.py to the list of tests. | |
| 20 test_files = filter(lambda f: f.endswith('_test.py'), files) | |
| 21 tests.extend([input_api.os_path.join(root, f) for f in test_files]) | |
| 22 | |
| 23 # A helper to augment PYTHONPATH in the unit test command environment. | |
| 24 def augment_pythonpath_in_environment(cmd): | |
| 25 env = cmd.kwargs.get('env', {}) | |
| 26 new_env_path = input_api.os_path.pathsep.join(pythonpath) | |
| 27 if 'PYTHONPATH' in env: | |
| 28 new_env_path += input_api.os_path.pathsep + env['PYTHONPATH'] | |
| 29 env['PYTHONPATH'] = new_env_path | |
| 30 cmd.kwargs['env'] = env | |
| 31 return cmd | |
| 32 | |
| 33 # Create the commands. | |
| 34 return map( | |
| 35 augment_pythonpath_in_environment, | |
| 36 input_api.canned_checks.GetUnitTests(input_api, output_api, tests)) | |
| 37 | |
| 38 | |
| 39 def CommonChecks(input_api, output_api): | |
| 40 output = [] | |
| 41 | |
| 42 join = input_api.os_path.join | |
| 43 root = input_api.PresubmitLocalPath() | |
| 44 while True: | |
| 45 if input_api.os_path.isfile(join(root, 'google_appengine', 'VERSION')): | |
| 46 break | |
| 47 next_root = input_api.os_path.dirname(root) | |
| 48 if next_root == root: | |
| 49 return [output_api.PresubmitError('Failed to find Google AppEngine SDK')] | |
| 50 root = next_root | |
| 51 input_api.logging.debug('Found GAE SDK in %s' % root) | |
| 52 | |
| 53 import sys | |
| 54 sys_path_backup = sys.path | |
| 55 try: | |
| 56 sys.path = [ | |
| 57 join(root, 'google_appengine'), | |
| 58 join(root, 'google_appengine', 'lib'), | |
| 59 join(root, 'google_appengine', 'lib', 'webapp2-2.5.2'), | |
| 60 join(root, 'google_appengine', 'lib', 'webob-1.2.3'), | |
| 61 join('third_party', 'google-api-python-client'), | |
| 62 input_api.PresubmitLocalPath(), | |
| 63 ] + sys.path | |
| 64 | |
| 65 output.extend(input_api.RunTests( | |
| 66 input_api.canned_checks.GetPylint( | |
| 67 input_api, | |
| 68 output_api) + | |
| 69 GetUnitTests(input_api, output_api, sys.path))) | |
| 70 finally: | |
| 71 sys.path = sys_path_backup | |
| 72 | |
| 73 return output | |
| 74 | |
| 75 | |
| 76 def CheckChangeOnUpload(input_api, output_api): | |
| 77 return CommonChecks(input_api, output_api) | |
| 78 | |
| 79 | |
| 80 def CheckChangeOnCommit(input_api, output_api): | |
| 81 return CommonChecks(input_api, output_api) | |
| OLD | NEW |