summaryrefslogtreecommitdiff
path: root/Lib/test/string_tests.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-09-28 12:56:42 -0400
committerBenjamin Peterson <benjamin@python.org>2014-09-28 12:56:42 -0400
commit8fe189f1bd41d4dc1aeef7b267c0e73eb670e3eb (patch)
tree5c5851bbcbe6d8e2b04d8386a066042411c997a6 /Lib/test/string_tests.py
parent6a9671c1fa7add87fd030aba506779a98f440375 (diff)
downloadcpython-8fe189f1bd41d4dc1aeef7b267c0e73eb670e3eb.tar.gz
check that exception messages are not empty (#22379)
Patch by Yongzhi Pan.
Diffstat (limited to 'Lib/test/string_tests.py')
-rw-r--r--Lib/test/string_tests.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index 5ed01f2979..242a931ec6 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -1,5 +1,5 @@
"""
-Common tests shared by test_str, test_unicode, test_userstring and test_string.
+Common tests shared by test_unicode, test_userstring and test_string.
"""
import unittest, string, sys, struct
@@ -79,11 +79,9 @@ class BaseTest:
def checkraises(self, exc, obj, methodname, *args):
obj = self.fixtype(obj)
args = self.fixtype(args)
- self.assertRaises(
- exc,
- getattr(obj, methodname),
- *args
- )
+ with self.assertRaises(exc) as cm:
+ getattr(obj, methodname)(*args)
+ self.assertNotEqual(str(cm.exception), '')
# call obj.method(*args) without any checks
def checkcall(self, obj, methodname, *args):
@@ -1119,8 +1117,7 @@ class MixinStrUnicodeUserStringTest:
def test_join(self):
# join now works with any sequence type
# moved here, because the argument order is
- # different in string.join (see the test in
- # test.test_string.StringTest.test_join)
+ # different in string.join
self.checkequal('a b c d', ' ', 'join', ['a', 'b', 'c', 'd'])
self.checkequal('abcd', '', 'join', ('a', 'b', 'c', 'd'))
self.checkequal('bd', '', 'join', ('', 'b', '', 'd'))
@@ -1140,6 +1137,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', [1, 2, bytes()])
try: