OLD | NEW |
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 """Imports the unit_tests modules and run them.""" | 128 """Imports the unit_tests modules and run them.""" |
129 # We don't want to hinder users from uploading incomplete patches. | 129 # We don't want to hinder users from uploading incomplete patches. |
130 if input_api.is_committing: | 130 if input_api.is_committing: |
131 message_type = output_api.PresubmitError | 131 message_type = output_api.PresubmitError |
132 else: | 132 else: |
133 message_type = output_api.PresubmitNotifyResult | 133 message_type = output_api.PresubmitNotifyResult |
134 tests_suite = [] | 134 tests_suite = [] |
135 outputs = [] | 135 outputs = [] |
136 for unit_test in unit_tests: | 136 for unit_test in unit_tests: |
137 try: | 137 try: |
138 tests_suite.extend(_RunPythonUnitTests_LoadTests(unit_test)) | 138 tests_suite.extend(_RunPythonUnitTests_LoadTests(input_api, unit_test)) |
139 except ImportError: | 139 except ImportError: |
140 outputs.append(message_type("Failed to load %s" % unit_test, | 140 outputs.append(message_type("Failed to load %s" % unit_test, |
141 long_text=input_api.traceback.format_exc())) | 141 long_text=input_api.traceback.format_exc())) |
142 | 142 |
143 results = input_api.unittest.TextTestRunner(verbosity=0).run( | 143 results = input_api.unittest.TextTestRunner(verbosity=0).run( |
144 input_api.unittest.TestSuite(tests_suite)) | 144 input_api.unittest.TestSuite(tests_suite)) |
145 if not results.wasSuccessful(): | 145 if not results.wasSuccessful(): |
146 outputs.append(message_type( | 146 outputs.append(message_type("%d unit tests failed." % |
147 "%d unit tests failed." % (results.failures + results.errors))) | 147 (len(results.failures) + len(results.errors)))) |
148 return outputs | 148 return outputs |
OLD | NEW |