Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15654)

Side by Side Diff: Lib/unittest/test/test_case.py

Issue 15836: unittest assertRaises should verify excClass is actually a BaseException class
Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 import difflib 1 import difflib
2 import pprint 2 import pprint
3 import pickle 3 import pickle
4 import re 4 import re
5 import sys 5 import sys
6 6
7 from copy import deepcopy 7 from copy import deepcopy
8 from test import test_support 8 from test import test_support
9 9
10 import unittest 10 import unittest
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 def Stub(foo): 1006 def Stub(foo):
1007 raise ExceptionMock(foo) 1007 raise ExceptionMock(foo)
1008 v = "particular value" 1008 v = "particular value"
1009 1009
1010 ctx = self.assertRaises(ExceptionMock) 1010 ctx = self.assertRaises(ExceptionMock)
1011 with ctx: 1011 with ctx:
1012 Stub(v) 1012 Stub(v)
1013 e = ctx.exception 1013 e = ctx.exception
1014 self.assertIsInstance(e, ExceptionMock) 1014 self.assertIsInstance(e, ExceptionMock)
1015 self.assertEqual(e.args[0], v) 1015 self.assertEqual(e.args[0], v)
1016
1017 def testAssertRaisesNoExceptionType(self):
1018 try:
1019 self.assertRaises(1)
1020 self.fail("Expected TypeError")
1021 except TypeError:
1022 pass
ezio.melotti 2014/06/29 11:24:12 I think all these should be rewritten as: with sel
1023
1024 try:
1025 self.assertRaises(object)
1026 self.fail("Expected TypeError")
1027 except TypeError:
1028 pass
1029
1030 try:
1031 self.assertRaises((TypeError, 1))
1032 self.fail("Expected TypeError")
1033 except TypeError:
1034 pass
1035
1036 try:
1037 self.assertRaises((object, 1))
1038 self.fail("Expected TypeError")
1039 except TypeError:
1040 pass
1041
1042 class _OldStyleError():
1043 pass
1044 def raises():
1045 raise _OldStyleError()
1046 self.assertRaises(_OldStyleError, raises)
1047
1016 1048
1017 def testSynonymAssertMethodNames(self): 1049 def testSynonymAssertMethodNames(self):
1018 """Test undocumented method name synonyms. 1050 """Test undocumented method name synonyms.
1019 1051
1020 Please do not use these methods names in your own code. 1052 Please do not use these methods names in your own code.
1021 1053
1022 This test confirms their continued existence and functionality 1054 This test confirms their continued existence and functionality
1023 in order to avoid breaking existing code. 1055 in order to avoid breaking existing code.
1024 """ 1056 """
1025 self.assertNotEquals(3, 5) 1057 self.assertNotEquals(3, 5)
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 1147
1116 # blew up prior to fix 1148 # blew up prior to fix
1117 pickled_test = pickle.dumps(test, protocol=protocol) 1149 pickled_test = pickle.dumps(test, protocol=protocol)
1118 1150
1119 unpickled_test = pickle.loads(pickled_test) 1151 unpickled_test = pickle.loads(pickled_test)
1120 self.assertEqual(test, unpickled_test) 1152 self.assertEqual(test, unpickled_test)
1121 1153
1122 1154
1123 if __name__ == '__main__': 1155 if __name__ == '__main__':
1124 unittest.main() 1156 unittest.main()
OLDNEW
« Lib/unittest/case.py ('K') | « Lib/unittest/case.py ('k') | Misc/ACKS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+