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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 connection = input_api.urllib2.urlopen(url) | 111 connection = input_api.urllib2.urlopen(url) |
112 status = connection.read() | 112 status = connection.read() |
113 connection.close() | 113 connection.close() |
114 if input_api.re.match(closed, status): | 114 if input_api.re.match(closed, status): |
115 long_text = status + '\n' + url | 115 long_text = status + '\n' + url |
116 return [output_api.PresubmitError("The tree is closed.", | 116 return [output_api.PresubmitError("The tree is closed.", |
117 long_text=long_text)] | 117 long_text=long_text)] |
118 except IOError: | 118 except IOError: |
119 pass | 119 pass |
120 return [] | 120 return [] |
| 121 |
| 122 |
| 123 def RunPythonUnitTests(input_api, output_api, unit_tests): |
| 124 """Imports the unit_tests modules and run them.""" |
| 125 import unittest |
| 126 tests_suite = [] |
| 127 test_loader = unittest.TestLoader() |
| 128 def LoadTests(module_name): |
| 129 module = __import__(module_name) |
| 130 for part in module_name.split('.')[1:]: |
| 131 module = getattr(module, part) |
| 132 tests_suite.extend(test_loader.loadTestsFromModule(module)._tests) |
| 133 |
| 134 outputs = [] |
| 135 for unit_test in unit_tests: |
| 136 try: |
| 137 LoadTests(unit_test) |
| 138 except ImportError: |
| 139 outputs.Append(output_api.PresubmitError("Failed to load %s" % unit_test)) |
| 140 raise |
| 141 |
| 142 results = unittest.TextTestRunner(verbosity=0).run(unittest.TestSuite( |
| 143 tests_suite)) |
| 144 if not results.wasSuccessful(): |
| 145 outputs.append(output_api.PresubmitError( |
| 146 "%d unit tests failed." % (results.failures + results.errors))) |
| 147 return outputs |
OLD | NEW |