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

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 import warnings 6 import warnings
7 import weakref 7 import weakref
8 import inspect 8 import inspect
9 9
10 from copy import deepcopy 10 from copy import deepcopy
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 def Stub(foo): 1019 def Stub(foo):
1020 raise ExceptionMock(foo) 1020 raise ExceptionMock(foo)
1021 v = "particular value" 1021 v = "particular value"
1022 1022
1023 ctx = self.assertRaises(ExceptionMock) 1023 ctx = self.assertRaises(ExceptionMock)
1024 with ctx: 1024 with ctx:
1025 Stub(v) 1025 Stub(v)
1026 e = ctx.exception 1026 e = ctx.exception
1027 self.assertIsInstance(e, ExceptionMock) 1027 self.assertIsInstance(e, ExceptionMock)
1028 self.assertEqual(e.args[0], v) 1028 self.assertEqual(e.args[0], v)
1029
1030 def testAssertRaisesNoExceptionType(self):
r.david.murray 2012/09/01 03:00:27 Using assertRaises to test itself seems a little b
illicitonion 2012/09/01 03:35:38 Agree :) Done
1031 ctx = self.assertRaises(TypeError)
1032 with ctx:
1033 self.assertRaises(1)
1034 self.assertIsInstance(ctx.exception, TypeError)
1035
1036 ctx = self.assertRaises(TypeError)
1037 with ctx:
1038 self.assertRaises(object)
1039 self.assertIsInstance(ctx.exception, TypeError)
1040
1041 ctx = self.assertRaises(TypeError)
1042 with ctx:
1043 self.assertRaises((TypeError, 1))
1044 self.assertIsInstance(ctx.exception, TypeError)
1045
1046 ctx = self.assertRaises(TypeError)
1047 with ctx:
1048 self.assertRaises((object, 1))
1049 self.assertIsInstance(ctx.exception, TypeError)
1029 1050
1030 def testAssertWarnsCallable(self): 1051 def testAssertWarnsCallable(self):
1031 def _runtime_warn(): 1052 def _runtime_warn():
1032 warnings.warn("foo", RuntimeWarning) 1053 warnings.warn("foo", RuntimeWarning)
1033 # Success when the right warning is triggered, even several times 1054 # Success when the right warning is triggered, even several times
1034 self.assertWarns(RuntimeWarning, _runtime_warn) 1055 self.assertWarns(RuntimeWarning, _runtime_warn)
1035 self.assertWarns(RuntimeWarning, _runtime_warn) 1056 self.assertWarns(RuntimeWarning, _runtime_warn)
1036 # A tuple of warning classes is accepted 1057 # A tuple of warning classes is accepted
1037 self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn) 1058 self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn)
1038 # *args and **kwargs also work 1059 # *args and **kwargs also work
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 self.assertEqual(len(result.errors), 1) 1327 self.assertEqual(len(result.errors), 1)
1307 self.assertEqual(result.testsRun, 1) 1328 self.assertEqual(result.testsRun, 1)
1308 1329
1309 @support.cpython_only 1330 @support.cpython_only
1310 def testNoCycles(self): 1331 def testNoCycles(self):
1311 case = unittest.TestCase() 1332 case = unittest.TestCase()
1312 wr = weakref.ref(case) 1333 wr = weakref.ref(case)
1313 with support.disable_gc(): 1334 with support.disable_gc():
1314 del case 1335 del case
1315 self.assertFalse(wr()) 1336 self.assertFalse(wr())
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+