Chromium Code Reviews| 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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 654 '\n' | 654 '\n' |
| 655 '** Presubmit Messages **\n' | 655 '** Presubmit Messages **\n' |
| 656 'http://tracker.com/42\n' | 656 'http://tracker.com/42\n' |
| 657 '\n' | 657 '\n' |
| 658 'Presubmit checks passed.\n')) | 658 'Presubmit checks passed.\n')) |
| 659 | 659 |
| 660 def testGetTrySlavesExecuter(self): | 660 def testGetTrySlavesExecuter(self): |
| 661 self.mox.ReplayAll() | 661 self.mox.ReplayAll() |
| 662 | 662 |
| 663 executer = presubmit.GetTrySlavesExecuter() | 663 executer = presubmit.GetTrySlavesExecuter() |
| 664 self.assertEqual([], executer.ExecPresubmitScript('', '')) | 664 self.assertEqual([], executer.ExecPresubmitScript('', '', '')) |
| 665 self.assertEqual( | 665 self.assertEqual( |
| 666 [], executer.ExecPresubmitScript('def foo():\n return\n', '')) | 666 [], executer.ExecPresubmitScript('def foo():\n return\n', '', '')) |
|
M-A Ruel
2011/05/26 12:49:49
You don't want to add a quick test for 'def foo(pr
bradn
2011/05/26 16:52:06
Done.
| |
| 667 | 667 |
| 668 # bad results | 668 # bad results |
| 669 starts_with_space_result = [' starts_with_space'] | 669 starts_with_space_result = [' starts_with_space'] |
| 670 not_list_result1 = "'foo'" | 670 not_list_result1 = "'foo'" |
| 671 not_list_result2 = "('a', 'tuple')" | 671 not_list_result2 = "('a', 'tuple')" |
| 672 for result in starts_with_space_result, not_list_result1, not_list_result2: | 672 for result in starts_with_space_result, not_list_result1, not_list_result2: |
| 673 self.assertRaises(presubmit.PresubmitFailure, | 673 self.assertRaises(presubmit.PresubmitFailure, |
| 674 executer.ExecPresubmitScript, | 674 executer.ExecPresubmitScript, |
| 675 self.presubmit_tryslave % result, '') | 675 self.presubmit_tryslave % result, '', '') |
| 676 | 676 |
| 677 # good results | 677 # good results |
| 678 expected_result = ['1', '2', '3'] | 678 expected_result = ['1', '2', '3'] |
| 679 empty_result = [] | 679 empty_result = [] |
| 680 space_in_name_result = ['foo bar', '1\t2 3'] | 680 space_in_name_result = ['foo bar', '1\t2 3'] |
| 681 for result in expected_result, empty_result, space_in_name_result: | 681 for result in expected_result, empty_result, space_in_name_result: |
| 682 self.assertEqual( | 682 self.assertEqual( |
| 683 result, | 683 result, |
| 684 executer.ExecPresubmitScript(self.presubmit_tryslave % result, '')) | 684 executer.ExecPresubmitScript( |
| 685 self.presubmit_tryslave % result, '', '')) | |
| 685 | 686 |
| 686 def testDoGetTrySlaves(self): | 687 def testDoGetTrySlaves(self): |
| 687 join = presubmit.os.path.join | 688 join = presubmit.os.path.join |
| 688 filename = 'foo.cc' | 689 filename = 'foo.cc' |
| 689 filename_linux = join('linux_only', 'penguin.cc') | 690 filename_linux = join('linux_only', 'penguin.cc') |
| 690 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') | 691 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') |
| 691 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') | 692 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') |
| 692 inherit_path = presubmit.os.path.join(self.fake_root_dir, | 693 inherit_path = presubmit.os.path.join(self.fake_root_dir, |
| 693 self._INHERIT_SETTINGS) | 694 self._INHERIT_SETTINGS) |
| 694 | 695 |
| 695 presubmit.os.path.isfile(inherit_path).AndReturn(False) | 696 presubmit.os.path.isfile(inherit_path).AndReturn(False) |
| 696 presubmit.os.path.isfile(root_presubmit).AndReturn(True) | 697 presubmit.os.path.isfile(root_presubmit).AndReturn(True) |
| 697 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( | 698 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( |
| 698 self.presubmit_tryslave % '["win"]') | 699 self.presubmit_tryslave % '["win"]') |
| 699 | 700 |
| 700 presubmit.os.path.isfile(inherit_path).AndReturn(False) | 701 presubmit.os.path.isfile(inherit_path).AndReturn(False) |
| 701 presubmit.os.path.isfile(root_presubmit).AndReturn(True) | 702 presubmit.os.path.isfile(root_presubmit).AndReturn(True) |
| 702 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) | 703 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) |
| 703 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( | 704 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( |
| 704 self.presubmit_tryslave % '["win"]') | 705 self.presubmit_tryslave % '["win"]') |
| 705 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn( | 706 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn( |
| 706 self.presubmit_tryslave % '["linux"]') | 707 self.presubmit_tryslave % '["linux"]') |
| 707 self.mox.ReplayAll() | 708 self.mox.ReplayAll() |
| 708 | 709 |
| 709 output = StringIO.StringIO() | 710 output = StringIO.StringIO() |
| 710 self.assertEqual(['win'], | 711 self.assertEqual(['win'], |
| 711 presubmit.DoGetTrySlaves([filename], self.fake_root_dir, | 712 presubmit.DoGetTrySlaves([filename], self.fake_root_dir, |
| 712 None, False, output)) | 713 None, None, False, output)) |
| 713 output = StringIO.StringIO() | 714 output = StringIO.StringIO() |
| 714 self.assertEqual(['win', 'linux'], | 715 self.assertEqual(['win', 'linux'], |
| 715 presubmit.DoGetTrySlaves([filename, filename_linux], | 716 presubmit.DoGetTrySlaves([filename, filename_linux], |
| 716 self.fake_root_dir, None, False, | 717 self.fake_root_dir, None, None, |
| 717 output)) | 718 » » » » » False, output)) |
|
M-A Ruel
2011/05/26 12:49:49
Please use space instead.
bradn
2011/05/26 16:52:06
Done.
| |
| 718 | 719 |
| 719 def testMainUnversioned(self): | 720 def testMainUnversioned(self): |
| 720 # OptParser calls presubmit.os.path.exists and is a pain when mocked. | 721 # OptParser calls presubmit.os.path.exists and is a pain when mocked. |
| 721 self.UnMock(presubmit.os.path, 'exists') | 722 self.UnMock(presubmit.os.path, 'exists') |
| 722 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') | 723 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') |
| 723 self.mox.StubOutWithMock(presubmit, 'ParseFiles') | 724 self.mox.StubOutWithMock(presubmit, 'ParseFiles') |
| 724 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) | 725 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) |
| 725 presubmit.ParseFiles(['random_file.txt'], None | 726 presubmit.ParseFiles(['random_file.txt'], None |
| 726 ).AndReturn(['random_file.txt']) | 727 ).AndReturn(['random_file.txt']) |
| 727 output = self.mox.CreateMock(presubmit.PresubmitOutput) | 728 output = self.mox.CreateMock(presubmit.PresubmitOutput) |
| (...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2146 whitelist=['^a$', '^b$'], | 2147 whitelist=['^a$', '^b$'], |
| 2147 blacklist=['a']) | 2148 blacklist=['a']) |
| 2148 self.assertEqual(results, []) | 2149 self.assertEqual(results, []) |
| 2149 self.checkstdout( | 2150 self.checkstdout( |
| 2150 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) | 2151 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) |
| 2151 | 2152 |
| 2152 | 2153 |
| 2153 if __name__ == '__main__': | 2154 if __name__ == '__main__': |
| 2154 import unittest | 2155 import unittest |
| 2155 unittest.main() | 2156 unittest.main() |
| OLD | NEW |