OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 # pylint: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 |
9 | 9 |
10 import logging | 10 import logging |
11 import os | 11 import os |
12 import StringIO | 12 import StringIO |
13 import sys | 13 import sys |
14 import time | 14 import time |
15 | 15 |
16 # TODO(maruel): Include inside depot_tools. | 16 _ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
17 from pylint import lint | 17 sys.path.insert(0, _ROOT) |
18 | |
19 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
20 | 18 |
21 from testing_support.super_mox import mox, SuperMoxTestBase | 19 from testing_support.super_mox import mox, SuperMoxTestBase |
22 | 20 |
23 import owners | 21 import owners |
24 import presubmit_support as presubmit | 22 import presubmit_support as presubmit |
25 import rietveld | 23 import rietveld |
26 | 24 |
27 # Shortcut. | 25 # Shortcut. |
28 presubmit_canned_checks = presubmit.presubmit_canned_checks | 26 presubmit_canned_checks = presubmit.presubmit_canned_checks |
29 | 27 |
(...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2129 input_api.subprocess.check_output( | 2127 input_api.subprocess.check_output( |
2130 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, | 2128 ['pyyyyython', '-m', 'test_module'], cwd=None, env=None, |
2131 stderr=input_api.subprocess.STDOUT) | 2129 stderr=input_api.subprocess.STDOUT) |
2132 self.mox.ReplayAll() | 2130 self.mox.ReplayAll() |
2133 | 2131 |
2134 results = presubmit_canned_checks.RunPythonUnitTests( | 2132 results = presubmit_canned_checks.RunPythonUnitTests( |
2135 input_api, presubmit.OutputApi, ['test_module']) | 2133 input_api, presubmit.OutputApi, ['test_module']) |
2136 self.assertEquals(len(results), 0) | 2134 self.assertEquals(len(results), 0) |
2137 | 2135 |
2138 def testCannedRunPylint(self): | 2136 def testCannedRunPylint(self): |
2139 # lint.Run() always calls sys.exit()... | |
2140 lint.Run = lambda x: sys.exit(0) | |
2141 input_api = self.MockInputApi(None, True) | 2137 input_api = self.MockInputApi(None, True) |
| 2138 input_api.environ = self.mox.CreateMock(os.environ) |
| 2139 input_api.environ.copy().AndReturn({}) |
2142 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True) | 2140 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True) |
2143 input_api.PresubmitLocalPath().AndReturn('/foo') | 2141 input_api.PresubmitLocalPath().AndReturn('/foo') |
2144 input_api.PresubmitLocalPath().AndReturn('/foo') | 2142 input_api.PresubmitLocalPath().AndReturn('/foo') |
2145 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])]) | 2143 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])]) |
| 2144 pylint = os.path.join(_ROOT, 'third_party', 'pylint.py') |
| 2145 pylintrc = os.path.join(_ROOT, 'pylintrc') |
| 2146 input_api.subprocess.call( |
| 2147 ['pyyyyython', pylint, 'file1.py', '--rcfile=%s' % pylintrc]) |
2146 self.mox.ReplayAll() | 2148 self.mox.ReplayAll() |
2147 | 2149 |
2148 results = presubmit_canned_checks.RunPylint( | 2150 results = presubmit_canned_checks.RunPylint( |
2149 input_api, presubmit.OutputApi) | 2151 input_api, presubmit.OutputApi) |
2150 self.assertEquals([], results) | 2152 self.assertEquals([], results) |
2151 | 2153 |
2152 def testCheckBuildbotPendingBuildsBad(self): | 2154 def testCheckBuildbotPendingBuildsBad(self): |
2153 input_api = self.MockInputApi(None, True) | 2155 input_api = self.MockInputApi(None, True) |
2154 connection = self.mox.CreateMockAnything() | 2156 connection = self.mox.CreateMockAnything() |
2155 input_api.urllib2.urlopen('uurl').AndReturn(connection) | 2157 input_api.urllib2.urlopen('uurl').AndReturn(connection) |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2455 owners_check=False) | 2457 owners_check=False) |
2456 self.assertEqual(1, len(results)) | 2458 self.assertEqual(1, len(results)) |
2457 self.assertEqual( | 2459 self.assertEqual( |
2458 'Found line ending with white spaces in:', results[0]._message) | 2460 'Found line ending with white spaces in:', results[0]._message) |
2459 self.checkstdout('') | 2461 self.checkstdout('') |
2460 | 2462 |
2461 | 2463 |
2462 if __name__ == '__main__': | 2464 if __name__ == '__main__': |
2463 import unittest | 2465 import unittest |
2464 unittest.main() | 2466 unittest.main() |
OLD | NEW |