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

Side by Side Diff: presubmit_canned_checks.py

Issue 115516: Add new presubmit check RunPythonUnitTests. (Closed)
Patch Set: Created 11 years, 7 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 | « PRESUBMIT.py ('k') | tests/presubmit_unittest.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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698