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 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
930 input_api.cStringIO = presubmit.cStringIO | 930 input_api.cStringIO = presubmit.cStringIO |
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', 'CheckChangeHasNoCR', 'CheckChangeHasNoTabs', | 940 'CheckChangeHasBugField', 'CheckChangeHasDescription', |
| 941 'CheckChangeHasNoCR', 'CheckChangeHasNoTabs', |
941 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 942 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
942 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', | 943 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', |
943 'CheckDoNotSubmit', | 944 'CheckDoNotSubmit', |
944 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 945 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
945 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 946 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
946 ] | 947 ] |
947 # If this test fails, you should add the relevant test. | 948 # If this test fails, you should add the relevant test. |
948 self.compareMembers(presubmit_canned_checks, members) | 949 self.compareMembers(presubmit_canned_checks, members) |
949 | 950 |
950 def DescriptionTest(self, check, description1, description2, error_type): | 951 def DescriptionTest(self, check, description1, description2, error_type, |
| 952 committing): |
951 input_api1 = self.MockInputApi() | 953 input_api1 = self.MockInputApi() |
952 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) | 954 input_api1.is_committing = committing |
| 955 input_api1.change = self.MakeBasicChange('foo', description1) |
953 input_api2 = self.MockInputApi() | 956 input_api2 = self.MockInputApi() |
954 input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2) | 957 input_api2.is_committing = committing |
| 958 input_api2.change = self.MakeBasicChange('foo', description2) |
955 self.mox.ReplayAll() | 959 self.mox.ReplayAll() |
956 | 960 |
957 results1 = check(input_api1, presubmit.OutputApi) | 961 results1 = check(input_api1, presubmit.OutputApi) |
958 self.assertEquals(results1, []) | 962 self.assertEquals(results1, []) |
959 results2 = check(input_api2, presubmit.OutputApi) | 963 results2 = check(input_api2, presubmit.OutputApi) |
960 self.assertEquals(len(results2), 1) | 964 self.assertEquals(len(results2), 1) |
961 self.assertEquals(results2[0].__class__, error_type) | 965 self.assertEquals(results2[0].__class__, error_type) |
962 | 966 |
963 def ContentTest(self, check, content1, content2, error_type): | 967 def ContentTest(self, check, content1, content2, error_type): |
964 input_api1 = self.MockInputApi() | 968 input_api1 = self.MockInputApi() |
(...skipping 17 matching lines...) Expand all Loading... |
982 self.mox.ReplayAll() | 986 self.mox.ReplayAll() |
983 | 987 |
984 results1 = check(input_api1, presubmit.OutputApi, None) | 988 results1 = check(input_api1, presubmit.OutputApi, None) |
985 self.assertEquals(results1, []) | 989 self.assertEquals(results1, []) |
986 results2 = check(input_api2, presubmit.OutputApi, None) | 990 results2 = check(input_api2, presubmit.OutputApi, None) |
987 self.assertEquals(len(results2), 1) | 991 self.assertEquals(len(results2), 1) |
988 self.assertEquals(results2[0].__class__, error_type) | 992 self.assertEquals(results2[0].__class__, error_type) |
989 | 993 |
990 def testCannedCheckChangeHasBugField(self): | 994 def testCannedCheckChangeHasBugField(self): |
991 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, | 995 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, |
992 'BUG=1234', '', | 996 'Foo\nBUG=1234', 'Foo\n', |
993 presubmit.OutputApi.PresubmitNotifyResult) | 997 presubmit.OutputApi.PresubmitNotifyResult, |
| 998 False) |
994 | 999 |
| 1000 def testCheckChangeHasDescription(self): |
| 1001 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, |
| 1002 'Bleh', '', |
| 1003 presubmit.OutputApi.PresubmitNotifyResult, |
| 1004 False) |
| 1005 self.mox.VerifyAll() |
| 1006 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, |
| 1007 'Bleh', '', |
| 1008 presubmit.OutputApi.PresubmitError, |
| 1009 True) |
| 1010 |
995 def testCannedCheckChangeHasTestField(self): | 1011 def testCannedCheckChangeHasTestField(self): |
996 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField, | 1012 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField, |
997 'TEST=did some stuff', '', | 1013 'Foo\nTEST=did some stuff', 'Foo\n', |
998 presubmit.OutputApi.PresubmitNotifyResult) | 1014 presubmit.OutputApi.PresubmitNotifyResult, |
| 1015 False) |
999 | 1016 |
1000 def testCannedCheckChangeHasTestedField(self): | 1017 def testCannedCheckChangeHasTestedField(self): |
1001 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField, | 1018 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField, |
1002 'TESTED=did some stuff', '', | 1019 'Foo\nTESTED=did some stuff', 'Foo\n', |
1003 presubmit.OutputApi.PresubmitError) | 1020 presubmit.OutputApi.PresubmitError, |
| 1021 False) |
1004 | 1022 |
1005 def testCannedCheckChangeHasQAField(self): | 1023 def testCannedCheckChangeHasQAField(self): |
1006 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField, | 1024 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField, |
1007 'QA=BSOD your machine', '', | 1025 'Foo\nQA=BSOD your machine', 'Foo\n', |
1008 presubmit.OutputApi.PresubmitError) | 1026 presubmit.OutputApi.PresubmitError, |
| 1027 False) |
1009 | 1028 |
1010 def testCannedCheckDoNotSubmitInDescription(self): | 1029 def testCannedCheckDoNotSubmitInDescription(self): |
1011 self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription, | 1030 self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription, |
1012 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1031 'Foo\nDO NOTSUBMIT', 'Foo\nDO NOT ' + 'SUBMIT', |
1013 presubmit.OutputApi.PresubmitError) | 1032 presubmit.OutputApi.PresubmitError, |
| 1033 False) |
1014 | 1034 |
1015 def testCannedCheckDoNotSubmitInFiles(self): | 1035 def testCannedCheckDoNotSubmitInFiles(self): |
1016 self.ContentTest( | 1036 self.ContentTest( |
1017 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), | 1037 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), |
1018 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', | 1038 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', |
1019 presubmit.OutputApi.PresubmitError) | 1039 presubmit.OutputApi.PresubmitError) |
1020 | 1040 |
1021 def testCheckChangeHasNoCR(self): | 1041 def testCheckChangeHasNoCR(self): |
1022 input_api1 = self.MockInputApi() | 1042 input_api1 = self.MockInputApi() |
1023 self.mox.StubOutWithMock(input_api1, 'ReadFile') | 1043 self.mox.StubOutWithMock(input_api1, 'ReadFile') |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 test_result.errors = 0 | 1269 test_result.errors = 0 |
1250 self.mox.ReplayAll() | 1270 self.mox.ReplayAll() |
1251 | 1271 |
1252 results = presubmit_canned_checks.RunPythonUnitTests( | 1272 results = presubmit_canned_checks.RunPythonUnitTests( |
1253 input_api, presubmit.OutputApi, ['test_module']) | 1273 input_api, presubmit.OutputApi, ['test_module']) |
1254 self.assertEquals(len(results), 0) | 1274 self.assertEquals(len(results), 0) |
1255 | 1275 |
1256 | 1276 |
1257 if __name__ == '__main__': | 1277 if __name__ == '__main__': |
1258 unittest.main() | 1278 unittest.main() |
OLD | NEW |