@@ -2435,22 +2435,22 @@ def test_raise_by_value(self):
24352435 self .check_wrapped (RuntimeError (msg ), msg )
24362436
24372437 @contextlib .contextmanager
2438- def assertNotWrapped (self , operation , exc_type , msg ):
2438+ def assertNotWrapped (self , operation , exc_type , msg_re , msg = None ):
2439+ if msg is None :
2440+ msg = msg_re
24392441 with self .assertRaisesRegex (exc_type , msg ) as caught :
24402442 yield caught
2441- actual_msg = str (caught .exception )
2442- self .assertNotIn (operation , actual_msg )
2443- self .assertNotIn (self .codec_name , actual_msg )
2443+ self .assertEqual (str (caught .exception ), msg )
24442444
2445- def check_not_wrapped (self , obj_to_raise , msg ):
2445+ def check_not_wrapped (self , obj_to_raise , msg_re , msg = None ):
24462446 self .set_codec (obj_to_raise )
2447- with self .assertNotWrapped ("encoding" , RuntimeError , msg ):
2447+ with self .assertNotWrapped ("encoding" , RuntimeError , msg_re , msg ):
24482448 "str input" .encode (self .codec_name )
2449- with self .assertNotWrapped ("encoding" , RuntimeError , msg ):
2449+ with self .assertNotWrapped ("encoding" , RuntimeError , msg_re , msg ):
24502450 codecs .encode ("str input" , self .codec_name )
2451- with self .assertNotWrapped ("decoding" , RuntimeError , msg ):
2451+ with self .assertNotWrapped ("decoding" , RuntimeError , msg_re , msg ):
24522452 b"bytes input" .decode (self .codec_name )
2453- with self .assertNotWrapped ("decoding" , RuntimeError , msg ):
2453+ with self .assertNotWrapped ("decoding" , RuntimeError , msg_re , msg ):
24542454 codecs .decode (b"bytes input" , self .codec_name )
24552455
24562456 def test_init_override_is_not_wrapped (self ):
@@ -2475,8 +2475,23 @@ def test_non_str_arg_is_not_wrapped(self):
24752475 self .check_not_wrapped (RuntimeError (1 ), "1" )
24762476
24772477 def test_multiple_args_is_not_wrapped (self ):
2478- msg = "\('a', 'b', 'c'\)"
2479- self .check_not_wrapped (RuntimeError ('a' , 'b' , 'c' ), msg )
2478+ msg_re = "\('a', 'b', 'c'\)"
2479+ msg = "('a', 'b', 'c')"
2480+ self .check_not_wrapped (RuntimeError ('a' , 'b' , 'c' ), msg_re , msg )
2481+
2482+ # http://bugs.python.org/issue19609
2483+ def test_codec_lookup_failure_not_wrapped (self ):
2484+ msg = "unknown encoding: %s" % self .codec_name
2485+ # The initial codec lookup should not be wrapped
2486+ with self .assertNotWrapped ("encoding" , LookupError , msg ):
2487+ "str input" .encode (self .codec_name )
2488+ with self .assertNotWrapped ("encoding" , LookupError , msg ):
2489+ codecs .encode ("str input" , self .codec_name )
2490+ with self .assertNotWrapped ("decoding" , LookupError , msg ):
2491+ b"bytes input" .decode (self .codec_name )
2492+ with self .assertNotWrapped ("decoding" , LookupError , msg ):
2493+ codecs .decode (b"bytes input" , self .codec_name )
2494+
24802495
24812496
24822497@unittest .skipUnless (sys .platform == 'win32' ,
0 commit comments