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

Side by Side Diff: tests/presubmit_unittest.py

Issue 7062012: Fixing unit tests to match --project changes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 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 21 matching lines...) Expand all
32 return [output_api.PresubmitPromptWarning("??"), 32 return [output_api.PresubmitPromptWarning("??"),
33 output_api.PresubmitError("XX!!XX")] 33 output_api.PresubmitError("XX!!XX")]
34 else: 34 else:
35 return () 35 return ()
36 """ 36 """
37 presubmit_tryslave = """ 37 presubmit_tryslave = """
38 def GetPreferredTrySlaves(): 38 def GetPreferredTrySlaves():
39 return %s 39 return %s
40 """ 40 """
41 41
42 presubmit_tryslave_project = """
43 def GetPreferredTrySlaves(project):
44 if project == %s:
45 return %s
46 else:
47 return %s
48 """
49
42 presubmit_diffs = """ 50 presubmit_diffs = """
43 --- file1 2011-02-09 10:38:16.517224845 -0800 51 --- file1 2011-02-09 10:38:16.517224845 -0800
44 +++ file2 2011-02-09 10:38:53.177226516 -0800 52 +++ file2 2011-02-09 10:38:53.177226516 -0800
45 @@ -1,6 +1,5 @@ 53 @@ -1,6 +1,5 @@
46 this is line number 0 54 this is line number 0
47 this is line number 1 55 this is line number 1
48 -this is line number 2 to be deleted 56 -this is line number 2 to be deleted
49 this is line number 3 57 this is line number 3
50 this is line number 4 58 this is line number 4
51 this is line number 5 59 this is line number 5
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 '\n' 662 '\n'
655 '** Presubmit Messages **\n' 663 '** Presubmit Messages **\n'
656 'http://tracker.com/42\n' 664 'http://tracker.com/42\n'
657 '\n' 665 '\n'
658 'Presubmit checks passed.\n')) 666 'Presubmit checks passed.\n'))
659 667
660 def testGetTrySlavesExecuter(self): 668 def testGetTrySlavesExecuter(self):
661 self.mox.ReplayAll() 669 self.mox.ReplayAll()
662 670
663 executer = presubmit.GetTrySlavesExecuter() 671 executer = presubmit.GetTrySlavesExecuter()
664 self.assertEqual([], executer.ExecPresubmitScript('', '')) 672 self.assertEqual([], executer.ExecPresubmitScript('', '', ''))
665 self.assertEqual( 673 self.assertEqual(
666 [], executer.ExecPresubmitScript('def foo():\n return\n', '')) 674 [], executer.ExecPresubmitScript('def foo():\n return\n', '', ''))
667 675
668 # bad results 676 # bad results
669 starts_with_space_result = [' starts_with_space'] 677 starts_with_space_result = [' starts_with_space']
670 not_list_result1 = "'foo'" 678 not_list_result1 = "'foo'"
671 not_list_result2 = "('a', 'tuple')" 679 not_list_result2 = "('a', 'tuple')"
672 for result in starts_with_space_result, not_list_result1, not_list_result2: 680 for result in starts_with_space_result, not_list_result1, not_list_result2:
673 self.assertRaises(presubmit.PresubmitFailure, 681 self.assertRaises(presubmit.PresubmitFailure,
674 executer.ExecPresubmitScript, 682 executer.ExecPresubmitScript,
675 self.presubmit_tryslave % result, '') 683 self.presubmit_tryslave % result, '', '')
676 684
677 # good results 685 # good results
678 expected_result = ['1', '2', '3'] 686 expected_result = ['1', '2', '3']
679 empty_result = [] 687 empty_result = []
680 space_in_name_result = ['foo bar', '1\t2 3'] 688 space_in_name_result = ['foo bar', '1\t2 3']
681 for result in expected_result, empty_result, space_in_name_result: 689 for result in expected_result, empty_result, space_in_name_result:
682 self.assertEqual( 690 self.assertEqual(
683 result, 691 result,
684 executer.ExecPresubmitScript(self.presubmit_tryslave % result, '')) 692 executer.ExecPresubmitScript(
693 self.presubmit_tryslave % result, '', ''))
694
695 def testGetTrySlavesExecuterWithProject(self):
696 self.mox.ReplayAll()
697
698 executer = presubmit.GetTrySlavesExecuter()
699 expected_result1 = ['1', '2']
700 expected_result2 = ['a', 'b', 'c']
701 script = self.presubmit_tryslave_project % (
702 repr('foo'), repr(expected_result1), repr(expected_result2))
703 self.assertEqual(
704 expected_result1, executer.ExecPresubmitScript(script, '', 'foo'))
705 self.assertEqual(
706 expected_result2, executer.ExecPresubmitScript(script, '', 'bar'))
685 707
686 def testDoGetTrySlaves(self): 708 def testDoGetTrySlaves(self):
687 join = presubmit.os.path.join 709 join = presubmit.os.path.join
688 filename = 'foo.cc' 710 filename = 'foo.cc'
689 filename_linux = join('linux_only', 'penguin.cc') 711 filename_linux = join('linux_only', 'penguin.cc')
690 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') 712 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py')
691 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') 713 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py')
692 inherit_path = presubmit.os.path.join(self.fake_root_dir, 714 inherit_path = presubmit.os.path.join(self.fake_root_dir,
693 self._INHERIT_SETTINGS) 715 self._INHERIT_SETTINGS)
694 716
695 presubmit.os.path.isfile(inherit_path).AndReturn(False) 717 presubmit.os.path.isfile(inherit_path).AndReturn(False)
696 presubmit.os.path.isfile(root_presubmit).AndReturn(True) 718 presubmit.os.path.isfile(root_presubmit).AndReturn(True)
697 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( 719 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn(
698 self.presubmit_tryslave % '["win"]') 720 self.presubmit_tryslave % '["win"]')
699 721
700 presubmit.os.path.isfile(inherit_path).AndReturn(False) 722 presubmit.os.path.isfile(inherit_path).AndReturn(False)
701 presubmit.os.path.isfile(root_presubmit).AndReturn(True) 723 presubmit.os.path.isfile(root_presubmit).AndReturn(True)
702 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) 724 presubmit.os.path.isfile(linux_presubmit).AndReturn(True)
703 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( 725 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn(
704 self.presubmit_tryslave % '["win"]') 726 self.presubmit_tryslave % '["win"]')
705 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn( 727 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn(
706 self.presubmit_tryslave % '["linux"]') 728 self.presubmit_tryslave % '["linux"]')
707 self.mox.ReplayAll() 729 self.mox.ReplayAll()
708 730
709 output = StringIO.StringIO() 731 output = StringIO.StringIO()
710 self.assertEqual(['win'], 732 self.assertEqual(['win'],
711 presubmit.DoGetTrySlaves([filename], self.fake_root_dir, 733 presubmit.DoGetTrySlaves([filename], self.fake_root_dir,
712 None, False, output)) 734 None, None, False, output))
713 output = StringIO.StringIO() 735 output = StringIO.StringIO()
714 self.assertEqual(['win', 'linux'], 736 self.assertEqual(['win', 'linux'],
715 presubmit.DoGetTrySlaves([filename, filename_linux], 737 presubmit.DoGetTrySlaves([filename, filename_linux],
716 self.fake_root_dir, None, False, 738 self.fake_root_dir, None, None,
717 output)) 739 False, output))
718 740
719 def testMainUnversioned(self): 741 def testMainUnversioned(self):
720 # OptParser calls presubmit.os.path.exists and is a pain when mocked. 742 # OptParser calls presubmit.os.path.exists and is a pain when mocked.
721 self.UnMock(presubmit.os.path, 'exists') 743 self.UnMock(presubmit.os.path, 'exists')
722 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') 744 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks')
723 self.mox.StubOutWithMock(presubmit, 'ParseFiles') 745 self.mox.StubOutWithMock(presubmit, 'ParseFiles')
724 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) 746 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None)
725 presubmit.ParseFiles(['random_file.txt'], None 747 presubmit.ParseFiles(['random_file.txt'], None
726 ).AndReturn(['random_file.txt']) 748 ).AndReturn(['random_file.txt'])
727 output = self.mox.CreateMock(presubmit.PresubmitOutput) 749 output = self.mox.CreateMock(presubmit.PresubmitOutput)
(...skipping 1418 matching lines...) Expand 10 before | Expand all | Expand 10 after
2146 whitelist=['^a$', '^b$'], 2168 whitelist=['^a$', '^b$'],
2147 blacklist=['a']) 2169 blacklist=['a'])
2148 self.assertEqual(results, []) 2170 self.assertEqual(results, [])
2149 self.checkstdout( 2171 self.checkstdout(
2150 'Running %s\n' % presubmit.os.path.join('random_directory', 'b')) 2172 'Running %s\n' % presubmit.os.path.join('random_directory', 'b'))
2151 2173
2152 2174
2153 if __name__ == '__main__': 2175 if __name__ == '__main__':
2154 import unittest 2176 import unittest
2155 unittest.main() 2177 unittest.main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698