OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 is too confused. | 8 # pylint is too confused. |
9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 | 9 # pylint: disable=E1101,E1103,R0201,W0212,W0403 |
10 | 10 |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 self.assertEquals(rhs_lines[8][2], 'this is line number 23.1') | 344 self.assertEquals(rhs_lines[8][2], 'this is line number 23.1') |
345 | 345 |
346 self.assertEquals(rhs_lines[12][0].LocalPath(), files[3][1]) | 346 self.assertEquals(rhs_lines[12][0].LocalPath(), files[3][1]) |
347 self.assertEquals(rhs_lines[12][1], 46) | 347 self.assertEquals(rhs_lines[12][1], 46) |
348 self.assertEquals(rhs_lines[12][2], '') | 348 self.assertEquals(rhs_lines[12][2], '') |
349 | 349 |
350 self.assertEquals(rhs_lines[13][0].LocalPath(), files[3][1]) | 350 self.assertEquals(rhs_lines[13][0].LocalPath(), files[3][1]) |
351 self.assertEquals(rhs_lines[13][1], 49) | 351 self.assertEquals(rhs_lines[13][1], 49) |
352 self.assertEquals(rhs_lines[13][2], 'this is line number 48.1') | 352 self.assertEquals(rhs_lines[13][2], 'this is line number 48.1') |
353 | 353 |
| 354 def testInvalidChange(self): |
| 355 try: |
| 356 presubmit.SvnChange( |
| 357 'mychange', |
| 358 'description', |
| 359 self.fake_root_dir, |
| 360 ['foo/blat.cc', 'bar'], |
| 361 0, |
| 362 0, |
| 363 None) |
| 364 self.fail() |
| 365 except AssertionError: |
| 366 pass |
| 367 |
354 def testExecPresubmitScript(self): | 368 def testExecPresubmitScript(self): |
355 description_lines = ('Hello there', | 369 description_lines = ('Hello there', |
356 'this is a change', | 370 'this is a change', |
357 'STORY=http://tracker/123') | 371 'STORY=http://tracker/123') |
358 files = [ | 372 files = [ |
359 ['A', 'foo\\blat.cc'], | 373 ['A', 'foo\\blat.cc'], |
360 ] | 374 ] |
361 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') | 375 fake_presubmit = presubmit.os.path.join(self.fake_root_dir, 'PRESUBMIT.py') |
362 self.mox.ReplayAll() | 376 self.mox.ReplayAll() |
363 | 377 |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 self.fake_root_dir, None, None, | 777 self.fake_root_dir, None, None, |
764 False, output)) | 778 False, output)) |
765 | 779 |
766 def testMainUnversioned(self): | 780 def testMainUnversioned(self): |
767 # OptParser calls presubmit.os.path.exists and is a pain when mocked. | 781 # OptParser calls presubmit.os.path.exists and is a pain when mocked. |
768 self.UnMock(presubmit.os.path, 'exists') | 782 self.UnMock(presubmit.os.path, 'exists') |
769 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') | 783 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') |
770 self.mox.StubOutWithMock(presubmit, 'ParseFiles') | 784 self.mox.StubOutWithMock(presubmit, 'ParseFiles') |
771 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) | 785 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) |
772 presubmit.ParseFiles(['random_file.txt'], None | 786 presubmit.ParseFiles(['random_file.txt'], None |
773 ).AndReturn(['random_file.txt']) | 787 ).AndReturn([('M', 'random_file.txt')]) |
774 output = self.mox.CreateMock(presubmit.PresubmitOutput) | 788 output = self.mox.CreateMock(presubmit.PresubmitOutput) |
775 output.should_continue().AndReturn(False) | 789 output.should_continue().AndReturn(False) |
776 | 790 |
777 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, | 791 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, |
778 mox.IgnoreArg(), | 792 mox.IgnoreArg(), |
779 mox.IgnoreArg(), | 793 mox.IgnoreArg(), |
780 None, False, None).AndReturn(output) | 794 None, False, None).AndReturn(output) |
781 self.mox.ReplayAll() | 795 self.mox.ReplayAll() |
782 | 796 |
783 self.assertEquals( | 797 self.assertEquals( |
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2254 owners_check=True) | 2268 owners_check=True) |
2255 self.assertEqual(1, len(results)) | 2269 self.assertEqual(1, len(results)) |
2256 self.assertEqual( | 2270 self.assertEqual( |
2257 'Found line ending with white spaces in:', results[0]._message) | 2271 'Found line ending with white spaces in:', results[0]._message) |
2258 self.checkstdout('') | 2272 self.checkstdout('') |
2259 | 2273 |
2260 | 2274 |
2261 if __name__ == '__main__': | 2275 if __name__ == '__main__': |
2262 import unittest | 2276 import unittest |
2263 unittest.main() | 2277 unittest.main() |
OLD | NEW |