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

Side by Side Diff: presubmit_canned_checks.py

Issue 119252: Add InputApi.is_committing to be able to return a failure or notification, depending on the check. (Closed)
Patch Set: merged to trunk Created 11 years, 6 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 | « no previous file | presubmit_support.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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generic presubmit checks that can be reused by other presubmit checks.""" 6 """Generic presubmit checks that can be reused by other presubmit checks."""
7 7
8 8
9 def CheckChangeHasTestField(input_api, output_api): 9 def CheckChangeHasTestField(input_api, output_api):
10 """Requires that the changelist have a TEST= field.""" 10 """Requires that the changelist have a TEST= field."""
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 def _RunPythonUnitTests_LoadTests(input_api, module_name): 119 def _RunPythonUnitTests_LoadTests(input_api, module_name):
120 """Meant to be stubbed out during unit testing.""" 120 """Meant to be stubbed out during unit testing."""
121 module = __import__(module_name) 121 module = __import__(module_name)
122 for part in module_name.split('.')[1:]: 122 for part in module_name.split('.')[1:]:
123 module = getattr(module, part) 123 module = getattr(module, part)
124 return input_api.unittest.TestLoader().loadTestsFromModule(module)._tests 124 return input_api.unittest.TestLoader().loadTestsFromModule(module)._tests
125 125
126 def RunPythonUnitTests(input_api, output_api, unit_tests): 126 def RunPythonUnitTests(input_api, output_api, unit_tests):
127 """Imports the unit_tests modules and run them.""" 127 """Imports the unit_tests modules and run them."""
128 # We don't want to hinder users from uploading incomplete patches.
129 if input_api.is_committing:
130 message_type = output_api.PresubmitError
131 else:
132 message_type = output_api.PresubmitNotifyResult
128 tests_suite = [] 133 tests_suite = []
129 outputs = [] 134 outputs = []
130 for unit_test in unit_tests: 135 for unit_test in unit_tests:
131 try: 136 try:
132 tests_suite.extend(_RunPythonUnitTests_LoadTests(unit_test)) 137 tests_suite.extend(_RunPythonUnitTests_LoadTests(unit_test))
133 except ImportError: 138 except ImportError:
134 outputs.append(output_api.PresubmitError("Failed to load %s" % unit_test)) 139 outputs.append(message_type("Failed to load %s" % unit_test,
140 long_text=input_api.traceback.format_exc()))
135 141
136 results = input_api.unittest.TextTestRunner(verbosity=0).run( 142 results = input_api.unittest.TextTestRunner(verbosity=0).run(
137 input_api.unittest.TestSuite(tests_suite)) 143 input_api.unittest.TestSuite(tests_suite))
138 if not results.wasSuccessful(): 144 if not results.wasSuccessful():
139 outputs.append(output_api.PresubmitError( 145 outputs.append(message_type(
140 "%d unit tests failed." % (results.failures + results.errors))) 146 "%d unit tests failed." % (results.failures + results.errors)))
141 return outputs 147 return outputs
OLDNEW
« no previous file with comments | « no previous file | presubmit_support.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698