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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) | 1006 input_api2.AffectedSourceFiles(None).AndReturn([affected_file2]) |
1007 input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2) | 1007 input_api2.ReadFile(affected_file2, 'rb').AndReturn(content2) |
1008 affected_file2.LocalPath().AndReturn('bar.cc') | 1008 affected_file2.LocalPath().AndReturn('bar.cc') |
1009 self.mox.ReplayAll() | 1009 self.mox.ReplayAll() |
1010 | 1010 |
1011 results = check(input_api1, presubmit.OutputApi) | 1011 results = check(input_api1, presubmit.OutputApi) |
1012 self.assertEquals(results, []) | 1012 self.assertEquals(results, []) |
1013 results2 = check(input_api2, presubmit.OutputApi) | 1013 results2 = check(input_api2, presubmit.OutputApi) |
1014 self.assertEquals(len(results2), 1) | 1014 self.assertEquals(len(results2), 1) |
1015 self.assertEquals(results2[0].__class__, error_type) | 1015 self.assertEquals(results2[0].__class__, error_type) |
1016 | 1016 |
| 1017 def SvnPropertyTest(self, check, property, value1, value2, committing, |
| 1018 error_type): |
| 1019 input_api1 = self.MockInputApi() |
| 1020 input_api1.is_committing = committing |
| 1021 files1 = [ |
| 1022 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1023 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1024 ] |
| 1025 input_api1.AffectedSourceFiles(None).AndReturn(files1) |
| 1026 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1027 property).AndReturn(value1) |
| 1028 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1029 property).AndReturn(value1) |
| 1030 input_api2 = self.MockInputApi() |
| 1031 input_api2.is_committing = committing |
| 1032 files2 = [ |
| 1033 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1034 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1035 ] |
| 1036 input_api2.AffectedSourceFiles(None).AndReturn(files2) |
| 1037 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1038 property).AndReturn(value2) |
| 1039 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1040 property).AndReturn(value2) |
| 1041 self.mox.ReplayAll() |
| 1042 |
| 1043 results1 = check(input_api1, presubmit.OutputApi, None) |
| 1044 self.assertEquals(results1, []) |
| 1045 results2 = check(input_api2, presubmit.OutputApi, None) |
| 1046 self.assertEquals(len(results2), 1) |
| 1047 self.assertEquals(results2[0].__class__, error_type) |
| 1048 |
1017 def testCannedCheckChangeHasBugField(self): | 1049 def testCannedCheckChangeHasBugField(self): |
1018 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, | 1050 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField, |
1019 'Foo\nBUG=1234', 'Foo\n', | 1051 'Foo\nBUG=1234', 'Foo\n', |
1020 presubmit.OutputApi.PresubmitNotifyResult, | 1052 presubmit.OutputApi.PresubmitNotifyResult, |
1021 False) | 1053 False) |
1022 | 1054 |
1023 def testCheckChangeHasDescription(self): | 1055 def testCheckChangeHasDescription(self): |
1024 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, | 1056 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasDescription, |
1025 'Bleh', '', | 1057 'Bleh', '', |
1026 presubmit.OutputApi.PresubmitNotifyResult, | 1058 presubmit.OutputApi.PresubmitNotifyResult, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 def testCannedCheckChangeHasNoTabs(self): | 1117 def testCannedCheckChangeHasNoTabs(self): |
1086 self.ContentTest(presubmit_canned_checks.CheckChangeHasNoTabs, | 1118 self.ContentTest(presubmit_canned_checks.CheckChangeHasNoTabs, |
1087 'blah blah', 'blah\tblah', | 1119 'blah blah', 'blah\tblah', |
1088 presubmit.OutputApi.PresubmitPromptWarning) | 1120 presubmit.OutputApi.PresubmitPromptWarning) |
1089 | 1121 |
1090 def testCannedCheckLongLines(self): | 1122 def testCannedCheckLongLines(self): |
1091 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) | 1123 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) |
1092 self.ContentTest(check, '', 'blah blah blah', | 1124 self.ContentTest(check, '', 'blah blah blah', |
1093 presubmit.OutputApi.PresubmitPromptWarning) | 1125 presubmit.OutputApi.PresubmitPromptWarning) |
1094 | 1126 |
| 1127 def testCheckChangeSvnEolStyleCommit(self): |
| 1128 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
| 1129 'svn:eol-style', 'LF', '', True, |
| 1130 presubmit.OutputApi.PresubmitError) |
1095 | 1131 |
1096 def testCheckChangeSvnEolStyle(self): | 1132 def testCheckChangeSvnEolStyleUpload(self): |
1097 input_api1 = self.MockInputApi() | 1133 self.SvnPropertyTest(presubmit_canned_checks.CheckChangeSvnEolStyle, |
1098 files1 = [ | 1134 'svn:eol-style', 'LF', '', False, |
1099 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | 1135 presubmit.OutputApi.PresubmitNotifyResult) |
1100 presubmit.SvnAffectedFile('foo.cc', 'M'), | |
1101 ] | |
1102 input_api1.AffectedSourceFiles(None).AndReturn(files1) | |
1103 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), | |
1104 'svn:eol-style').AndReturn('LF') | |
1105 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), | |
1106 'svn:eol-style').AndReturn('LF') | |
1107 input_api2 = self.MockInputApi() | |
1108 files2 = [ | |
1109 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), | |
1110 presubmit.SvnAffectedFile('foo.cc', 'M'), | |
1111 ] | |
1112 input_api2.AffectedSourceFiles(None).AndReturn(files2) | |
1113 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), | |
1114 'svn:eol-style').AndReturn('native') | |
1115 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), | |
1116 'svn:eol-style').AndReturn('CRLF') | |
1117 self.mox.ReplayAll() | |
1118 | |
1119 results1 = presubmit_canned_checks.CheckChangeSvnEolStyle( | |
1120 input_api1, presubmit.OutputApi, None) | |
1121 self.assertEquals(results1, []) | |
1122 results2 = presubmit_canned_checks.CheckChangeSvnEolStyle( | |
1123 input_api2, presubmit.OutputApi, None) | |
1124 self.assertEquals(len(results2), 1) | |
1125 self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError) | |
1126 | 1136 |
1127 def testCannedCheckTreeIsOpenOpen(self): | 1137 def testCannedCheckTreeIsOpenOpen(self): |
1128 input_api = self.MockInputApi() | 1138 input_api = self.MockInputApi() |
1129 input_api.is_committing = True | 1139 input_api.is_committing = True |
1130 connection = self.mox.CreateMockAnything() | 1140 connection = self.mox.CreateMockAnything() |
1131 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 1141 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
1132 connection.read().AndReturn('1') | 1142 connection.read().AndReturn('1') |
1133 connection.close() | 1143 connection.close() |
1134 self.mox.ReplayAll() | 1144 self.mox.ReplayAll() |
1135 results = presubmit_canned_checks.CheckTreeIsOpen( | 1145 results = presubmit_canned_checks.CheckTreeIsOpen( |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 test_result.errors = 0 | 1298 test_result.errors = 0 |
1289 self.mox.ReplayAll() | 1299 self.mox.ReplayAll() |
1290 | 1300 |
1291 results = presubmit_canned_checks.RunPythonUnitTests( | 1301 results = presubmit_canned_checks.RunPythonUnitTests( |
1292 input_api, presubmit.OutputApi, ['test_module']) | 1302 input_api, presubmit.OutputApi, ['test_module']) |
1293 self.assertEquals(len(results), 0) | 1303 self.assertEquals(len(results), 0) |
1294 | 1304 |
1295 | 1305 |
1296 if __name__ == '__main__': | 1306 if __name__ == '__main__': |
1297 unittest.main() | 1307 unittest.main() |
OLD | NEW |