| 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 exceptions | 8 import exceptions |
| 9 import random | 9 import random |
| 10 import string | 10 import string |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 input_api.re = presubmit.re | 931 input_api.re = presubmit.re |
| 932 input_api.traceback = presubmit.traceback | 932 input_api.traceback = presubmit.traceback |
| 933 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) | 933 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) |
| 934 input_api.unittest = unittest | 934 input_api.unittest = unittest |
| 935 return input_api | 935 return input_api |
| 936 | 936 |
| 937 def testMembersChanged(self): | 937 def testMembersChanged(self): |
| 938 self.mox.ReplayAll() | 938 self.mox.ReplayAll() |
| 939 members = [ | 939 members = [ |
| 940 'CheckChangeHasBugField', 'CheckChangeHasDescription', | 940 'CheckChangeHasBugField', 'CheckChangeHasDescription', |
| 941 'CheckChangeHasNoStrayWhitespace', |
| 941 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', | 942 'CheckChangeHasOnlyOneEol', 'CheckChangeHasNoCR', |
| 942 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', | 943 'CheckChangeHasNoCrAndHasOnlyOneEol', 'CheckChangeHasNoTabs', |
| 943 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 944 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
| 944 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', | 945 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', |
| 945 'CheckDoNotSubmit', | 946 'CheckDoNotSubmit', |
| 946 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 947 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
| 947 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 948 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
| 948 ] | 949 ] |
| 949 # If this test fails, you should add the relevant test. | 950 # If this test fails, you should add the relevant test. |
| 950 self.compareMembers(presubmit_canned_checks, members) | 951 self.compareMembers(presubmit_canned_checks, members) |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 'Foo\nDO NOTSUBMIT', 'Foo\nDO NOT ' + 'SUBMIT', | 1087 'Foo\nDO NOTSUBMIT', 'Foo\nDO NOT ' + 'SUBMIT', |
| 1087 presubmit.OutputApi.PresubmitError, | 1088 presubmit.OutputApi.PresubmitError, |
| 1088 False) | 1089 False) |
| 1089 | 1090 |
| 1090 def testCannedCheckDoNotSubmitInFiles(self): | 1091 def testCannedCheckDoNotSubmitInFiles(self): |
| 1091 self.ContentTest( | 1092 self.ContentTest( |
| 1092 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), | 1093 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), |
| 1093 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1094 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', |
| 1094 presubmit.OutputApi.PresubmitError) | 1095 presubmit.OutputApi.PresubmitError) |
| 1095 | 1096 |
| 1097 def testCheckChangeHasNoStrayWhitespace(self): |
| 1098 self.ContentTest( |
| 1099 lambda x,y,z: |
| 1100 presubmit_canned_checks.CheckChangeHasNoStrayWhitespace(x, y), |
| 1101 'Foo', 'Foo ', |
| 1102 presubmit.OutputApi.PresubmitPromptWarning) |
| 1103 |
| 1104 |
| 1096 def testCheckChangeHasOnlyOneEol(self): | 1105 def testCheckChangeHasOnlyOneEol(self): |
| 1097 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, | 1106 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasOnlyOneEol, |
| 1098 "Hey!\nHo!\n", "Hey!\nHo!\n\n", | 1107 "Hey!\nHo!\n", "Hey!\nHo!\n\n", |
| 1099 presubmit.OutputApi.PresubmitPromptWarning) | 1108 presubmit.OutputApi.PresubmitPromptWarning) |
| 1100 | 1109 |
| 1101 def testCheckChangeHasNoCR(self): | 1110 def testCheckChangeHasNoCR(self): |
| 1102 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, | 1111 self.ReadFileTest(presubmit_canned_checks.CheckChangeHasNoCR, |
| 1103 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", | 1112 "Hey!\nHo!\n", "Hey!\r\nHo!\r\n", |
| 1104 presubmit.OutputApi.PresubmitPromptWarning) | 1113 presubmit.OutputApi.PresubmitPromptWarning) |
| 1105 | 1114 |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 test_result.errors = 0 | 1307 test_result.errors = 0 |
| 1299 self.mox.ReplayAll() | 1308 self.mox.ReplayAll() |
| 1300 | 1309 |
| 1301 results = presubmit_canned_checks.RunPythonUnitTests( | 1310 results = presubmit_canned_checks.RunPythonUnitTests( |
| 1302 input_api, presubmit.OutputApi, ['test_module']) | 1311 input_api, presubmit.OutputApi, ['test_module']) |
| 1303 self.assertEquals(len(results), 0) | 1312 self.assertEquals(len(results), 0) |
| 1304 | 1313 |
| 1305 | 1314 |
| 1306 if __name__ == '__main__': | 1315 if __name__ == '__main__': |
| 1307 unittest.main() | 1316 unittest.main() |
| OLD | NEW |