Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: tools/auto_bisect/PRESUBMIT.py

Issue 529593002: In the presubmit for auto-bisect, run pylint and unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/PRESUBMIT.py ('k') | tools/auto_bisect/builder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Top-level presubmit script for auto-bisect. 5 """Top-level presubmit script for auto-bisect.
6 6
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for 7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
8 details on the presubmit API built into gcl. 8 details on the presubmit API.
9 """ 9 """
10 10
11 import imp 11 import imp
12 import subprocess
12 import os 13 import os
13 14
14 # Paths to bisect config files relative to src/tools. 15 # Paths to bisect config files relative to src/tools.
15 CONFIG_FILES = [ 16 CONFIG_FILES = [
16 'auto_bisect/config.cfg', 17 'auto_bisect/config.cfg',
17 'run-perf-test.cfg' 18 'run-perf-test.cfg'
18 ] 19 ]
19 20
20 PYLINT_BLACKLIST = []
21 PYLINT_DISABLED_WARNINGS = []
22
23
24 def CheckChangeOnUpload(input_api, output_api): 21 def CheckChangeOnUpload(input_api, output_api):
25 return _CommonChecks(input_api, output_api) 22 return _CommonChecks(input_api, output_api)
26 23
27 24
28 def CheckChangeOnCommit(input_api, output_api): 25 def CheckChangeOnCommit(input_api, output_api):
29 return _CommonChecks(input_api, output_api) 26 return _CommonChecks(input_api, output_api)
30 27
31 28
32 def _CommonChecks(input_api, output_api): 29 def _CommonChecks(input_api, output_api):
33 """Does all presubmit checks for auto-bisect.""" 30 """Does all presubmit checks for auto-bisect."""
34 # TODO(qyearsley) Run bisect unit test.
35 # TODO(qyearsley) Run pylint on all auto-bisect py files but not other files.
36 results = [] 31 results = []
37 results.extend(_CheckAllConfigFiles(input_api, output_api)) 32 results.extend(_CheckAllConfigFiles(input_api, output_api))
33 results.extend(_RunUnitTests(input_api, output_api))
34 results.extend(_RunPyLint(input_api, output_api))
38 return results 35 return results
39 36
40 37
41 def _CheckAllConfigFiles(input_api, output_api): 38 def _CheckAllConfigFiles(input_api, output_api):
42 """Checks all bisect config files and returns a list of presubmit results.""" 39 """Checks all bisect config files and returns a list of presubmit results."""
43 results = [] 40 results = []
44 for f in input_api.AffectedFiles(): 41 for f in input_api.AffectedFiles():
45 for config_file in CONFIG_FILES: 42 for config_file in CONFIG_FILES:
46 if f.LocalPath().endswith(config_file): 43 if f.LocalPath().endswith(config_file):
47 results.extend(_CheckConfigFile(config_file, output_api)) 44 results.extend(_CheckConfigFile(config_file, output_api))
48 return results 45 return results
49 46
50 47
51 def _CheckConfigFile(file_path, output_api): 48 def _CheckConfigFile(file_path, output_api):
52 """Checks one bisect config file and returns a list of presubmit results.""" 49 """Checks one bisect config file and returns a list of presubmit results."""
53 try: 50 try:
54 config_file = imp.load_source('config', file_path) 51 config_file = imp.load_source('config', file_path)
55 except IOError as e: 52 except IOError as e:
56 warning = 'Failed to read config file %s: %s' % (file_path, str(e)) 53 warning = 'Failed to read config file %s: %s' % (file_path, str(e))
57 return [output_api.PresubmitError(warning, items=[file_path])] 54 return [output_api.PresubmitError(warning, items=[file_path])]
58 55
59 if not hasattr(config_file.config): 56 if not hasattr(config_file.config):
60 warning = 'Config file has no "config" global variable: %s' % str(e) 57 warning = 'Config file has no "config" global variable: %s' % str(e)
61 return [output_api.PresubmitError(warning, items=[file_path])] 58 return [output_api.PresubmitError(warning, items=[file_path])]
62 59
63 if type(config_file.config) is not dict: 60 if type(config_file.config) is not dict:
64 warning = 'Config file "config" global variable is not dict: %s' % str(e) 61 warning = 'Config file "config" global variable is not dict: %s' % str(e)
65 return [output_api.PresubmitError(warning, items=[file_path])] 62 return [output_api.PresubmitError(warning, items=[file_path])]
66 63
67 for k, v in config_dict.iteritems(): 64 for k, v in config_file.config.iteritems():
68 if v != '': 65 if v != '':
69 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v)) 66 warning = 'Non-empty value in config dict: %s: %s' % (repr(k), repr(v))
70 warning += ('\nThe bisection config file should only contain a config ' 67 warning += ('\nThe bisection config file should only contain a config '
71 'dict with empty fields. Changes to this file should not ' 68 'dict with empty fields. Changes to this file should not '
72 'be submitted.') 69 'be submitted.')
73 return [output_api.PresubmitError(warning, items=[file_path])] 70 return [output_api.PresubmitError(warning, items=[file_path])]
74 71
75 return [] 72 return []
73
74
75 def _RunUnitTests(input_api, output_api):
76 """Runs unit tests for auto-bisect."""
77 repo_root = input_api.change.RepositoryRoot()
78 auto_bisect_dir = os.path.join(repo_root, 'tools', 'auto_bisect')
79 test_runner = os.path.join(auto_bisect_dir, 'run_tests')
80 return_code = subprocess.call(['python', test_runner])
81 if return_code:
82 message = 'Auto-bisect unit tests did not all pass.'
83 return [output_api.PresubmitError(message)]
84 return []
85
86
87 def _RunPyLint(input_api, output_api):
88 """Runs unit tests for auto-bisect."""
89 tests = input_api.canned_checks.GetPylint(input_api, output_api)
90 return input_api.RunTests(tests)
OLDNEW
« no previous file with comments | « tools/PRESUBMIT.py ('k') | tools/auto_bisect/builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698