[Python-checkins] cpython (3.4): check that exception messages are not empty (#22379)

benjamin.peterson python-checkins at python.org
Sun Sep 28 18:57:33 CEST 2014


https://hg.python.org/cpython/rev/ab1570d0132d
changeset:   92620:ab1570d0132d
branch:      3.4
parent:      92617:6375bf34fff6
user:        Benjamin Peterson <benjamin at python.org>
date:        Sun Sep 28 12:56:42 2014 -0400
summary:
  check that exception messages are not empty (#22379)

Patch by Yongzhi Pan.

files:
  Lib/test/string_tests.py    |  14 ++++++--------
  Lib/test/test_bytes.py      |   1 +
  Lib/test/test_userstring.py |  12 +++++-------
  Misc/ACKS                   |   1 +
  4 files changed, 13 insertions(+), 15 deletions(-)


diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
--- 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 @@
     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 @@
     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 @@
         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:
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py
--- a/Lib/test/test_bytes.py
+++ b/Lib/test/test_bytes.py
@@ -298,6 +298,7 @@
         seq = [b"abc"] * 1000
         expected = b"abc" + b".:abc" * 999
         self.assertEqual(dot_join(seq), expected)
+        self.assertRaises(TypeError, self.type2test(b" ").join, None)
         # Error handling and cleanup when some item in the middle of the
         # sequence has the wrong type.
         with self.assertRaises(TypeError):
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -28,14 +28,12 @@
             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(str(cm.exception), '')
 
     def checkcall(self, object, methodname, *args):
         object = self.fixtype(object)
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1010,6 +1010,7 @@
 Todd R. Palmer
 Juan David Ibáñez Palomar
 Jan Palus
+Yongzhi Pan
 Martin Panter
 Mathias Panzenböck
 M. Papillon

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list