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

Side by Side Diff: tests/presubmit_unittest.py

Issue 119285: Fix presubmit_support.py run standalone and RunPythonUnitTests (Closed)
Patch Set: 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_support.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 951 matching lines...) Expand 10 before | Expand all | Expand 10 after
962 input_api = self.MockInputApi() 962 input_api = self.MockInputApi()
963 input_api.is_committing = False 963 input_api.is_committing = False
964 self.mox.ReplayAll() 964 self.mox.ReplayAll()
965 results = presubmit_canned_checks.RunPythonUnitTests( 965 results = presubmit_canned_checks.RunPythonUnitTests(
966 input_api, presubmit.OutputApi, []) 966 input_api, presubmit.OutputApi, [])
967 self.assertEquals(results, []) 967 self.assertEquals(results, [])
968 968
969 def testRunPythonUnitTestsNonExistent1(self): 969 def testRunPythonUnitTestsNonExistent1(self):
970 input_api = self.MockInputApi() 970 input_api = self.MockInputApi()
971 input_api.is_committing = False 971 input_api.is_committing = False
972 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module' 972 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
973 ).AndRaise(exceptions.ImportError('Blehh')) 973 input_api, '_non_existent_module').AndRaise(
974 exceptions.ImportError('Blehh'))
974 self.mox.ReplayAll() 975 self.mox.ReplayAll()
975 results = presubmit_canned_checks.RunPythonUnitTests( 976 results = presubmit_canned_checks.RunPythonUnitTests(
976 input_api, presubmit.OutputApi, ['_non_existent_module']) 977 input_api, presubmit.OutputApi, ['_non_existent_module'])
977 self.assertEquals(len(results), 1) 978 self.assertEquals(len(results), 1)
978 self.assertEquals(results[0].__class__, 979 self.assertEquals(results[0].__class__,
979 presubmit.OutputApi.PresubmitNotifyResult) 980 presubmit.OutputApi.PresubmitNotifyResult)
980 981
981 def testRunPythonUnitTestsNonExistent2(self): 982 def testRunPythonUnitTestsNonExistent2(self):
982 input_api = self.MockInputApi() 983 input_api = self.MockInputApi()
983 input_api.is_committing = True 984 input_api.is_committing = True
984 presubmit_canned_checks._RunPythonUnitTests_LoadTests('_non_existent_module' 985 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
985 ).AndRaise(exceptions.ImportError('Blehh')) 986 input_api, '_non_existent_module').AndRaise(
987 exceptions.ImportError('Blehh'))
986 self.mox.ReplayAll() 988 self.mox.ReplayAll()
987 results = presubmit_canned_checks.RunPythonUnitTests( 989 results = presubmit_canned_checks.RunPythonUnitTests(
988 input_api, presubmit.OutputApi, ['_non_existent_module']) 990 input_api, presubmit.OutputApi, ['_non_existent_module'])
989 self.assertEquals(len(results), 1) 991 self.assertEquals(len(results), 1)
990 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 992 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
991 993
992 def testRunPythonUnitTestsEmpty1(self): 994 def testRunPythonUnitTestsEmpty1(self):
993 input_api = self.MockInputApi() 995 input_api = self.MockInputApi()
994 input_api.is_committing = False 996 input_api.is_committing = False
995 test_module = self.mox.CreateMockAnything() 997 test_module = self.mox.CreateMockAnything()
996 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 998 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
997 ).AndReturn([]) 999 input_api, 'test_module').AndReturn([])
998 self.mox.ReplayAll() 1000 self.mox.ReplayAll()
999 1001
1000 results = presubmit_canned_checks.RunPythonUnitTests( 1002 results = presubmit_canned_checks.RunPythonUnitTests(
1001 input_api, presubmit.OutputApi, ['test_module']) 1003 input_api, presubmit.OutputApi, ['test_module'])
1002 self.assertEquals(results, []) 1004 self.assertEquals(results, [])
1003 1005
1004 def testRunPythonUnitTestsEmpty2(self): 1006 def testRunPythonUnitTestsEmpty2(self):
1005 input_api = self.MockInputApi() 1007 input_api = self.MockInputApi()
1006 input_api.is_committing = True 1008 input_api.is_committing = True
1007 test_module = self.mox.CreateMockAnything() 1009 test_module = self.mox.CreateMockAnything()
1008 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1010 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1009 ).AndReturn([]) 1011 input_api, 'test_module').AndReturn([])
1010 self.mox.ReplayAll() 1012 self.mox.ReplayAll()
1011 1013
1012 results = presubmit_canned_checks.RunPythonUnitTests( 1014 results = presubmit_canned_checks.RunPythonUnitTests(
1013 input_api, presubmit.OutputApi, ['test_module']) 1015 input_api, presubmit.OutputApi, ['test_module'])
1014 self.assertEquals(results, []) 1016 self.assertEquals(results, [])
1015 1017
1016 def testRunPythonUnitTestsFailure1(self): 1018 def testRunPythonUnitTestsFailure1(self):
1017 input_api = self.MockInputApi() 1019 input_api = self.MockInputApi()
1018 input_api.is_committing = False 1020 input_api.is_committing = False
1019 input_api.unittest = self.mox.CreateMock(unittest) 1021 input_api.unittest = self.mox.CreateMock(unittest)
1020 test = self.mox.CreateMockAnything() 1022 test = self.mox.CreateMockAnything()
1021 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1023 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1022 ).AndReturn([test]) 1024 input_api, 'test_module').AndReturn([test])
1023 runner = self.mox.CreateMockAnything() 1025 runner = self.mox.CreateMockAnything()
1024 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1026 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
1025 suite = self.mox.CreateMockAnything() 1027 suite = self.mox.CreateMockAnything()
1026 input_api.unittest.TestSuite([test]).AndReturn(suite) 1028 input_api.unittest.TestSuite([test]).AndReturn(suite)
1027 test_result = self.mox.CreateMockAnything() 1029 test_result = self.mox.CreateMockAnything()
1028 runner.run(suite).AndReturn(test_result) 1030 runner.run(suite).AndReturn(test_result)
1029 test_result.wasSuccessful().AndReturn(False) 1031 test_result.wasSuccessful().AndReturn(False)
1030 test_result.failures = 2 1032 test_result.failures = [None, None]
1031 test_result.errors = 3 1033 test_result.errors = [None, None, None]
1032 self.mox.ReplayAll() 1034 self.mox.ReplayAll()
1033 1035
1034 results = presubmit_canned_checks.RunPythonUnitTests( 1036 results = presubmit_canned_checks.RunPythonUnitTests(
1035 input_api, presubmit.OutputApi, ['test_module']) 1037 input_api, presubmit.OutputApi, ['test_module'])
1036 self.assertEquals(len(results), 1) 1038 self.assertEquals(len(results), 1)
1037 self.assertEquals(results[0].__class__, 1039 self.assertEquals(results[0].__class__,
1038 presubmit.OutputApi.PresubmitNotifyResult) 1040 presubmit.OutputApi.PresubmitNotifyResult)
1039 1041
1040 def testRunPythonUnitTestsFailure2(self): 1042 def testRunPythonUnitTestsFailure2(self):
1041 input_api = self.MockInputApi() 1043 input_api = self.MockInputApi()
1042 input_api.is_committing = True 1044 input_api.is_committing = True
1043 input_api.unittest = self.mox.CreateMock(unittest) 1045 input_api.unittest = self.mox.CreateMock(unittest)
1044 test = self.mox.CreateMockAnything() 1046 test = self.mox.CreateMockAnything()
1045 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1047 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1046 ).AndReturn([test]) 1048 input_api, 'test_module').AndReturn([test])
1047 runner = self.mox.CreateMockAnything() 1049 runner = self.mox.CreateMockAnything()
1048 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1050 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
1049 suite = self.mox.CreateMockAnything() 1051 suite = self.mox.CreateMockAnything()
1050 input_api.unittest.TestSuite([test]).AndReturn(suite) 1052 input_api.unittest.TestSuite([test]).AndReturn(suite)
1051 test_result = self.mox.CreateMockAnything() 1053 test_result = self.mox.CreateMockAnything()
1052 runner.run(suite).AndReturn(test_result) 1054 runner.run(suite).AndReturn(test_result)
1053 test_result.wasSuccessful().AndReturn(False) 1055 test_result.wasSuccessful().AndReturn(False)
1054 test_result.failures = 2 1056 test_result.failures = [None, None]
1055 test_result.errors = 3 1057 test_result.errors = [None, None, None]
1056 self.mox.ReplayAll() 1058 self.mox.ReplayAll()
1057 1059
1058 results = presubmit_canned_checks.RunPythonUnitTests( 1060 results = presubmit_canned_checks.RunPythonUnitTests(
1059 input_api, presubmit.OutputApi, ['test_module']) 1061 input_api, presubmit.OutputApi, ['test_module'])
1060 self.assertEquals(len(results), 1) 1062 self.assertEquals(len(results), 1)
1061 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError) 1063 self.assertEquals(results[0].__class__, presubmit.OutputApi.PresubmitError)
1062 1064
1063 def testRunPythonUnitTestsSuccess(self): 1065 def testRunPythonUnitTestsSuccess(self):
1064 input_api = self.MockInputApi() 1066 input_api = self.MockInputApi()
1065 input_api.is_committing = False 1067 input_api.is_committing = False
1066 input_api.unittest = self.mox.CreateMock(unittest) 1068 input_api.unittest = self.mox.CreateMock(unittest)
1067 test = self.mox.CreateMockAnything() 1069 test = self.mox.CreateMockAnything()
1068 presubmit_canned_checks._RunPythonUnitTests_LoadTests('test_module' 1070 presubmit_canned_checks._RunPythonUnitTests_LoadTests(
1069 ).AndReturn([test]) 1071 input_api, 'test_module').AndReturn([test])
1070 runner = self.mox.CreateMockAnything() 1072 runner = self.mox.CreateMockAnything()
1071 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner) 1073 input_api.unittest.TextTestRunner(verbosity=0).AndReturn(runner)
1072 suite = self.mox.CreateMockAnything() 1074 suite = self.mox.CreateMockAnything()
1073 input_api.unittest.TestSuite([test]).AndReturn(suite) 1075 input_api.unittest.TestSuite([test]).AndReturn(suite)
1074 test_result = self.mox.CreateMockAnything() 1076 test_result = self.mox.CreateMockAnything()
1075 runner.run(suite).AndReturn(test_result) 1077 runner.run(suite).AndReturn(test_result)
1076 test_result.wasSuccessful().AndReturn(True) 1078 test_result.wasSuccessful().AndReturn(True)
1077 test_result.failures = 0 1079 test_result.failures = 0
1078 test_result.errors = 0 1080 test_result.errors = 0
1079 self.mox.ReplayAll() 1081 self.mox.ReplayAll()
1080 1082
1081 results = presubmit_canned_checks.RunPythonUnitTests( 1083 results = presubmit_canned_checks.RunPythonUnitTests(
1082 input_api, presubmit.OutputApi, ['test_module']) 1084 input_api, presubmit.OutputApi, ['test_module'])
1083 self.assertEquals(len(results), 0) 1085 self.assertEquals(len(results), 0)
1084 1086
1085 1087
1086 if __name__ == '__main__': 1088 if __name__ == '__main__':
1087 unittest.main() 1089 unittest.main()
OLDNEW
« no previous file with comments | « presubmit_support.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698