| 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 StringIO | 10 import StringIO |
| (...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 self.fail() | 1183 self.fail() |
| 1184 except SystemExit, e: | 1184 except SystemExit, e: |
| 1185 self.assertEquals(2, e.code) | 1185 self.assertEquals(2, e.code) |
| 1186 | 1186 |
| 1187 | 1187 |
| 1188 class InputApiUnittest(PresubmitTestsBase): | 1188 class InputApiUnittest(PresubmitTestsBase): |
| 1189 """Tests presubmit.InputApi.""" | 1189 """Tests presubmit.InputApi.""" |
| 1190 def testMembersChanged(self): | 1190 def testMembersChanged(self): |
| 1191 self.mox.ReplayAll() | 1191 self.mox.ReplayAll() |
| 1192 members = [ | 1192 members = [ |
| 1193 'AbsoluteLocalPaths', 'AffectedFiles', 'AffectedSourceFiles', | 1193 'AbsoluteLocalPaths', |
| 1194 'AffectedTextFiles', 'DEFAULT_BLACK_LIST', 'DEFAULT_WHITE_LIST', | 1194 'AffectedFiles', |
| 1195 'DepotToLocalPath', 'FilterSourceFile', 'LocalPaths', 'LocalToDepotPath', | 1195 'AffectedSourceFiles', |
| 1196 'Command', 'RunTests', 'PresubmitLocalPath', 'ReadFile', | 1196 'AffectedTextFiles', |
| 1197 'RightHandSideLines', 'ServerPaths', 'basename', 'cPickle', 'cpplint', | 1197 'DEFAULT_BLACK_LIST', |
| 1198 'cStringIO', 'canned_checks', 'change', 'cpu_count', 'environ', 'glob', | 1198 'DEFAULT_WHITE_LIST', |
| 1199 'host_url', 'is_committing', 'json', 'logging', 'marshal', 'os_listdir', | 1199 'DepotToLocalPath', |
| 1200 'os_walk', 'os_path', 'os_stat', 'owners_db', 'pickle', 'platform', | 1200 'FilterSourceFile', |
| 1201 'python_executable', 're', 'rietveld', 'subprocess', 'tbr', 'tempfile', | 1201 'LocalPaths', |
| 1202 'time', 'traceback', 'unittest', 'urllib2', 'version', 'verbose', | 1202 'LocalToDepotPath', |
| 1203 'dry_run', 'gerrit', | 1203 'Command', |
| 1204 'RunTests', |
| 1205 'PresubmitLocalPath', |
| 1206 'ReadFile', |
| 1207 'RightHandSideLines', |
| 1208 'ServerPaths', |
| 1209 'basename', |
| 1210 'cPickle', |
| 1211 'cpplint', |
| 1212 'cStringIO', |
| 1213 'canned_checks', |
| 1214 'change', |
| 1215 'cpu_count', |
| 1216 'environ', |
| 1217 'fnmatch', |
| 1218 'glob', |
| 1219 'host_url', |
| 1220 'is_committing', |
| 1221 'json', |
| 1222 'logging', |
| 1223 'marshal', |
| 1224 'os_listdir', |
| 1225 'os_walk', |
| 1226 'os_path', |
| 1227 'os_stat', |
| 1228 'owners_db', |
| 1229 'pickle', |
| 1230 'platform', |
| 1231 'python_executable', |
| 1232 're', |
| 1233 'rietveld', |
| 1234 'subprocess', |
| 1235 'tbr', |
| 1236 'tempfile', |
| 1237 'time', |
| 1238 'traceback', |
| 1239 'unittest', |
| 1240 'urllib2', |
| 1241 'version', |
| 1242 'verbose', |
| 1243 'dry_run', |
| 1244 'gerrit', |
| 1204 ] | 1245 ] |
| 1205 # If this test fails, you should add the relevant test. | 1246 # If this test fails, you should add the relevant test. |
| 1206 self.compareMembers( | 1247 self.compareMembers( |
| 1207 presubmit.InputApi(self.fake_change, './.', False, None, False), | 1248 presubmit.InputApi(self.fake_change, './.', False, None, False), |
| 1208 members) | 1249 members) |
| 1209 | 1250 |
| 1210 def testDepotToLocalPath(self): | 1251 def testDepotToLocalPath(self): |
| 1211 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir | 1252 presubmit.scm.SVN._CaptureInfo(['svn://foo/smurf'], self.fake_root_dir |
| 1212 ).AndReturn({'Path': 'prout'}) | 1253 ).AndReturn({'Path': 'prout'}) |
| 1213 presubmit.scm.SVN._CaptureInfo( | 1254 presubmit.scm.SVN._CaptureInfo( |
| (...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2728 expected_output='') | 2769 expected_output='') |
| 2729 | 2770 |
| 2730 def testCannedCheckOwners_NoReviewers(self): | 2771 def testCannedCheckOwners_NoReviewers(self): |
| 2731 response = { | 2772 response = { |
| 2732 "owner_email": "john@example.com", | 2773 "owner_email": "john@example.com", |
| 2733 "messages": [ | 2774 "messages": [ |
| 2734 { | 2775 { |
| 2735 "sender": "ben@example.com", "text": "foo", "approval": False, | 2776 "sender": "ben@example.com", "text": "foo", "approval": False, |
| 2736 }, | 2777 }, |
| 2737 ], | 2778 ], |
| 2738 "reviewers":[], | 2779 "reviewers": [], |
| 2739 } | 2780 } |
| 2740 self.AssertOwnersWorks( | 2781 self.AssertOwnersWorks( |
| 2741 approvers=set(), | 2782 approvers=set(), |
| 2742 reviewers=set(), | 2783 reviewers=set(), |
| 2743 rietveld_response=response, | 2784 rietveld_response=response, |
| 2744 expected_output= | 2785 expected_output= |
| 2745 'Missing LGTM from someone other than john@example.com\n') | 2786 'Missing LGTM from someone other than john@example.com\n') |
| 2746 | 2787 |
| 2747 self.AssertOwnersWorks( | 2788 self.AssertOwnersWorks( |
| 2748 approvers=set(), | 2789 approvers=set(), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2923 owners_check=False) | 2964 owners_check=False) |
| 2924 self.assertEqual(2, len(results)) | 2965 self.assertEqual(2, len(results)) |
| 2925 self.assertEqual( | 2966 self.assertEqual( |
| 2926 'Found line ending with white spaces in:', results[0]._message) | 2967 'Found line ending with white spaces in:', results[0]._message) |
| 2927 self.checkstdout('') | 2968 self.checkstdout('') |
| 2928 | 2969 |
| 2929 | 2970 |
| 2930 if __name__ == '__main__': | 2971 if __name__ == '__main__': |
| 2931 import unittest | 2972 import unittest |
| 2932 unittest.main() | 2973 unittest.main() |
| OLD | NEW |