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 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 self.failIf(warning._Handle(output, input)) | 824 self.failIf(warning._Handle(output, input)) |
825 self.failUnless(output.getvalue().count('???')) | 825 self.failUnless(output.getvalue().count('???')) |
826 | 826 |
827 | 827 |
828 class AffectedFileUnittest(PresubmitTestsBase): | 828 class AffectedFileUnittest(PresubmitTestsBase): |
829 def testMembersChanged(self): | 829 def testMembersChanged(self): |
830 self.mox.ReplayAll() | 830 self.mox.ReplayAll() |
831 members = [ | 831 members = [ |
832 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath', | 832 'AbsoluteLocalPath', 'Action', 'IsDirectory', 'IsTextFile', 'LocalPath', |
833 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', | 833 'NewContents', 'OldContents', 'OldFileTempPath', 'Property', 'ServerPath', |
| 834 'scm', |
834 ] | 835 ] |
835 # If this test fails, you should add the relevant test. | 836 # If this test fails, you should add the relevant test. |
836 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) | 837 self.compareMembers(presubmit.AffectedFile('a', 'b'), members) |
837 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) | 838 self.compareMembers(presubmit.SvnAffectedFile('a', 'b'), members) |
838 | 839 |
839 def testAffectedFile(self): | 840 def testAffectedFile(self): |
840 path = presubmit.os.path.join('foo', 'blat.cc') | 841 path = presubmit.os.path.join('foo', 'blat.cc') |
841 presubmit.os.path.exists(path).AndReturn(True) | 842 presubmit.os.path.exists(path).AndReturn(True) |
842 presubmit.os.path.isdir(path).AndReturn(False) | 843 presubmit.os.path.isdir(path).AndReturn(False) |
843 presubmit.gcl.ReadFile(path).AndReturn('whatever\ncookie') | 844 presubmit.gcl.ReadFile(path).AndReturn('whatever\ncookie') |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 input_api.traceback = presubmit.traceback | 930 input_api.traceback = presubmit.traceback |
930 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) | 931 input_api.urllib2 = self.mox.CreateMock(presubmit.urllib2) |
931 input_api.unittest = unittest | 932 input_api.unittest = unittest |
932 return input_api | 933 return input_api |
933 | 934 |
934 def testMembersChanged(self): | 935 def testMembersChanged(self): |
935 self.mox.ReplayAll() | 936 self.mox.ReplayAll() |
936 members = [ | 937 members = [ |
937 'CheckChangeHasBugField', 'CheckChangeHasNoCR', 'CheckChangeHasNoTabs', | 938 'CheckChangeHasBugField', 'CheckChangeHasNoCR', 'CheckChangeHasNoTabs', |
938 'CheckChangeHasQaField', 'CheckChangeHasTestedField', | 939 'CheckChangeHasQaField', 'CheckChangeHasTestedField', |
939 'CheckChangeHasTestField', 'CheckDoNotSubmit', | 940 'CheckChangeHasTestField', 'CheckChangeSvnEolStyle', |
| 941 'CheckDoNotSubmit', |
940 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', | 942 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', |
941 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', | 943 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', |
942 ] | 944 ] |
943 # If this test fails, you should add the relevant test. | 945 # If this test fails, you should add the relevant test. |
944 self.compareMembers(presubmit_canned_checks, members) | 946 self.compareMembers(presubmit_canned_checks, members) |
945 | 947 |
946 def TestDescription(self, check, description1, description2, error_type): | 948 def TestDescription(self, check, description1, description2, error_type): |
947 input_api1 = self.MockInputApi() | 949 input_api1 = self.MockInputApi() |
948 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) | 950 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) |
949 input_api2 = self.MockInputApi() | 951 input_api2 = self.MockInputApi() |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 def testCannedCheckChangeHasNoTabs(self): | 1044 def testCannedCheckChangeHasNoTabs(self): |
1043 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, | 1045 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, |
1044 'blah blah', 'blah\tblah', | 1046 'blah blah', 'blah\tblah', |
1045 presubmit.OutputApi.PresubmitPromptWarning) | 1047 presubmit.OutputApi.PresubmitPromptWarning) |
1046 | 1048 |
1047 def testCannedCheckLongLines(self): | 1049 def testCannedCheckLongLines(self): |
1048 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) | 1050 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) |
1049 self.TestContent(check, '', 'blah blah blah', | 1051 self.TestContent(check, '', 'blah blah blah', |
1050 presubmit.OutputApi.PresubmitPromptWarning) | 1052 presubmit.OutputApi.PresubmitPromptWarning) |
1051 | 1053 |
| 1054 |
| 1055 def testCheckChangeSvnEolStyle(self): |
| 1056 input_api1 = self.MockInputApi() |
| 1057 files1 = [ |
| 1058 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1059 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1060 ] |
| 1061 input_api1.AffectedSourceFiles(None).AndReturn(files1) |
| 1062 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1063 'svn:eol-style').AndReturn('LF') |
| 1064 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1065 'svn:eol-style').AndReturn('LF') |
| 1066 input_api2 = self.MockInputApi() |
| 1067 files2 = [ |
| 1068 presubmit.SvnAffectedFile('foo/bar.cc', 'A'), |
| 1069 presubmit.SvnAffectedFile('foo.cc', 'M'), |
| 1070 ] |
| 1071 input_api2.AffectedSourceFiles(None).AndReturn(files2) |
| 1072 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo/bar.cc'), |
| 1073 'svn:eol-style').AndReturn('native') |
| 1074 presubmit.gcl.GetSVNFileProperty(presubmit.normpath('foo.cc'), |
| 1075 'svn:eol-style').AndReturn('CRLF') |
| 1076 self.mox.ReplayAll() |
| 1077 |
| 1078 results1 = presubmit_canned_checks.CheckChangeSvnEolStyle( |
| 1079 input_api1, presubmit.OutputApi, None) |
| 1080 self.assertEquals(results1, []) |
| 1081 results2 = presubmit_canned_checks.CheckChangeSvnEolStyle( |
| 1082 input_api2, presubmit.OutputApi, None) |
| 1083 self.assertEquals(len(results2), 1) |
| 1084 self.assertEquals(results2[0].__class__, presubmit.OutputApi.PresubmitError) |
| 1085 |
1052 def testCannedCheckTreeIsOpenOpen(self): | 1086 def testCannedCheckTreeIsOpenOpen(self): |
1053 input_api = self.MockInputApi() | 1087 input_api = self.MockInputApi() |
1054 input_api.is_committing = True | 1088 input_api.is_committing = True |
1055 connection = self.mox.CreateMockAnything() | 1089 connection = self.mox.CreateMockAnything() |
1056 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) | 1090 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) |
1057 connection.read().AndReturn('1') | 1091 connection.read().AndReturn('1') |
1058 connection.close() | 1092 connection.close() |
1059 self.mox.ReplayAll() | 1093 self.mox.ReplayAll() |
1060 results = presubmit_canned_checks.CheckTreeIsOpen( | 1094 results = presubmit_canned_checks.CheckTreeIsOpen( |
1061 input_api, presubmit.OutputApi, url='url_to_open', closed='0') | 1095 input_api, presubmit.OutputApi, url='url_to_open', closed='0') |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1197 test_result.errors = 0 | 1231 test_result.errors = 0 |
1198 self.mox.ReplayAll() | 1232 self.mox.ReplayAll() |
1199 | 1233 |
1200 results = presubmit_canned_checks.RunPythonUnitTests( | 1234 results = presubmit_canned_checks.RunPythonUnitTests( |
1201 input_api, presubmit.OutputApi, ['test_module']) | 1235 input_api, presubmit.OutputApi, ['test_module']) |
1202 self.assertEquals(len(results), 0) | 1236 self.assertEquals(len(results), 0) |
1203 | 1237 |
1204 | 1238 |
1205 if __name__ == '__main__': | 1239 if __name__ == '__main__': |
1206 unittest.main() | 1240 unittest.main() |
OLD | NEW |