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

Side by Side Diff: PRESUBMIT_unittest.py

Issue 42086: Allow PRESUBMIT.py to handle deleted files. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 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
« no previous file with comments | « 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/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 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 top-level Chromium presubmit script. 6 """Unit tests for top-level Chromium presubmit script.
7 """ 7 """
8 8
9 9
10 import os 10 import os
11 import PRESUBMIT 11 import PRESUBMIT
12 import re 12 import re
13 import unittest 13 import unittest
14 14
15 15
16 class MockInputApi(object): 16 class MockInputApi(object):
17 def __init__(self): 17 def __init__(self):
18 self.affected_files = [] 18 self.affected_files = []
19 self.re = re 19 self.re = re
20 self.os_path = os.path 20 self.os_path = os.path
21 21
22 def AffectedFiles(self): 22 def AffectedFiles(self, include_deletes=True):
23 return self.affected_files 23 if include_deletes:
24 return self.affected_files
25 else:
26 return filter(lambda x: x.Action() != 'D', self.affected_files)
24 27
25 def AffectedTextFiles(self, include_deletes=True): 28 def AffectedTextFiles(self, include_deletes=True):
26 return self.affected_files 29 return self.affected_files
27 30
28 31
29 class MockAffectedFile(object): 32 class MockAffectedFile(object):
30 def __init__(self, path): 33 def __init__(self, path, action='A'):
31 self.path = path 34 self.path = path
35 self.action = action
36
37 def Action(self):
38 return self.action
32 39
33 def LocalPath(self): 40 def LocalPath(self):
34 return self.path 41 return self.path
35 42
36 43
37 class MockOutputApi(object): 44 class MockOutputApi(object):
38 class PresubmitError(object): 45 class PresubmitError(object):
39 def __init__(self, msg, items=[], long_text=''): 46 def __init__(self, msg, items=[], long_text=''):
40 self.msg = msg 47 self.msg = msg
41 self.items = items 48 self.items = items
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 self.failUnless( 82 self.failUnless(
76 len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3) 83 len(PRESUBMIT.LocalChecks(api, MockOutputApi)[0].items) == 3)
77 84
78 self.file_contents = 'both\ttabs and\r\nCRLF\n' 85 self.file_contents = 'both\ttabs and\r\nCRLF\n'
79 # 3 source files, 1 error by file + 1 global CR error. 86 # 3 source files, 1 error by file + 1 global CR error.
80 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4) 87 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 4)
81 88
82 self.file_contents = 'file with\nzero \\t errors \\r\\n\n' 89 self.file_contents = 'file with\nzero \\t errors \\r\\n\n'
83 self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi)) 90 self.failIf(PRESUBMIT.LocalChecks(api, MockOutputApi))
84 91
92 def testLocalChecksDeletedFile(self):
93 api = MockInputApi()
94 api.affected_files = [
95 MockAffectedFile('foo/blat/source.py', 'D'),
96 ]
97 self.file_contents = 'file with \n\terror\nhere\r\nyes there'
98 self.failUnless(len(PRESUBMIT.LocalChecks(api, MockOutputApi)) == 0)
99
85 100
86 if __name__ == '__main__': 101 if __name__ == '__main__':
87 unittest.main() 102 unittest.main()
OLDNEW
« no previous file with comments | « PRESUBMIT.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698