OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-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 presubmit_support.py and presubmit_canned_checks.py.""" | 6 """Unit tests for presubmit_support.py and presubmit_canned_checks.py.""" |
7 | 7 |
8 import os | 8 import os |
9 import StringIO | 9 import StringIO |
10 import sys | 10 import sys |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 if not x.startswith('_')] | 109 if not x.startswith('_')] |
110 self.assertEqual(actual_members, sorted(members)) | 110 self.assertEqual(actual_members, sorted(members)) |
111 | 111 |
112 | 112 |
113 class PresubmitUnittest(PresubmitTestsBase): | 113 class PresubmitUnittest(PresubmitTestsBase): |
114 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 114 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
115 def testMembersChanged(self): | 115 def testMembersChanged(self): |
116 members = [ | 116 members = [ |
117 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', | 117 'AffectedFile', 'DoPresubmitChecks', 'GclChange', 'InputApi', |
118 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', | 118 'ListRelevantPresubmitFiles', 'Main', 'NotImplementedException', |
119 'OutputApi', 'ParseFiles', 'PresubmitExecuter', 'SPECIAL_KEYS', | 119 'OutputApi', 'ParseFiles', 'PresubmitExecuter', |
120 'ScanSubDirs', 'SvnAffectedFile', 'cPickle', 'cStringIO', 'exceptions', | 120 'ScanSubDirs', 'SvnAffectedFile', 'cPickle', 'cStringIO', 'exceptions', |
121 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', | 121 'fnmatch', 'gcl', 'gclient', 'glob', 'marshal', 'normpath', 'optparse', |
122 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', | 122 'os', 'pickle', 'presubmit_canned_checks', 're', 'subprocess', 'sys', |
123 'tempfile', 'types', 'urllib2', | 123 'tempfile', 'types', 'urllib2', |
124 ] | 124 ] |
125 # If this test fails, you should add the relevant test. | 125 # If this test fails, you should add the relevant test. |
126 self.compareMembers(presubmit, members) | 126 self.compareMembers(presubmit, members) |
127 | 127 |
128 def testListRelevantPresubmitFiles(self): | 128 def testListRelevantPresubmitFiles(self): |
129 presubmit_files = presubmit.ListRelevantPresubmitFiles([ | 129 presubmit_files = presubmit.ListRelevantPresubmitFiles([ |
(...skipping 25 matching lines...) Expand all Loading... |
155 ['M', 'flop/notfound.txt'], # not found in SVN, still exists locally | 155 ['M', 'flop/notfound.txt'], # not found in SVN, still exists locally |
156 ['D', 'boo/flap.h'], | 156 ['D', 'boo/flap.h'], |
157 ] | 157 ] |
158 | 158 |
159 ci = gcl.ChangeInfo(name='mychange', | 159 ci = gcl.ChangeInfo(name='mychange', |
160 description='\n'.join(description_lines), | 160 description='\n'.join(description_lines), |
161 files=files) | 161 files=files) |
162 change = presubmit.GclChange(ci) | 162 change = presubmit.GclChange(ci) |
163 | 163 |
164 self.failUnless(change.Change() == 'mychange') | 164 self.failUnless(change.Change() == 'mychange') |
165 self.failUnless(change.Changelist() == 'mychange') | |
166 self.failUnless(change.DescriptionText() == | 165 self.failUnless(change.DescriptionText() == |
167 'Hello there\nthis is a change\nand some more regular text') | 166 'Hello there\nthis is a change\nand some more regular text') |
168 self.failUnless(change.FullDescriptionText() == | 167 self.failUnless(change.FullDescriptionText() == |
169 '\n'.join(description_lines)) | 168 '\n'.join(description_lines)) |
170 | 169 |
171 self.failUnless(change.BugIDs == '123') | |
172 self.failUnless(change.BUG == '123') | 170 self.failUnless(change.BUG == '123') |
173 self.failUnless(change.STORY == 'http://foo/') | 171 self.failUnless(change.STORY == 'http://foo/') |
174 | 172 |
175 self.failUnless(len(change.AffectedFiles()) == 4) | 173 self.failUnless(len(change.AffectedFiles()) == 4) |
176 self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5) | 174 self.failUnless(len(change.AffectedFiles(include_dirs=True)) == 5) |
177 self.failUnless(len(change.AffectedFiles(include_deletes=False)) == 3) | 175 self.failUnless(len(change.AffectedFiles(include_deletes=False)) == 3) |
178 self.failUnless(len(change.AffectedFiles(include_dirs=True, | 176 self.failUnless(len(change.AffectedFiles(include_dirs=True, |
179 include_deletes=False)) == 4) | 177 include_deletes=False)) == 4) |
180 | 178 |
181 affected_text_files = change.AffectedTextFiles(include_deletes=True) | 179 affected_text_files = change.AffectedTextFiles(include_deletes=True) |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 # TODO(maruel): Add real tests. | 783 # TODO(maruel): Add real tests. |
786 self.failIf(presubmit_canned_checks.RunPythonUnitTests( | 784 self.failIf(presubmit_canned_checks.RunPythonUnitTests( |
787 self.MockInputApi(), | 785 self.MockInputApi(), |
788 presubmit.OutputApi, [])) | 786 presubmit.OutputApi, [])) |
789 self.failUnless(presubmit_canned_checks.RunPythonUnitTests( | 787 self.failUnless(presubmit_canned_checks.RunPythonUnitTests( |
790 self.MockInputApi(), | 788 self.MockInputApi(), |
791 presubmit.OutputApi, ['non_existent_module'])) | 789 presubmit.OutputApi, ['non_existent_module'])) |
792 | 790 |
793 if __name__ == '__main__': | 791 if __name__ == '__main__': |
794 unittest.main() | 792 unittest.main() |
OLD | NEW |