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 functools | 10 import functools |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 except SystemExit, e: | 1176 except SystemExit, e: |
1177 self.assertEquals(2, e.code) | 1177 self.assertEquals(2, e.code) |
1178 | 1178 |
1179 | 1179 |
1180 class InputApiUnittest(PresubmitTestsBase): | 1180 class InputApiUnittest(PresubmitTestsBase): |
1181 """Tests presubmit.InputApi.""" | 1181 """Tests presubmit.InputApi.""" |
1182 def testMembersChanged(self): | 1182 def testMembersChanged(self): |
1183 self.mox.ReplayAll() | 1183 self.mox.ReplayAll() |
1184 members = [ | 1184 members = [ |
1185 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', | 1185 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', |
1186 'AffectedTextFiles', | 1186 'AffectedTextFiles', 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', |
1187 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', | 1187 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 'LocalToDepotPath', |
1188 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', | 1188 'Command', 'RunTests', 'PresubmitLocalPath', 'ReadFile', |
1189 'LocalToDepotPath', 'Command', 'RunTests', | 1189 'RightHandSideLines', 'ServerPaths', 'basename', 'cPickle', 'cpplint', |
1190 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', | 1190 'cStringIO', 'canned_checks', 'change', 'cpu_count', 'environ', 'glob', |
1191 'basename', 'cPickle', 'cpplint', 'cStringIO', 'canned_checks', 'change', | 1191 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir', |
1192 'environ', 'glob', 'host_url', 'is_committing', 'json', 'logging', | 1192 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform', |
1193 'marshal', 'os_listdir', 'os_walk', 'os_path', 'os_stat', 'owners_db', | 1193 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile', |
1194 'pickle', 'platform', 'python_executable', 're', 'rietveld', 'subprocess', | 1194 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose', |
1195 'tbr', 'tempfile', 'time', 'traceback', 'unittest', 'urllib2', 'version', | |
1196 'verbose', | |
1197 ] | 1195 ] |
1198 # If this test fails, you should add the relevant test. | 1196 # If this test fails, you should add the relevant test. |
1199 self.compareMembers( | 1197 self.compareMembers( |
1200 presubmit.InputApi(self.fake_change, './.', False, None, False), | 1198 presubmit.InputApi(self.fake_change, './.', False, None, False), |
1201 members) | 1199 members) |
1202 | 1200 |
1203 def testDepotToLocalPath(self): | 1201 def testDepotToLocalPath(self): |
1204 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir | 1202 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir |
1205 ).AndReturn({'Path': 'prout'}) | 1203 ).AndReturn({'Path': 'prout'}) |
1206 presubmit.scm.SVN._CaptureInfo( | 1204 presubmit.scm.SVN._CaptureInfo( |
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1845 return 'foo' | 1843 return 'foo' |
1846 input_api.subprocess.CalledProcessError = fake_CalledProcessError | 1844 input_api.subprocess.CalledProcessError = fake_CalledProcessError |
1847 input_api.verbose = False | 1845 input_api.verbose = False |
1848 | 1846 |
1849 input_api.change = change | 1847 input_api.change = change |
1850 input_api.host_url = 'http://localhost' | 1848 input_api.host_url = 'http://localhost' |
1851 input_api.is_committing = committing | 1849 input_api.is_committing = committing |
1852 input_api.tbr = False | 1850 input_api.tbr = False |
1853 input_api.python_executable = 'pyyyyython' | 1851 input_api.python_executable = 'pyyyyython' |
1854 input_api.platform = sys.platform | 1852 input_api.platform = sys.platform |
| 1853 input_api.cpu_count = 2 |
1855 input_api.time = time | 1854 input_api.time = time |
1856 input_api.canned_checks = presubmit_canned_checks | 1855 input_api.canned_checks = presubmit_canned_checks |
1857 input_api.Command = presubmit.CommandData | 1856 input_api.Command = presubmit.CommandData |
1858 input_api.RunTests = functools.partial( | 1857 input_api.RunTests = functools.partial( |
1859 presubmit.InputApi.RunTests, input_api) | 1858 presubmit.InputApi.RunTests, input_api) |
1860 return input_api | 1859 return input_api |
1861 | 1860 |
1862 def testMembersChanged(self): | 1861 def testMembersChanged(self): |
1863 self.mox.ReplayAll() | 1862 self.mox.ReplayAll() |
1864 members = [ | 1863 members = [ |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 input_api.environ = self.mox.CreateMock(os.environ) | 2517 input_api.environ = self.mox.CreateMock(os.environ) |
2519 input_api.environ.copy().AndReturn({}) | 2518 input_api.environ.copy().AndReturn({}) |
2520 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True) | 2519 input_api.AffectedSourceFiles(mox.IgnoreArg()).AndReturn(True) |
2521 input_api.PresubmitLocalPath().AndReturn('/foo') | 2520 input_api.PresubmitLocalPath().AndReturn('/foo') |
2522 input_api.PresubmitLocalPath().AndReturn('/foo') | 2521 input_api.PresubmitLocalPath().AndReturn('/foo') |
2523 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])]) | 2522 input_api.os_walk('/foo').AndReturn([('/foo', [], ['file1.py'])]) |
2524 pylint = os.path.join(_ROOT, 'third_party', 'pylint.py') | 2523 pylint = os.path.join(_ROOT, 'third_party', 'pylint.py') |
2525 pylintrc = os.path.join(_ROOT, 'pylintrc') | 2524 pylintrc = os.path.join(_ROOT, 'pylintrc') |
2526 | 2525 |
2527 CommHelper(input_api, | 2526 CommHelper(input_api, |
2528 ['pyyyyython', pylint, '--args-on-stdin'], | 2527 ['pyyyyython', pylint, '--args-on-stdin', '--disable=cyclic-import', |
| 2528 '--jobs=2'], |
| 2529 env=mox.IgnoreArg(), stdin='file1.py\n--rcfile=%s' % pylintrc) |
| 2530 CommHelper(input_api, |
| 2531 ['pyyyyython', pylint, '--args-on-stdin', '--disable=all', |
| 2532 '--enable=cyclic-import'], |
2529 env=mox.IgnoreArg(), stdin='file1.py\n--rcfile=%s' % pylintrc) | 2533 env=mox.IgnoreArg(), stdin='file1.py\n--rcfile=%s' % pylintrc) |
2530 self.mox.ReplayAll() | 2534 self.mox.ReplayAll() |
2531 | 2535 |
2532 results = presubmit_canned_checks.RunPylint( | 2536 results = presubmit_canned_checks.RunPylint( |
2533 input_api, presubmit.OutputApi) | 2537 input_api, presubmit.OutputApi) |
2534 self.assertEquals([], results) | 2538 self.assertEquals([], results) |
2535 self.checkstdout('') | 2539 self.checkstdout('') |
2536 | 2540 |
2537 def testCheckBuildbotPendingBuildsBad(self): | 2541 def testCheckBuildbotPendingBuildsBad(self): |
2538 input_api = self.MockInputApi(None, True) | 2542 input_api = self.MockInputApi(None, True) |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2890 owners_check=False) | 2894 owners_check=False) |
2891 self.assertEqual(1, len(results)) | 2895 self.assertEqual(1, len(results)) |
2892 self.assertEqual( | 2896 self.assertEqual( |
2893 'Found line ending with white spaces in:', results[0]._message) | 2897 'Found line ending with white spaces in:', results[0]._message) |
2894 self.checkstdout('') | 2898 self.checkstdout('') |
2895 | 2899 |
2896 | 2900 |
2897 if __name__ == '__main__': | 2901 if __name__ == '__main__': |
2898 import unittest | 2902 import unittest |
2899 unittest.main() | 2903 unittest.main() |
OLD | NEW |