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

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
« no previous file with comments | « Lib/unittest/case.py ('k') | Misc/ACKS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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):
1031 try:
berkerpeksag 2014/06/14 20:35:36 Can this be written like with.assertRaises(Ty
1032 self.assertRaises(1)
1033 self.fail("Expected TypeError")
1034 except TypeError:
1035 pass
1036
1037 try:
1038 self.assertRaises(object)
1039 self.fail("Expected TypeError")
1040 except TypeError:
1041 pass
1042
1043 try:
1044 self.assertRaises((TypeError, 1))
1045 self.fail("Expected TypeError")
1046 except TypeError:
1047 pass
1048
1049 try:
1050 self.assertRaises((object, 1))
storchaka 2015/03/21 18:47:08 Should be something like self.assertRaises((TypeEr
1051 self.fail("Expected TypeError")
1052 except TypeError:
1053 pass
1029 1054
1030 def testAssertWarnsCallable(self): 1055 def testAssertWarnsCallable(self):
1031 def _runtime_warn(): 1056 def _runtime_warn():
1032 warnings.warn("foo", RuntimeWarning) 1057 warnings.warn("foo", RuntimeWarning)
1033 # Success when the right warning is triggered, even several times 1058 # Success when the right warning is triggered, even several times
1034 self.assertWarns(RuntimeWarning, _runtime_warn) 1059 self.assertWarns(RuntimeWarning, _runtime_warn)
1035 self.assertWarns(RuntimeWarning, _runtime_warn) 1060 self.assertWarns(RuntimeWarning, _runtime_warn)
1036 # A tuple of warning classes is accepted 1061 # A tuple of warning classes is accepted
1037 self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn) 1062 self.assertWarns((DeprecationWarning, RuntimeWarning), _runtime_warn)
1038 # *args and **kwargs also work 1063 # *args and **kwargs also work
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 self.assertEqual(len(result.errors), 1) 1331 self.assertEqual(len(result.errors), 1)
1307 self.assertEqual(result.testsRun, 1) 1332 self.assertEqual(result.testsRun, 1)
1308 1333
1309 @support.cpython_only 1334 @support.cpython_only
1310 def testNoCycles(self): 1335 def testNoCycles(self):
1311 case = unittest.TestCase() 1336 case = unittest.TestCase()
1312 wr = weakref.ref(case) 1337 wr = weakref.ref(case)
1313 with support.disable_gc(): 1338 with support.disable_gc():
1314 del case 1339 del case
1315 self.assertFalse(wr()) 1340 self.assertFalse(wr())
OLDNEW
« no previous file with comments | « Lib/unittest/case.py ('k') | Misc/ACKS » ('j') | no next file with comments »

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