OLD | NEW |
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 """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: disable=E1101,E1103 | 8 # pylint: disable=E1101,E1103 |
9 | 9 |
10 import functools | 10 import functools |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 class PresubmitUnittest(PresubmitTestsBase): | 160 class PresubmitUnittest(PresubmitTestsBase): |
161 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" | 161 """General presubmit_support.py tests (excluding InputApi and OutputApi).""" |
162 | 162 |
163 _INHERIT_SETTINGS = 'inherit-review-settings-ok' | 163 _INHERIT_SETTINGS = 'inherit-review-settings-ok' |
164 | 164 |
165 def testMembersChanged(self): | 165 def testMembersChanged(self): |
166 self.mox.ReplayAll() | 166 self.mox.ReplayAll() |
167 members = [ | 167 members = [ |
168 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', | 168 'AffectedFile', 'Change', 'DoGetTrySlaves', 'DoPresubmitChecks', |
169 'GetTrySlavesExecuter', 'GitAffectedFile', 'CallCommand', 'CommandData', | 169 'GetTrySlavesExecuter', 'GitAffectedFile', 'CallCommand', 'CommandData', |
170 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'Main', | 170 'GitChange', 'InputApi', 'ListRelevantPresubmitFiles', 'main', |
171 'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles', | 171 'NonexistantCannedCheckFilter', 'OutputApi', 'ParseFiles', |
172 'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', | 172 'PresubmitFailure', 'PresubmitExecuter', 'PresubmitOutput', 'ScanSubDirs', |
173 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cpplint', 'cStringIO', | 173 'SvnAffectedFile', 'SvnChange', 'cPickle', 'cpplint', 'cStringIO', |
174 'contextlib', 'canned_check_filter', 'fix_encoding', 'fnmatch', | 174 'contextlib', 'canned_check_filter', 'fix_encoding', 'fnmatch', |
175 'gclient_utils', 'glob', 'inspect', 'json', 'load_files', 'logging', | 175 'gclient_utils', 'glob', 'inspect', 'json', 'load_files', 'logging', |
176 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', | 176 'marshal', 'normpath', 'optparse', 'os', 'owners', 'pickle', |
177 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', | 177 'presubmit_canned_checks', 'random', 're', 'rietveld', 'scm', |
178 'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', | 178 'subprocess', 'sys', 'tempfile', 'time', 'traceback', 'types', 'unittest', |
179 'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters', | 179 'urllib2', 'warn', 'multiprocessing', 'DoGetTryMasters', |
180 'GetTryMastersExecuter', 'itertools', | 180 'GetTryMastersExecuter', 'itertools', |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 output.should_continue().AndReturn(False) | 1145 output.should_continue().AndReturn(False) |
1146 | 1146 |
1147 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, | 1147 presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False, |
1148 mox.IgnoreArg(), | 1148 mox.IgnoreArg(), |
1149 mox.IgnoreArg(), | 1149 mox.IgnoreArg(), |
1150 None, False, None).AndReturn(output) | 1150 None, False, None).AndReturn(output) |
1151 self.mox.ReplayAll() | 1151 self.mox.ReplayAll() |
1152 | 1152 |
1153 self.assertEquals( | 1153 self.assertEquals( |
1154 True, | 1154 True, |
1155 presubmit.Main(['--root', self.fake_root_dir, 'random_file.txt'])) | 1155 presubmit.main(['--root', self.fake_root_dir, 'random_file.txt'])) |
1156 | 1156 |
1157 def testMainUnversionedFail(self): | 1157 def testMainUnversionedFail(self): |
1158 # OptParser calls presubmit.os.path.exists and is a pain when mocked. | 1158 # OptParser calls presubmit.os.path.exists and is a pain when mocked. |
1159 self.UnMock(presubmit.os.path, 'exists') | 1159 self.UnMock(presubmit.os.path, 'exists') |
1160 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') | 1160 self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks') |
1161 self.mox.StubOutWithMock(presubmit, 'ParseFiles') | 1161 self.mox.StubOutWithMock(presubmit, 'ParseFiles') |
1162 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) | 1162 presubmit.scm.determine_scm(self.fake_root_dir).AndReturn(None) |
1163 self.mox.StubOutWithMock(presubmit.sys, 'stderr') | 1163 self.mox.StubOutWithMock(presubmit.sys, 'stderr') |
1164 presubmit.sys.stderr.write( | 1164 presubmit.sys.stderr.write( |
1165 'Usage: presubmit_unittest.py [options] <files...>\n') | 1165 'Usage: presubmit_unittest.py [options] <files...>\n') |
1166 presubmit.sys.stderr.write('\n') | 1166 presubmit.sys.stderr.write('\n') |
1167 presubmit.sys.stderr.write( | 1167 presubmit.sys.stderr.write( |
1168 'presubmit_unittest.py: error: For unversioned directory, <files> is ' | 1168 'presubmit_unittest.py: error: For unversioned directory, <files> is ' |
1169 'not optional.\n') | 1169 'not optional.\n') |
1170 self.mox.ReplayAll() | 1170 self.mox.ReplayAll() |
1171 | 1171 |
1172 try: | 1172 try: |
1173 presubmit.Main(['--root', self.fake_root_dir]) | 1173 presubmit.main(['--root', self.fake_root_dir]) |
1174 self.fail() | 1174 self.fail() |
1175 except SystemExit, e: | 1175 except SystemExit, e: |
1176 self.assertEquals(2, e.code) | 1176 self.assertEquals(2, e.code) |
1177 | 1177 |
1178 | 1178 |
1179 class InputApiUnittest(PresubmitTestsBase): | 1179 class InputApiUnittest(PresubmitTestsBase): |
1180 """Tests presubmit.InputApi.""" | 1180 """Tests presubmit.InputApi.""" |
1181 def testMembersChanged(self): | 1181 def testMembersChanged(self): |
1182 self.mox.ReplayAll() | 1182 self.mox.ReplayAll() |
1183 members = [ | 1183 members = [ |
(...skipping 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2866 owners_check=False) | 2866 owners_check=False) |
2867 self.assertEqual(1, len(results)) | 2867 self.assertEqual(1, len(results)) |
2868 self.assertEqual( | 2868 self.assertEqual( |
2869 'Found line ending with white spaces in:', results[0]._message) | 2869 'Found line ending with white spaces in:', results[0]._message) |
2870 self.checkstdout('') | 2870 self.checkstdout('') |
2871 | 2871 |
2872 | 2872 |
2873 if __name__ == '__main__': | 2873 if __name__ == '__main__': |
2874 import unittest | 2874 import unittest |
2875 unittest.main() | 2875 unittest.main() |
OLD | NEW |