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

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: Address all comments 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 AffectedFiles(self):
20 return self.files
21
22
23 class MockOutputApi(object):
24 class PresubmitResult(object):
25 def __init__(self, message, items=None, long_text=''):
26 self.message = message
27 self.items = items
28 self.long_text = long_text
29
30 class PresubmitError(PresubmitResult):
31 pass
32
33 class PresubmitPromptWarning(PresubmitResult):
34 pass
35
36 class PresubmitNotifyResult(PresubmitResult):
37 pass
17 38
18 39
19 class MockFile(object): 40 class MockFile(object):
20 def __init__(self, local_path, new_contents): 41 def __init__(self, local_path, new_contents):
21 self._local_path = local_path 42 self._local_path = local_path
22 self._new_contents = new_contents 43 self._new_contents = new_contents
23 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)] 44 self._changed_contents = [(i + 1, l) for i, l in enumerate(new_contents)]
24 45
25 def ChangedContents(self): 46 def ChangedContents(self):
26 return self._changed_contents 47 return self._changed_contents
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ' ScopedTempDir temp_dir_;', 215 ' ScopedTempDir temp_dir_;',
195 '>>>>>>> master'] 216 '>>>>>>> master']
196 errors = PRESUBMIT._CheckForVersionControlConflictsInFile( 217 errors = PRESUBMIT._CheckForVersionControlConflictsInFile(
197 MockInputApi(), MockFile('some/path/foo_platform.cc', lines)) 218 MockInputApi(), MockFile('some/path/foo_platform.cc', lines))
198 self.assertEqual(3, len(errors)) 219 self.assertEqual(3, len(errors))
199 self.assertTrue('1' in errors[0]) 220 self.assertTrue('1' in errors[0])
200 self.assertTrue('3' in errors[1]) 221 self.assertTrue('3' in errors[1])
201 self.assertTrue('5' in errors[2]) 222 self.assertTrue('5' in errors[2])
202 223
203 224
225 class BadExtensionsTest(unittest.TestCase):
226 def testBadRejFile(self):
227 mock_input_api = MockInputApi()
228 mock_input_api.files = [
229 MockFile('some/path/foo.cc', ''),
230 MockFile('some/path/foo.cc.rej', ''),
231 MockFile('some/path2/bar.h.rej', ''),
232 ]
233
234 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
235 self.assertEqual(1, len(results))
236 self.assertEqual(2, len(results[0].items))
237 self.assertTrue('foo.cc.rej' in results[0].items[0])
238 self.assertTrue('bar.h.rej' in results[0].items[1])
239
240 def testBadOrigFile(self):
241 mock_input_api = MockInputApi()
242 mock_input_api.files = [
243 MockFile('other/path/qux.h.orig', ''),
244 MockFile('other/path/qux.h', ''),
245 MockFile('other/path/qux.cc', ''),
246 ]
247
248 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
249 self.assertEqual(1, len(results))
250 self.assertEqual(1, len(results[0].items))
251 self.assertTrue('qux.h.orig' in results[0].items[0])
252
253 def testGoodFiles(self):
254 mock_input_api = MockInputApi()
255 mock_input_api.files = [
256 MockFile('other/path/qux.h', ''),
257 MockFile('other/path/qux.cc', ''),
258 ]
259 results = PRESUBMIT._CheckPatchFiles(mock_input_api, MockOutputApi())
260 self.assertEqual(0, len(results))
261
262
204 if __name__ == '__main__': 263 if __name__ == '__main__':
205 unittest.main() 264 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