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

Side by Side Diff: PRESUBMIT_test.py

Issue 11448014: Add a presubmit check to prevent committing .rej/.orig patch files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« PRESUBMIT.py ('K') | « PRESUBMIT.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 import os 6 import os
7 import re 7 import re
8 import unittest 8 import unittest
9 9
10 import PRESUBMIT 10 import PRESUBMIT
11 11
12 12
13 class MockInputApi(object): 13 class MockInputApi(object):
14 def __init__(self): 14 def __init__(self):
15 self.re = re 15 self.re = re
16 self.os_path = os.path 16 self.os_path = os.path
17 self.files = []
18
19 def AddFile(self, f):
M-A Ruel 2012/12/05 19:30:17 I don't think it's necessary.
20 self.files.append(f)
21
22 def AffectedFiles(self):
23 return self.files
24
25
26 class MockOutputApi(object):
27 class PresubmitResult(object):
28 def __init__(self, message, items=None, long_text=''):
29 self.message = message
30 self.items = items
31 self.long_text = long_text
32
33 class PresubmitError(PresubmitResult):
34 pass
35
36 class PresubmitPromptWarning(PresubmitResult):
37 pass
38
39 class PresubmitNotifyResult(PresubmitResult):
40 pass
17 41
18 42
19 class MockFile(object): 43 class MockFile(object):
20 def __init__(self, local_path, new_contents): 44 def __init__(self, local_path, new_contents):
21 self._local_path = local_path 45 self._local_path = local_path
22 self._new_contents = new_contents 46 self._new_contents = new_contents
23 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] 47 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)]
24 48
25 def ChangedContents(self): 49 def ChangedContents(self):
26 return self._changed_contents 50 return self._changed_contents
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ' ScopedTempDir temp_dir_;', 218 ' ScopedTempDir temp_dir_;',
195 '>>>>>>> master'] 219 '>>>>>>> master']
196 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( 220 errors = PRESUBMIT._CheckForVersionControlConflictsInFile(
197 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 221 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
198 self.assertEqual(3, len(errors)) 222 self.assertEqual(3, len(errors))
199 self.assertTrue('1' in errors[0]) 223 self.assertTrue('1' in errors[0])
200 self.assertTrue('3' in errors[1]) 224 self.assertTrue('3' in errors[1])
201 self.assertTrue('5' in errors[2]) 225 self.assertTrue('5' in errors[2])
202 226
203 227
228 class BadExtensionsTest(unittest.TestCase):
229 def testBadRejFile(self):
230 mock_input_api = MockInputApi()
231 mock_input_api.AddFile(MockFile('some/path/foo.cc', ''))
M-A Ruel 2012/12/05 19:30:17 mock_input_api.files = [ MockFile(...), ..
232 mock_input_api.AddFile(MockFile('some/path/foo.cc.rej', ''))
233 mock_input_api.AddFile(MockFile('some/path2/bar.h.rej', ''))
234
235 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
236 self.assertEqual(1, len(results))
237 self.assertEqual(2, len(results[0].items))
238 self.assertTrue('foo.cc.rej' in results[0].items[0])
239 self.assertTrue('bar.h.rej' in results[0].items[1])
240
241 def testBadOrigFile(self):
242 mock_input_api = MockInputApi()
243 mock_input_api.AddFile(MockFile('other/path/qux.h.orig', ''))
244 mock_input_api.AddFile(MockFile('other/path/qux.h', ''))
245 mock_input_api.AddFile(MockFile('other/path/qux.cc', ''))
246
247 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
248 self.assertEqual(1, len(results))
249 self.assertEqual(1, len(results[0].items))
250 self.assertTrue('qux.h.orig' in results[0].items[0])
251
252 def testGoodFiles(self):
253 mock_input_api = MockInputApi()
254 mock_input_api.AddFile(MockFile('other/path/qux.h', ''))
255 mock_input_api.AddFile(MockFile('other/path/qux.cc', ''))
256 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
257 self.assertEqual(0, len(results))
258
259
204 if __name__ == '__main__': 260 if __name__ == '__main__':
205 unittest.main() 261 unittest.main()
OLDNEW
« PRESUBMIT.py ('K') | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698