diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-09-28 16:48:46 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-09-28 16:48:46 (GMT) |
commit | 1643d5cb08b72cb4f589ddd38db059412a4dcdd1 (patch) | |
tree | 8fb181a9a0a9205c4f4850917ac9ab7b1685264b /Lib | |
parent | 9ad23c6c315d09bef659a12a9f7f7123c707ea41 (diff) | |
download | cpython-1643d5cb08b72cb4f589ddd38db059412a4dcdd1.zip cpython-1643d5cb08b72cb4f589ddd38db059412a4dcdd1.tar.gz cpython-1643d5cb08b72cb4f589ddd38db059412a4dcdd1.tar.bz2 |
give exception a nice message (closes #22379)
Patch by Yongzhi Pan.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/string_tests.py | 13 | ||||
-rw-r--r-- | Lib/test/test_string.py | 11 | ||||
-rw-r--r-- | Lib/test/test_userstring.py | 12 |
3 files changed, 15 insertions, 21 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index 0479601..7818112 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -65,14 +65,12 @@ class CommonTest(unittest.TestCase): self.assertTrue(object is not realresult) # check that object.method(*args) raises exc - def checkraises(self, exc, object, methodname, *args): - object = self.fixtype(object) + def checkraises(self, exc, obj, methodname, *args): + obj = self.fixtype(obj) args = self.fixtype(args) - self.assertRaises( - exc, - getattr(object, methodname), - *args - ) + with self.assertRaises(exc) as cm: + getattr(obj, methodname)(*args) + self.assertNotEqual(cm.exception.message, '') # call object.method(*args) without any checks def checkcall(self, object, methodname, *args): @@ -1057,6 +1055,7 @@ class MixinStrUnicodeUserStringTest: self.checkequal('a b c', ' ', 'join', BadSeq2()) self.checkraises(TypeError, ' ', 'join') + self.checkraises(TypeError, ' ', 'join', None) self.checkraises(TypeError, ' ', 'join', 7) self.checkraises(TypeError, ' ', 'join', Sequence([7, 'hello', 123L])) try: diff --git a/Lib/test/test_string.py b/Lib/test/test_string.py index 0d07b91..f69255b 100644 --- a/Lib/test/test_string.py +++ b/Lib/test/test_string.py @@ -16,13 +16,10 @@ class StringTest( realresult ) - def checkraises(self, exc, object, methodname, *args): - self.assertRaises( - exc, - getattr(string, methodname), - object, - *args - ) + def checkraises(self, exc, obj, methodname, *args): + with self.assertRaises(exc) as cm: + getattr(string, methodname)(obj, *args) + self.assertNotEqual(cm.exception.message, '') def checkcall(self, object, methodname, *args): getattr(string, methodname)(object, *args) diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py index 51d8e8b..9cca14a 100644 --- a/Lib/test/test_userstring.py +++ b/Lib/test/test_userstring.py @@ -28,14 +28,12 @@ class UserStringTest( realresult ) - def checkraises(self, exc, object, methodname, *args): - object = self.fixtype(object) + def checkraises(self, exc, obj, methodname, *args): + obj = self.fixtype(obj) # we don't fix the arguments, because UserString can't cope with it - self.assertRaises( - exc, - getattr(object, methodname), - *args - ) + with self.assertRaises(exc) as cm: + getattr(obj, methodname)(*args) + self.assertNotEqual(cm.exception.message, '') def checkcall(self, object, methodname, *args): object = self.fixtype(object) |