Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(280)

Side by Side Diff: tests/presubmit_unittest.py

Issue 118415: Fixes RunPythonUnitTests output. (Closed)
Patch Set: merge to trunk Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 class CannedChecksUnittest(PresubmitTestsBase): 918 class CannedChecksUnittest(PresubmitTestsBase):
919 """Tests presubmit_canned_checks.py.""" 919 """Tests presubmit_canned_checks.py."""
920 920
921 def setUp(self): 921 def setUp(self):
922 PresubmitTestsBase.setUp(self) 922 PresubmitTestsBase.setUp(self)
923 self.mox.StubOutWithMock(presubmit_canned_checks, 923 self.mox.StubOutWithMock(presubmit_canned_checks,
924 '_RunPythonUnitTests_LoadTests') 924 '_RunPythonUnitTests_LoadTests')
925 925
926 def MockInputApi(self): 926 def MockInputApi(self):
927 input_api = self.mox.CreateMock(presubmit.InputApi) 927 input_api = self.mox.CreateMock(presubmit.InputApi)
928 input_api.cStringIO = presubmit.cStringIO
928 input_api.re = presubmit.re 929 input_api.re = presubmit.re
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', 'CheckDoNotSubmit',
940 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles', 941 'CheckDoNotSubmitInDescription', 'CheckDoNotSubmitInFiles',
941 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests', 942 'CheckLongLines', 'CheckTreeIsOpen', 'RunPythonUnitTests',
942 ] 943 ]
943 # If this test fails, you should add the relevant test. 944 # If this test fails, you should add the relevant test.
944 self.compareMembers(presubmit_canned_checks, members) 945 self.compareMembers(presubmit_canned_checks, members)
945 946
946 def TestDescription(self, check, description1, description2, error_type): 947 def DescriptionTest(self, check, description1, description2, error_type):
947 input_api1 = self.MockInputApi() 948 input_api1 = self.MockInputApi()
948 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1) 949 input_api1.change = self.MakeBasicChange('foo', 'Foo\n' + description1)
949 input_api2 = self.MockInputApi() 950 input_api2 = self.MockInputApi()
950 input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2) 951 input_api2.change = self.MakeBasicChange('foo', 'Foo\n' + description2)
951 self.mox.ReplayAll() 952 self.mox.ReplayAll()
952 953
953 results1 = check(input_api1, presubmit.OutputApi) 954 results1 = check(input_api1, presubmit.OutputApi)
954 self.assertEquals(results1, []) 955 self.assertEquals(results1, [])
955 results2 = check(input_api2, presubmit.OutputApi) 956 results2 = check(input_api2, presubmit.OutputApi)
956 self.assertEquals(len(results2), 1) 957 self.assertEquals(len(results2), 1)
957 self.assertEquals(results2[0].__class__, error_type) 958 self.assertEquals(results2[0].__class__, error_type)
958 959
959 def TestContent(self, check, content1, content2, error_type): 960 def ContentTest(self, check, content1, content2, error_type):
960 input_api1 = self.MockInputApi() 961 input_api1 = self.MockInputApi()
961 input_api1.change = self.MakeBasicChange('foo', 'Foo\n') 962 input_api1.change = self.MakeBasicChange('foo', 'Foo\n')
962 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile) 963 affected_file = self.mox.CreateMock(presubmit.SvnAffectedFile)
963 affected_file.LocalPath().AndReturn('foo.cc') 964 affected_file.LocalPath().AndReturn('foo.cc')
964 output1 = [ 965 output1 = [
965 (affected_file, 42, 'yo, ' + content1), 966 (affected_file, 42, 'yo, ' + content1),
966 (affected_file, 43, 'yer'), 967 (affected_file, 43, 'yer'),
967 (affected_file, 23, 'ya'), 968 (affected_file, 23, 'ya'),
968 ] 969 ]
969 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1) 970 input_api1.RightHandSideLines(mox.IgnoreArg()).AndReturn(output1)
970 input_api2 = self.MockInputApi() 971 input_api2 = self.MockInputApi()
971 input_api2.change = self.MakeBasicChange('foo', 'Foo\n') 972 input_api2.change = self.MakeBasicChange('foo', 'Foo\n')
972 output2 = [ 973 output2 = [
973 (affected_file, 42, 'yo, ' + content2), 974 (affected_file, 42, 'yo, ' + content2),
974 (affected_file, 43, 'yer'), 975 (affected_file, 43, 'yer'),
975 (affected_file, 23, 'ya'), 976 (affected_file, 23, 'ya'),
976 ] 977 ]
977 input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2) 978 input_api2.RightHandSideLines(mox.IgnoreArg()).AndReturn(output2)
978 self.mox.ReplayAll() 979 self.mox.ReplayAll()
979 980
980 results1 = check(input_api1, presubmit.OutputApi, None) 981 results1 = check(input_api1, presubmit.OutputApi, None)
981 self.assertEquals(results1, []) 982 self.assertEquals(results1, [])
982 results2 = check(input_api2, presubmit.OutputApi, None) 983 results2 = check(input_api2, presubmit.OutputApi, None)
983 self.assertEquals(len(results2), 1) 984 self.assertEquals(len(results2), 1)
984 self.assertEquals(results2[0].__class__, error_type) 985 self.assertEquals(results2[0].__class__, error_type)
985 986
986 def testCannedCheckChangeHasBugField(self): 987 def testCannedCheckChangeHasBugField(self):
987 self.TestDescription(presubmit_canned_checks.CheckChangeHasBugField, 988 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasBugField,
988 'BUG=1234', '', 989 'BUG=1234', '',
989 presubmit.OutputApi.PresubmitNotifyResult) 990 presubmit.OutputApi.PresubmitNotifyResult)
990 991
991 def testCannedCheckChangeHasTestField(self): 992 def testCannedCheckChangeHasTestField(self):
992 self.TestDescription(presubmit_canned_checks.CheckChangeHasTestField, 993 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestField,
993 'TEST=did some stuff', '', 994 'TEST=did some stuff', '',
994 presubmit.OutputApi.PresubmitNotifyResult) 995 presubmit.OutputApi.PresubmitNotifyResult)
995 996
996 def testCannedCheckChangeHasTestedField(self): 997 def testCannedCheckChangeHasTestedField(self):
997 self.TestDescription(presubmit_canned_checks.CheckChangeHasTestedField, 998 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasTestedField,
998 'TESTED=did some stuff', '', 999 'TESTED=did some stuff', '',
999 presubmit.OutputApi.PresubmitError) 1000 presubmit.OutputApi.PresubmitError)
1000 1001
1001 def testCannedCheckChangeHasQAField(self): 1002 def testCannedCheckChangeHasQAField(self):
1002 self.TestDescription(presubmit_canned_checks.CheckChangeHasQaField, 1003 self.DescriptionTest(presubmit_canned_checks.CheckChangeHasQaField,
1003 'QA=BSOD your machine', '', 1004 'QA=BSOD your machine', '',
1004 presubmit.OutputApi.PresubmitError) 1005 presubmit.OutputApi.PresubmitError)
1005 1006
1006 def testCannedCheckDoNotSubmitInDescription(self): 1007 def testCannedCheckDoNotSubmitInDescription(self):
1007 self.TestDescription(presubmit_canned_checks.CheckDoNotSubmitInDescription, 1008 self.DescriptionTest(presubmit_canned_checks.CheckDoNotSubmitInDescription,
1008 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', 1009 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT',
1009 presubmit.OutputApi.PresubmitError) 1010 presubmit.OutputApi.PresubmitError)
1010 1011
1011 def testCannedCheckDoNotSubmitInFiles(self): 1012 def testCannedCheckDoNotSubmitInFiles(self):
1012 self.TestContent( 1013 self.ContentTest(
1013 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y), 1014 lambda x,y,z: presubmit_canned_checks.CheckDoNotSubmitInFiles(x, y),
1014 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT', 1015 'DO NOTSUBMIT', 'DO NOT ' + 'SUBMIT',
1015 presubmit.OutputApi.PresubmitError) 1016 presubmit.OutputApi.PresubmitError)
1016 1017
1017 def testCheckChangeHasNoCR(self): 1018 def testCheckChangeHasNoCR(self):
1018 input_api1 = self.MockInputApi() 1019 input_api1 = self.MockInputApi()
1019 self.mox.StubOutWithMock(input_api1, 'ReadFile') 1020 self.mox.StubOutWithMock(input_api1, 'ReadFile')
1020 input_api1.change = self.MakeBasicChange('foo', 'Foo\n') 1021 input_api1.change = self.MakeBasicChange('foo', 'Foo\n')
1021 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile) 1022 affected_file1 = self.mox.CreateMock(presubmit.SvnAffectedFile)
1022 input_api1.AffectedSourceFiles(None).AndReturn([affected_file1]) 1023 input_api1.AffectedSourceFiles(None).AndReturn([affected_file1])
(...skipping 10 matching lines...) Expand all
1033 results = presubmit_canned_checks.CheckChangeHasNoCR( 1034 results = presubmit_canned_checks.CheckChangeHasNoCR(
1034 input_api1, presubmit.OutputApi, None) 1035 input_api1, presubmit.OutputApi, None)
1035 self.assertEquals(results, []) 1036 self.assertEquals(results, [])
1036 results2 = presubmit_canned_checks.CheckChangeHasNoCR( 1037 results2 = presubmit_canned_checks.CheckChangeHasNoCR(
1037 input_api2, presubmit.OutputApi, None) 1038 input_api2, presubmit.OutputApi, None)
1038 self.assertEquals(len(results2), 1) 1039 self.assertEquals(len(results2), 1)
1039 self.assertEquals(results2[0].__class__, 1040 self.assertEquals(results2[0].__class__,
1040 presubmit.OutputApi.PresubmitPromptWarning) 1041 presubmit.OutputApi.PresubmitPromptWarning)
1041 1042
1042 def testCannedCheckChangeHasNoTabs(self): 1043 def testCannedCheckChangeHasNoTabs(self):
1043 self.TestContent(presubmit_canned_checks.CheckChangeHasNoTabs, 1044 self.ContentTest(presubmit_canned_checks.CheckChangeHasNoTabs,
1044 'blah blah', 'blah\tblah', 1045 'blah blah', 'blah\tblah',
1045 presubmit.OutputApi.PresubmitPromptWarning) 1046 presubmit.OutputApi.PresubmitPromptWarning)
1046 1047
1047 def testCannedCheckLongLines(self): 1048 def testCannedCheckLongLines(self):
1048 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z) 1049 check = lambda x,y,z: presubmit_canned_checks.CheckLongLines(x, y, 10, z)
1049 self.TestContent(check, '', 'blah blah blah', 1050 self.ContentTest(check, '', 'blah blah blah',
1050 presubmit.OutputApi.PresubmitPromptWarning) 1051 presubmit.OutputApi.PresubmitPromptWarning)
1051 1052
1052 def testCannedCheckTreeIsOpenOpen(self): 1053 def testCannedCheckTreeIsOpenOpen(self):
1053 input_api = self.MockInputApi() 1054 input_api = self.MockInputApi()
1054 input_api.is_committing = True 1055 input_api.is_committing = True
1055 connection = self.mox.CreateMockAnything() 1056 connection = self.mox.CreateMockAnything()
1056 input_api.urllib2.urlopen('url_to_open').AndReturn(connection) 1057 input_api.urllib2.urlopen('url_to_open').AndReturn(connection)
1057 connection.read().AndReturn('1') 1058 connection.read().AndReturn('1')
1058 connection.close() 1059 connection.close()
1059 self.mox.ReplayAll() 1060 self.mox.ReplayAll()
(...skipping 16 matching lines...) Expand all
1076 presubmit.OutputApi.PresubmitPromptWarning) 1077 presubmit.OutputApi.PresubmitPromptWarning)
1077 1078
1078 def testRunPythonUnitTestsNoTest(self): 1079 def testRunPythonUnitTestsNoTest(self):
1079 input_api = self.MockInputApi() 1080 input_api = self.MockInputApi()
1080 input_api.is_committing = False 1081 input_api.is_committing = False
1081 self.mox.ReplayAll() 1082 self.mox.ReplayAll()
1082 results = presubmit_canned_checks.RunPythonUnitTests( 1083 results = presubmit_canned_checks.RunPythonUnitTests(
1083 input_api, presubmit.OutputApi, []) 1084 input_api, presubmit.OutputApi, [])
1084 self.assertEquals(results, []) 1085 self.assertEquals(results, [])
1085 1086
1086 def testRunPythonUnitTestsNonExistent1(self): 1087 def testRunPythonUnitTestsNonExistentUpload(self):
1087 input_api = self.MockInputApi() 1088 input_api = self.MockInputApi()
1088 input_api.is_committing = False 1089 input_api.is_committing = False
1089 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1090 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1090 input_api, '_non_existent_module').AndRaise( 1091 input_api, '_non_existent_module').AndRaise(
1091 exceptions.ImportError('Blehh')) 1092 exceptions.ImportError('Blehh'))
1092 self.mox.ReplayAll() 1093 self.mox.ReplayAll()
1093 results = presubmit_canned_checks.RunPythonUnitTests( 1094 results = presubmit_canned_checks.RunPythonUnitTests(
1094 input_api, presubmit.OutputApi, ['_non_existent_module']) 1095 input_api, presubmit.OutputApi, ['_non_existent_module'])
1095 self.assertEquals(len(results), 1) 1096 self.assertEquals(len(results), 1)
1096 self.assertEquals(results[0].__class__, 1097 self.assertEquals(results[0].__class__,
1097 presubmit.OutputApi.PresubmitNotifyResult) 1098 presubmit.OutputApi.PresubmitNotifyResult)
1098 1099
1099 def testRunPythonUnitTestsNonExistent2(self): 1100 def testRunPythonUnitTestsNonExistentCommitting(self):
1100 input_api = self.MockInputApi() 1101 input_api = self.MockInputApi()
1101 input_api.is_committing = True 1102 input_api.is_committing = True
1102 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1103 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1103 input_api, '_non_existent_module').AndRaise( 1104 input_api, '_non_existent_module').AndRaise(
1104 exceptions.ImportError('Blehh')) 1105 exceptions.ImportError('Blehh'))
1105 self.mox.ReplayAll() 1106 self.mox.ReplayAll()
1106 results = presubmit_canned_checks.RunPythonUnitTests( 1107 results = presubmit_canned_checks.RunPythonUnitTests(
1107 input_api, presubmit.OutputApi, ['_non_existent_module']) 1108 input_api, presubmit.OutputApi, ['_non_existent_module'])
1108 self.assertEquals(len(results), 1) 1109 self.assertEquals(len(results), 1)
1109 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 1110 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
1110 1111
1111 def testRunPythonUnitTestsEmpty1(self): 1112 def testRunPythonUnitTestsEmptyUpload(self):
1112 input_api = self.MockInputApi() 1113 input_api = self.MockInputApi()
1113 input_api.is_committing = False 1114 input_api.is_committing = False
1114 test_module = self.mox.CreateMockAnything() 1115 test_module = self.mox.CreateMockAnything()
1115 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1116 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1116 input_api, 'test_module').AndReturn([]) 1117 input_api, 'test_module').AndReturn([])
1117 self.mox.ReplayAll() 1118 self.mox.ReplayAll()
1118 1119
1119 results = presubmit_canned_checks.RunPythonUnitTests( 1120 results = presubmit_canned_checks.RunPythonUnitTests(
1120 input_api, presubmit.OutputApi, ['test_module']) 1121 input_api, presubmit.OutputApi, ['test_module'])
1121 self.assertEquals(results, []) 1122 self.assertEquals(results, [])
1122 1123
1123 def testRunPythonUnitTestsEmpty2(self): 1124 def testRunPythonUnitTestsEmptyCommitting(self):
1124 input_api = self.MockInputApi() 1125 input_api = self.MockInputApi()
1125 input_api.is_committing = True 1126 input_api.is_committing = True
1126 test_module = self.mox.CreateMockAnything() 1127 test_module = self.mox.CreateMockAnything()
1127 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1128 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1128 input_api, 'test_module').AndReturn([]) 1129 input_api, 'test_module').AndReturn([])
1129 self.mox.ReplayAll() 1130 self.mox.ReplayAll()
1130 1131
1131 results = presubmit_canned_checks.RunPythonUnitTests( 1132 results = presubmit_canned_checks.RunPythonUnitTests(
1132 input_api, presubmit.OutputApi, ['test_module']) 1133 input_api, presubmit.OutputApi, ['test_module'])
1133 self.assertEquals(results, []) 1134 self.assertEquals(results, [])
1134 1135
1135 def testRunPythonUnitTestsFailure1(self): 1136 def testRunPythonUnitTestsFailureUpload(self):
1136 input_api = self.MockInputApi() 1137 input_api = self.MockInputApi()
1137 input_api.is_committing = False 1138 input_api.is_committing = False
1138 input_api.unittest = self.mox.CreateMock(unittest) 1139 input_api.unittest = self.mox.CreateMock(unittest)
1140 input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
1139 test = self.mox.CreateMockAnything() 1141 test = self.mox.CreateMockAnything()
1140 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1142 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1141 input_api, 'test_module').AndReturn([test]) 1143 input_api, 'test_module').AndReturn([test])
1142 runner = self.mox.CreateMockAnything() 1144 runner = self.mox.CreateMockAnything()
1143 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1145 buffer = self.mox.CreateMockAnything()
1146 input_api.cStringIO.StringIO().AndReturn(buffer)
1147 buffer.getvalue().AndReturn('BOO HOO!')
1148 input_api.unittest.TextTestRunner(stream=buffer, verbosity=0
1149 ).AndReturn(runner)
1144 suite = self.mox.CreateMockAnything() 1150 suite = self.mox.CreateMockAnything()
1145 input_api.unittest.TestSuite([test]).AndReturn(suite) 1151 input_api.unittest.TestSuite([test]).AndReturn(suite)
1146 test_result = self.mox.CreateMockAnything() 1152 test_result = self.mox.CreateMockAnything()
1147 runner.run(suite).AndReturn(test_result) 1153 runner.run(suite).AndReturn(test_result)
1148 test_result.wasSuccessful().AndReturn(False) 1154 test_result.wasSuccessful().AndReturn(False)
1149 test_result.failures = [None, None] 1155 test_result.failures = [None, None]
1150 test_result.errors = [None, None, None] 1156 test_result.errors = [None, None, None]
1151 self.mox.ReplayAll() 1157 self.mox.ReplayAll()
1152 1158
1153 results = presubmit_canned_checks.RunPythonUnitTests( 1159 results = presubmit_canned_checks.RunPythonUnitTests(
1154 input_api, presubmit.OutputApi, ['test_module']) 1160 input_api, presubmit.OutputApi, ['test_module'])
1155 self.assertEquals(len(results), 1) 1161 self.assertEquals(len(results), 1)
1156 self.assertEquals(results[0].__class__, 1162 self.assertEquals(results[0].__class__,
1157 presubmit.OutputApi.PresubmitNotifyResult) 1163 presubmit.OutputApi.PresubmitNotifyResult)
1164 self.assertEquals(results[0]._long_text, 'BOO HOO!')
1158 1165
1159 def testRunPythonUnitTestsFailure2(self): 1166 def testRunPythonUnitTestsFailureCommitting(self):
1160 input_api = self.MockInputApi() 1167 input_api = self.MockInputApi()
1161 input_api.is_committing = True 1168 input_api.is_committing = True
1162 input_api.unittest = self.mox.CreateMock(unittest) 1169 input_api.unittest = self.mox.CreateMock(unittest)
1170 input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
1163 test = self.mox.CreateMockAnything() 1171 test = self.mox.CreateMockAnything()
1164 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1172 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1165 input_api, 'test_module').AndReturn([test]) 1173 input_api, 'test_module').AndReturn([test])
1166 runner = self.mox.CreateMockAnything() 1174 runner = self.mox.CreateMockAnything()
1167 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1175 buffer = self.mox.CreateMockAnything()
1176 input_api.cStringIO.StringIO().AndReturn(buffer)
1177 buffer.getvalue().AndReturn('BOO HOO!')
1178 input_api.unittest.TextTestRunner(stream=buffer, verbosity=0
1179 ).AndReturn(runner)
1168 suite = self.mox.CreateMockAnything() 1180 suite = self.mox.CreateMockAnything()
1169 input_api.unittest.TestSuite([test]).AndReturn(suite) 1181 input_api.unittest.TestSuite([test]).AndReturn(suite)
1170 test_result = self.mox.CreateMockAnything() 1182 test_result = self.mox.CreateMockAnything()
1171 runner.run(suite).AndReturn(test_result) 1183 runner.run(suite).AndReturn(test_result)
1172 test_result.wasSuccessful().AndReturn(False) 1184 test_result.wasSuccessful().AndReturn(False)
1173 test_result.failures = [None, None] 1185 test_result.failures = [None, None]
1174 test_result.errors = [None, None, None] 1186 test_result.errors = [None, None, None]
1175 self.mox.ReplayAll() 1187 self.mox.ReplayAll()
1176 1188
1177 results = presubmit_canned_checks.RunPythonUnitTests( 1189 results = presubmit_canned_checks.RunPythonUnitTests(
1178 input_api, presubmit.OutputApi, ['test_module']) 1190 input_api, presubmit.OutputApi, ['test_module'])
1179 self.assertEquals(len(results), 1) 1191 self.assertEquals(len(results), 1)
1180 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 1192 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
1193 self.assertEquals(results[0]._long_text, 'BOO HOO!')
1181 1194
1182 def testRunPythonUnitTestsSuccess(self): 1195 def testRunPythonUnitTestsSuccess(self):
1183 input_api = self.MockInputApi() 1196 input_api = self.MockInputApi()
1184 input_api.is_committing = False 1197 input_api.is_committing = False
1185 input_api.unittest = self.mox.CreateMock(unittest) 1198 input_api.unittest = self.mox.CreateMock(unittest)
1199 input_api.cStringIO = self.mox.CreateMock(presubmit.cStringIO)
1186 test = self.mox.CreateMockAnything() 1200 test = self.mox.CreateMockAnything()
1187 presubmit_canned_checks._RunPythonUnitTests_LoadTests( 1201 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1188 input_api, 'test_module').AndReturn([test]) 1202 input_api, 'test_module').AndReturn([test])
1189 runner = self.mox.CreateMockAnything() 1203 runner = self.mox.CreateMockAnything()
1190 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1204 buffer = self.mox.CreateMockAnything()
1205 input_api.cStringIO.StringIO().AndReturn(buffer)
1206 input_api.unittest.TextTestRunner(stream=buffer, verbosity=0
1207 ).AndReturn(runner)
1191 suite = self.mox.CreateMockAnything() 1208 suite = self.mox.CreateMockAnything()
1192 input_api.unittest.TestSuite([test]).AndReturn(suite) 1209 input_api.unittest.TestSuite([test]).AndReturn(suite)
1193 test_result = self.mox.CreateMockAnything() 1210 test_result = self.mox.CreateMockAnything()
1194 runner.run(suite).AndReturn(test_result) 1211 runner.run(suite).AndReturn(test_result)
1195 test_result.wasSuccessful().AndReturn(True) 1212 test_result.wasSuccessful().AndReturn(True)
1196 test_result.failures = 0 1213 test_result.failures = 0
1197 test_result.errors = 0 1214 test_result.errors = 0
1198 self.mox.ReplayAll() 1215 self.mox.ReplayAll()
1199 1216
1200 results = presubmit_canned_checks.RunPythonUnitTests( 1217 results = presubmit_canned_checks.RunPythonUnitTests(
1201 input_api, presubmit.OutputApi, ['test_module']) 1218 input_api, presubmit.OutputApi, ['test_module'])
1202 self.assertEquals(len(results), 0) 1219 self.assertEquals(len(results), 0)
1203 1220
1204 1221
1205 if __name__ == '__main__': 1222 if __name__ == '__main__':
1206 unittest.main() 1223 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_canned_checks.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698