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

Side by Side Diff: tests/presubmit_unittest.py

Issue 6581030: Add first changes needed for OWNERS file support. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools
Patch Set: more linting Created 9 years, 9 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
« owners.py ('K') | « presubmit_support.py ('k') | 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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,W0212,W0403 9 # pylint: disable=E1101,E1103,W0212,W0403
10 10
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 this is line number 45 90 this is line number 45
91 + 91 +
92 this is line number 46 92 this is line number 46
93 this is line number 47 93 this is line number 47
94 -this is line number 48 94 -this is line number 48
95 +this is line number 48.1 95 +this is line number 48.1
96 this is line number 49 96 this is line number 49
97 """ 97 """
98 98
99 def setUp(self): 99 def setUp(self):
100 class FakeChange(object):
101 root = '/'
102
103 def RepositoryRoot(self):
104 return self.root
105
100 SuperMoxTestBase.setUp(self) 106 SuperMoxTestBase.setUp(self)
107 self.fake_change = FakeChange()
101 self.mox.StubOutWithMock(presubmit, 'random') 108 self.mox.StubOutWithMock(presubmit, 'random')
102 self.mox.StubOutWithMock(presubmit, 'warn') 109 self.mox.StubOutWithMock(presubmit, 'warn')
103 presubmit._ASKED_FOR_FEEDBACK = False 110 presubmit._ASKED_FOR_FEEDBACK = False
104 self.fake_root_dir = self.RootDir() 111 self.fake_root_dir = self.RootDir()
105 # Special mocks. 112 # Special mocks.
106 def MockAbsPath(f): 113 def MockAbsPath(f):
107 return f 114 return f
108 def MockChdir(f): 115 def MockChdir(f):
109 return None 116 return None
110 # SuperMoxTestBase already mock these but simplify our life. 117 # SuperMoxTestBase already mock these but simplify our life.
(...skipping 15 matching lines...) Expand all
126 def testMembersChanged(self): 133 def testMembersChanged(self):
127 self.mox.ReplayAll() 134 self.mox.ReplayAll()
128 members = [ 135 members = [
129 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', 136 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks',
130 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange', 137 'GetTrySlavesExecuter', 'GitAffectedFile', 'GitChange',
131 'InputApi', 'ListRelevantPresubmitFiles', 'Main', 138 'InputApi', 'ListRelevantPresubmitFiles', 'Main',
132 'NotImplementedException', 'OutputApi', 'ParseFiles', 139 'NotImplementedException', 'OutputApi', 'ParseFiles',
133 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs', 140 'PresubmitExecuter', 'PromptYesNo', 'ScanSubDirs',
134 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO', 141 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cStringIO',
135 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json', 142 'exceptions', 'fnmatch', 'gclient_utils', 'glob', 'json',
136 'logging', 'marshal', 'normpath', 'optparse', 'os', 'pickle', 143 'logging', 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle',
137 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess', 144 'presubmit_canned_checks', 'random', 're', 'scm', 'subprocess',
138 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2', 145 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', 'urllib2',
139 'warn', 146 'warn',
140 ] 147 ]
141 # If this test fails, you should add the relevant test. 148 # If this test fails, you should add the relevant test.
142 self.compareMembers(presubmit, members) 149 self.compareMembers(presubmit, members)
143 150
144 def testListRelevantPresubmitFiles(self): 151 def testListRelevantPresubmitFiles(self):
145 join = presubmit.os.path.join 152 join = presubmit.os.path.join
146 files = [ 153 files = [
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 def testMembersChanged(self): 692 def testMembersChanged(self):
686 self.mox.ReplayAll() 693 self.mox.ReplayAll()
687 members = [ 694 members = [
688 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', 695 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles',
689 'AffectedTextFiles', 696 'AffectedTextFiles',
690 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', 697 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST',
691 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 698 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths',
692 'LocalToDepotPath', 699 'LocalToDepotPath',
693 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths', 700 'PresubmitLocalPath', 'ReadFile', 'RightHandSideLines', 'ServerPaths',
694 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ', 701 'basename', 'cPickle', 'cStringIO', 'canned_checks', 'change', 'environ',
695 'is_committing', 'json', 'marshal', 'os_path', 'pickle', 'platform', 702 'is_committing', 'json', 'marshal', 'os_path', 'owners_db', 'pickle',
696 'python_executable', 're', 'subprocess', 'tempfile', 'traceback', 703 'platform', 'python_executable', 're', 'subprocess', 'tempfile',
697 'unittest', 'urllib2', 'version', 704 'traceback', 'unittest', 'urllib2', 'version',
698 ] 705 ]
699 # If this test fails, you should add the relevant test. 706 # If this test fails, you should add the relevant test.
700 self.compareMembers(presubmit.InputApi(None, './.', False), members) 707 self.compareMembers(presubmit.InputApi(self.fake_change, './.', False),
708 members)
701 709
702 def testDepotToLocalPath(self): 710 def testDepotToLocalPath(self):
703 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn( 711 presubmit.scm.SVN.CaptureInfo('svn://foo/smurf').AndReturn(
704 {'Path': 'prout'}) 712 {'Path': 'prout'})
705 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({}) 713 presubmit.scm.SVN.CaptureInfo('svn:/foo/notfound/burp').AndReturn({})
706 self.mox.ReplayAll() 714 self.mox.ReplayAll()
707 715
708 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( 716 path = presubmit.InputApi(self.fake_change, './p', False).DepotToLocalPath(
709 'svn://foo/smurf') 717 'svn://foo/smurf')
710 self.failUnless(path == 'prout') 718 self.failUnless(path == 'prout')
711 path = presubmit.InputApi(None, './p', False).DepotToLocalPath( 719 path = presubmit.InputApi(self.fake_change, './p', False).DepotToLocalPath(
712 'svn:/foo/notfound/burp') 720 'svn:/foo/notfound/burp')
713 self.failUnless(path == None) 721 self.failUnless(path == None)
714 722
715 def testLocalToDepotPath(self): 723 def testLocalToDepotPath(self):
716 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 724 presubmit.scm.SVN.CaptureInfo('smurf').AndReturn({'URL': 'svn://foo'})
717 'svn://foo'})
718 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({}) 725 presubmit.scm.SVN.CaptureInfo('notfound-food').AndReturn({})
719 self.mox.ReplayAll() 726 self.mox.ReplayAll()
720 727 path = presubmit.InputApi(self.fake_change, './p', False).LocalToDepotPath(
721 path = presubmit.InputApi(None, './p', False).LocalToDepotPath('smurf') 728 'smurf')
722 self.assertEqual(path, 'svn://foo') 729 self.assertEqual(path, 'svn://foo')
723 path = presubmit.InputApi(None, './p', False).LocalToDepotPath( 730 path = presubmit.InputApi(self.fake_change, './p', False).LocalToDepotPath(
724 'notfound-food') 731 'notfound-food')
725 self.failUnless(path == None) 732 self.failUnless(path == None)
726 733
727 def testInputApiConstruction(self): 734 def testInputApiConstruction(self):
728 self.mox.ReplayAll() 735 self.mox.ReplayAll()
729 # Fudge the change object, it's not used during construction anyway 736 api = presubmit.InputApi(self.fake_change,
730 api = presubmit.InputApi(change=42, presubmit_path='foo/path/PRESUBMIT.py', 737 presubmit_path='foo/path/PRESUBMIT.py',
731 is_committing=False) 738 is_committing=False)
732 self.assertEquals(api.PresubmitLocalPath(), 'foo/path') 739 self.assertEquals(api.PresubmitLocalPath(), 'foo/path')
733 self.assertEquals(api.change, 42) 740 self.assertEquals(api.change, self.fake_change)
734 741
735 def testInputApiPresubmitScriptFiltering(self): 742 def testInputApiPresubmitScriptFiltering(self):
736 join = presubmit.os.path.join 743 join = presubmit.os.path.join
737 description_lines = ('Hello there', 744 description_lines = ('Hello there',
738 'this is a change', 745 'this is a change',
739 'BUG=123', 746 'BUG=123',
740 ' STORY =http://foo/ \t', 747 ' STORY =http://foo/ \t',
741 'and some more regular text') 748 'and some more regular text')
742 files = [ 749 files = [
743 ['A', join('foo', 'blat.cc')], 750 ['A', join('foo', 'blat.cc')],
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 f('a/.git'), 871 f('a/.git'),
865 f('b.c/.git'), 872 f('b.c/.git'),
866 f('a/.git/bleh.py'), 873 f('a/.git/bleh.py'),
867 f('.git/bleh.py'), 874 f('.git/bleh.py'),
868 ], 875 ],
869 [ 876 [
870 # Expected. 877 # Expected.
871 ], 878 ],
872 ), 879 ),
873 ] 880 ]
874 input_api = presubmit.InputApi(None, './PRESUBMIT.py', False) 881 input_api = presubmit.InputApi(self.fake_change, './PRESUBMIT.py', False)
875 self.mox.ReplayAll() 882 self.mox.ReplayAll()
876 883
877 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 22) 884 self.assertEqual(len(input_api.DEFAULT_WHITE_LIST), 22)
878 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9) 885 self.assertEqual(len(input_api.DEFAULT_BLACK_LIST), 9)
879 for item in files: 886 for item in files:
880 results = filter(input_api.FilterSourceFile, item[0]) 887 results = filter(input_api.FilterSourceFile, item[0])
881 for i in range(len(results)): 888 for i in range(len(results)):
882 self.assertEquals(results[i].LocalPath(), 889 self.assertEquals(results[i].LocalPath(),
883 presubmit.normpath(item[1][i])) 890 presubmit.normpath(item[1][i]))
884 # Same number of expected results. 891 # Same number of expected results.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 self.failUnless(len(output) == 1) 1163 self.failUnless(len(output) == 1)
1157 self.failUnless(files[0] == output[0]) 1164 self.failUnless(files[0] == output[0])
1158 1165
1159 1166
1160 class GclChangeUnittest(PresubmitTestsBase): 1167 class GclChangeUnittest(PresubmitTestsBase):
1161 def testMembersChanged(self): 1168 def testMembersChanged(self):
1162 members = [ 1169 members = [
1163 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles', 1170 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedTextFiles',
1164 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name', 1171 'DescriptionText', 'FullDescriptionText', 'LocalPaths', 'Name',
1165 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths', 1172 'RepositoryRoot', 'RightHandSideLines', 'ServerPaths',
1166 'issue', 'patchset', 'scm', 'tags', 1173 'approvers', 'issue', 'patchset', 'scm', 'tags',
1167 ] 1174 ]
1168 # If this test fails, you should add the relevant test. 1175 # If this test fails, you should add the relevant test.
1169 self.mox.ReplayAll() 1176 self.mox.ReplayAll()
1170 1177
1171 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')], 1178 change = presubmit.Change('foo', 'foo', self.fake_root_dir, [('M', 'AA')],
1172 0, 0) 1179 0, 0)
1173 self.compareMembers(change, members) 1180 self.compareMembers(change, members)
1174 1181
1175 1182
1176 class CannedChecksUnittest(PresubmitTestsBase): 1183 class CannedChecksUnittest(PresubmitTestsBase):
(...skipping 30 matching lines...) Expand all
1207 'CheckChangeLintsClean', 1214 'CheckChangeLintsClean',
1208 'CheckChangeSvnEolStyle', 1215 'CheckChangeSvnEolStyle',
1209 'CheckLicense', 1216 'CheckLicense',
1210 'CheckSvnModifiedDirectories', 1217 'CheckSvnModifiedDirectories',
1211 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty', 1218 'CheckSvnForCommonMimeTypes', 'CheckSvnProperty',
1212 'CheckDoNotSubmit', 1219 'CheckDoNotSubmit',
1213 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', 1220 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
1214 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', 1221 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests',
1215 'RunPylint', 1222 'RunPylint',
1216 'CheckBuildbotPendingBuilds', 'CheckRietveldTryJobExecution', 1223 'CheckBuildbotPendingBuilds', 'CheckRietveldTryJobExecution',
1224 'CheckOwners',
1217 ] 1225 ]
1218 # If this test fails, you should add the relevant test. 1226 # If this test fails, you should add the relevant test.
1219 self.compareMembers(presubmit_canned_checks, members) 1227 self.compareMembers(presubmit_canned_checks, members)
1220 1228
1221 def DescriptionTest(self, check, description1, description2, error_type, 1229 def DescriptionTest(self, check, description1, description2, error_type,
1222 committing): 1230 committing):
1223 change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None, 1231 change1 = presubmit.Change('foo1', description1, self.fake_root_dir, None,
1224 0, 0) 1232 0, 0)
1225 input_api1 = self.MockInputApi(change1, committing) 1233 input_api1 = self.MockInputApi(change1, committing)
1226 change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None, 1234 change2 = presubmit.Change('foo2', description2, self.fake_root_dir, None,
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 results = presubmit_canned_checks.CheckBuildbotPendingBuilds( 1837 results = presubmit_canned_checks.CheckBuildbotPendingBuilds(
1830 input_api, presubmit.OutputApi, 'uurl', 2, ('foo')) 1838 input_api, presubmit.OutputApi, 'uurl', 2, ('foo'))
1831 self.assertEquals(len(results), 1) 1839 self.assertEquals(len(results), 1)
1832 self.assertEquals(results[0].__class__, 1840 self.assertEquals(results[0].__class__,
1833 presubmit.OutputApi.PresubmitNotifyResult) 1841 presubmit.OutputApi.PresubmitNotifyResult)
1834 1842
1835 1843
1836 if __name__ == '__main__': 1844 if __name__ == '__main__':
1837 import unittest 1845 import unittest
1838 unittest.main() 1846 unittest.main()
OLDNEW
« owners.py ('K') | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698