diff -r 4d89d03690ef Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py Sun Aug 31 15:48:55 2014 +0200
+++ b/Lib/test/test_codecs.py Tue Sep 02 02:22:55 2014 +0200
@@ -2628,7 +2628,7 @@ class ExceptionChainingTest(unittest.Tes
def raise_obj(self, *args, **kwds):
# Helper to dynamically change the object raised by a test codec
- raise self.obj_to_raise
+ raise self.obj_to_raise()
def check_wrapped(self, obj_to_raise, msg, exc_type=RuntimeError):
self.obj_to_raise = obj_to_raise
@@ -2643,27 +2643,27 @@ class ExceptionChainingTest(unittest.Tes
codecs.decode(b"bytes input", self.codec_name)
def test_raise_by_type(self):
- self.check_wrapped(RuntimeError, "")
+ self.check_wrapped(lambda: RuntimeError, "")
def test_raise_by_value(self):
msg = "This should be wrapped"
- self.check_wrapped(RuntimeError(msg), msg)
+ self.check_wrapped(lambda: RuntimeError(msg), msg)
def test_raise_grandchild_subclass_exact_size(self):
msg = "This should be wrapped"
class MyRuntimeError(RuntimeError):
__slots__ = ()
- self.check_wrapped(MyRuntimeError(msg), msg, MyRuntimeError)
+ self.check_wrapped(lambda: MyRuntimeError(msg), msg, MyRuntimeError)
def test_raise_subclass_with_weakref_support(self):
msg = "This should be wrapped"
class MyRuntimeError(RuntimeError):
pass
- self.check_wrapped(MyRuntimeError(msg), msg, MyRuntimeError)
+ self.check_wrapped(lambda: MyRuntimeError(msg), msg, MyRuntimeError)
def check_not_wrapped(self, obj_to_raise, msg):
def raise_obj(*args, **kwds):
- raise obj_to_raise
+ raise obj_to_raise()
self.set_codec(raise_obj, raise_obj)
with self.assertRaisesRegex(RuntimeError, msg):
"str input".encode(self.codec_name)
@@ -2678,26 +2678,28 @@ class ExceptionChainingTest(unittest.Tes
class CustomInit(RuntimeError):
def __init__(self):
pass
- self.check_not_wrapped(CustomInit, "")
+ self.check_not_wrapped(lambda: CustomInit, "")
def test_new_override_is_not_wrapped(self):
class CustomNew(RuntimeError):
def __new__(cls):
return super().__new__(cls)
- self.check_not_wrapped(CustomNew, "")
+ self.check_not_wrapped(lambda: CustomNew, "")
def test_instance_attribute_is_not_wrapped(self):
msg = "This should NOT be wrapped"
- exc = RuntimeError(msg)
- exc.attr = 1
- self.check_not_wrapped(exc, "^{}$".format(msg))
+ def func():
+ exc = RuntimeError(msg)
+ exc.attr = 1
+ return exc
+ self.check_not_wrapped(func, "^{}$".format(msg))
def test_non_str_arg_is_not_wrapped(self):
- self.check_not_wrapped(RuntimeError(1), "1")
+ self.check_not_wrapped(lambda: RuntimeError(1), "1")
def test_multiple_args_is_not_wrapped(self):
msg_re = r"^\('a', 'b', 'c'\)$"
- self.check_not_wrapped(RuntimeError('a', 'b', 'c'), msg_re)
+ self.check_not_wrapped(lambda: RuntimeError('a', 'b', 'c'), msg_re)
# http://bugs.python.org/issue19609
def test_codec_lookup_failure_not_wrapped(self):