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

Side by Side Diff: tests/presubmit_unittest.py

Issue 8036046: Revert r102783 "Support for |change| argument to |GetPreferredTrySlaves()|." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 9 years, 2 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 | « presubmit_support.py ('k') | tests/trychange_unittest.py » ('j') | 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 146
147 def testMembersChanged(self): 147 def testMembersChanged(self):
148 self.mox.ReplayAll() 148 self.mox.ReplayAll()
149 members = [ 149 members = [
150 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', 150 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
151 'GetTrySlavesExecuter', 'GitAffectedFile', 151 'GetTrySlavesExecuter', 'GitAffectedFile',
152 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', 152 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
153 'OutputApi', 'ParseFiles', 'PresubmitFailure', 153 'OutputApi', 'ParseFiles', 'PresubmitFailure',
154 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', 154 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs',
155 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 155 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO',
156 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'inspect', 'json', 156 'fix_encoding', 'fnmatch', 'gclient_utils', 'glob', 'json',
157 'load_files', 157 'load_files',
158 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', 158 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
159 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', 159 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm',
160 'subprocess', 160 'subprocess',
161 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', 161 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2',
162 'warn', 162 'warn',
163 ] 163 ]
164 # If this test fails, you should add the relevant test. 164 # If this test fails, you should add the relevant test.
165 self.compareMembers(presubmit, members) 165 self.compareMembers(presubmit, members)
166 166
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 'Warning, no PRESUBMIT.py found.\n' 662 'Warning, no PRESUBMIT.py found.\n'
663 'Running default presubmit script.\n' 663 'Running default presubmit script.\n'
664 '\n' 664 '\n'
665 '** Presubmit Messages **\n' 665 '** Presubmit Messages **\n'
666 'http://tracker.com/42\n' 666 'http://tracker.com/42\n'
667 '\n' 667 '\n'
668 'Presubmit checks passed.\n')) 668 'Presubmit checks passed.\n'))
669 669
670 def testGetTrySlavesExecuter(self): 670 def testGetTrySlavesExecuter(self):
671 self.mox.ReplayAll() 671 self.mox.ReplayAll()
672 change = presubmit.Change( 672
673 'foo',
674 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n',
675 self.fake_root_dir,
676 None,
677 0,
678 0,
679 None)
680 executer = presubmit.GetTrySlavesExecuter() 673 executer = presubmit.GetTrySlavesExecuter()
681 self.assertEqual([], executer.ExecPresubmitScript('', '', '', change)) 674 self.assertEqual([], executer.ExecPresubmitScript('', '', ''))
682 self.assertEqual([], 675 self.assertEqual(
683 executer.ExecPresubmitScript('def foo():\n return\n', '', '', change)) 676 [], executer.ExecPresubmitScript('def foo():\n return\n', '', ''))
684 677
685 # bad results 678 # bad results
686 starts_with_space_result = [' starts_with_space'] 679 starts_with_space_result = [' starts_with_space']
687 not_list_result1 = "'foo'" 680 not_list_result1 = "'foo'"
688 not_list_result2 = "('a', 'tuple')" 681 not_list_result2 = "('a', 'tuple')"
689 for result in starts_with_space_result, not_list_result1, not_list_result2: 682 for result in starts_with_space_result, not_list_result1, not_list_result2:
690 self.assertRaises(presubmit.PresubmitFailure, 683 self.assertRaises(presubmit.PresubmitFailure,
691 executer.ExecPresubmitScript, 684 executer.ExecPresubmitScript,
692 self.presubmit_tryslave % result, '', '', change) 685 self.presubmit_tryslave % result, '', '')
693 686
694 # good results 687 # good results
695 expected_result = ['1', '2', '3'] 688 expected_result = ['1', '2', '3']
696 empty_result = [] 689 empty_result = []
697 space_in_name_result = ['foo bar', '1\t2 3'] 690 space_in_name_result = ['foo bar', '1\t2 3']
698 for result in expected_result, empty_result, space_in_name_result: 691 for result in expected_result, empty_result, space_in_name_result:
699 self.assertEqual( 692 self.assertEqual(
700 result, 693 result,
701 executer.ExecPresubmitScript( 694 executer.ExecPresubmitScript(
702 self.presubmit_tryslave % result, '', '', change)) 695 self.presubmit_tryslave % result, '', ''))
703 696
704 def testGetTrySlavesExecuterWithProject(self): 697 def testGetTrySlavesExecuterWithProject(self):
705 self.mox.ReplayAll() 698 self.mox.ReplayAll()
706 699
707 change = presubmit.Change(
708 'foo',
709 'Blah Blah\n\nSTORY=http://tracker.com/42\nBUG=boo\n',
710 self.fake_root_dir,
711 None,
712 0,
713 0,
714 None)
715
716 executer = presubmit.GetTrySlavesExecuter() 700 executer = presubmit.GetTrySlavesExecuter()
717 expected_result1 = ['1', '2'] 701 expected_result1 = ['1', '2']
718 expected_result2 = ['a', 'b', 'c'] 702 expected_result2 = ['a', 'b', 'c']
719 script = self.presubmit_tryslave_project % ( 703 script = self.presubmit_tryslave_project % (
720 repr('foo'), repr(expected_result1), repr(expected_result2)) 704 repr('foo'), repr(expected_result1), repr(expected_result2))
721 self.assertEqual( 705 self.assertEqual(
722 expected_result1, executer.ExecPresubmitScript(script, '', 'foo', 706 expected_result1, executer.ExecPresubmitScript(script, '', 'foo'))
723 change))
724 self.assertEqual( 707 self.assertEqual(
725 expected_result2, executer.ExecPresubmitScript(script, '', 'bar', 708 expected_result2, executer.ExecPresubmitScript(script, '', 'bar'))
726 change))
727 709
728 def testDoGetTrySlaves(self): 710 def testDoGetTrySlaves(self):
729 join = presubmit.os.path.join 711 join = presubmit.os.path.join
730 filename = 'foo.cc' 712 filename = 'foo.cc'
731 filename_linux = join('linux_only', 'penguin.cc') 713 filename_linux = join('linux_only', 'penguin.cc')
732 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py') 714 root_presubmit = join(self.fake_root_dir, 'PRESUBMIT.py')
733 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py') 715 linux_presubmit = join(self.fake_root_dir, 'linux_only', 'PRESUBMIT.py')
734 inherit_path = presubmit.os.path.join(self.fake_root_dir, 716 inherit_path = presubmit.os.path.join(self.fake_root_dir,
735 self._INHERIT_SETTINGS) 717 self._INHERIT_SETTINGS)
736 718
737 presubmit.os.path.isfile(inherit_path).AndReturn(False) 719 presubmit.os.path.isfile(inherit_path).AndReturn(False)
738 presubmit.os.path.isfile(root_presubmit).AndReturn(True) 720 presubmit.os.path.isfile(root_presubmit).AndReturn(True)
739 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( 721 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn(
740 self.presubmit_tryslave % '["win"]') 722 self.presubmit_tryslave % '["win"]')
741 723
742 presubmit.os.path.isfile(inherit_path).AndReturn(False) 724 presubmit.os.path.isfile(inherit_path).AndReturn(False)
743 presubmit.os.path.isfile(root_presubmit).AndReturn(True) 725 presubmit.os.path.isfile(root_presubmit).AndReturn(True)
744 presubmit.os.path.isfile(linux_presubmit).AndReturn(True) 726 presubmit.os.path.isfile(linux_presubmit).AndReturn(True)
745 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn( 727 presubmit.gclient_utils.FileRead(root_presubmit, 'rU').AndReturn(
746 self.presubmit_tryslave % '["win"]') 728 self.presubmit_tryslave % '["win"]')
747 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn( 729 presubmit.gclient_utils.FileRead(linux_presubmit, 'rU').AndReturn(
748 self.presubmit_tryslave % '["linux"]') 730 self.presubmit_tryslave % '["linux"]')
749 self.mox.ReplayAll() 731 self.mox.ReplayAll()
750 732
751 change = presubmit.Change(
752 'mychange', '', self.fake_root_dir, [], 0, 0, None)
753
754 output = StringIO.StringIO() 733 output = StringIO.StringIO()
755 self.assertEqual(['win'], 734 self.assertEqual(['win'],
756 presubmit.DoGetTrySlaves(change, [filename], 735 presubmit.DoGetTrySlaves([filename], self.fake_root_dir,
757 self.fake_root_dir,
758 None, None, False, output)) 736 None, None, False, output))
759 output = StringIO.StringIO() 737 output = StringIO.StringIO()
760 self.assertEqual(['win', 'linux'], 738 self.assertEqual(['win', 'linux'],
761 presubmit.DoGetTrySlaves(change, 739 presubmit.DoGetTrySlaves([filename, filename_linux],
762 [filename, filename_linux],
763 self.fake_root_dir, None, None, 740 self.fake_root_dir, None, None,
764 False, output)) 741 False, output))
765 742
766 def testMainUnversioned(self): 743 def testMainUnversioned(self):
767 # OptParser calls presubmit.os.path.exists and is a pain when mocked. 744 # OptParser calls presubmit.os.path.exists and is a pain when mocked.
768 self.UnMock(presubmit.os.path, 'exists') 745 self.UnMock(presubmit.os.path, 'exists')
769 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') 746 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks')
770 self.mox.StubOutWithMock(presubmit, 'ParseFiles') 747 self.mox.StubOutWithMock(presubmit, 'ParseFiles')
771 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) 748 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None)
772 presubmit.ParseFiles(['random_file.txt'], None 749 presubmit.ParseFiles(['random_file.txt'], None
(...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after
2254 owners_check=True) 2231 owners_check=True)
2255 self.assertEqual(1, len(results)) 2232 self.assertEqual(1, len(results))
2256 self.assertEqual( 2233 self.assertEqual(
2257 'Found line ending with white spaces in:', results[0]._message) 2234 'Found line ending with white spaces in:', results[0]._message)
2258 self.checkstdout('') 2235 self.checkstdout('')
2259 2236
2260 2237
2261 if __name__ == '__main__': 2238 if __name__ == '__main__':
2262 import unittest 2239 import unittest
2263 unittest.main() 2240 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | tests/trychange_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698