diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-02-23 23:16:07 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-02-23 23:16:07 (GMT) |
commit | f20f9c299ee093fd67c5b3caf0b5013af71c3136 (patch) | |
tree | fbd924eb5d0c4f24b121074fce82ca6a5dc3a658 /Lib | |
parent | ea370a9edd7212c81921decc7e33589ad9f69389 (diff) | |
download | cpython-f20f9c299ee093fd67c5b3caf0b5013af71c3136.zip cpython-f20f9c299ee093fd67c5b3caf0b5013af71c3136.tar.gz cpython-f20f9c299ee093fd67c5b3caf0b5013af71c3136.tar.bz2 |
Issue #7649: Fix u'%c' % char for character in range 0x80..0xFF
=> raise an UnicodeDecodeError. Patch written by Ezio Melotti.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_unicode.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index debcddc..5eb331a 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -395,6 +395,19 @@ class UnicodeTest( self.assertEqual(u'%c' % 0x1234, u'\u1234') self.assertRaises(OverflowError, u"%c".__mod__, (sys.maxunicode+1,)) + for num in range(0x00,0x80): + char = chr(num) + self.assertEqual(u"%c" % char, char) + self.assertEqual(u"%c" % num, char) + # Issue 7649 + for num in range(0x80,0x100): + uchar = unichr(num) + self.assertEqual(uchar, u"%c" % num) # works only with ints + self.assertEqual(uchar, u"%c" % uchar) # and unicode chars + # the implicit decoding should fail for non-ascii chars + self.assertRaises(UnicodeDecodeError, u"%c".__mod__, chr(num)) + self.assertRaises(UnicodeDecodeError, u"%s".__mod__, chr(num)) + # formatting jobs delegated from the string implementation: self.assertEqual('...%(foo)s...' % {'foo':u"abc"}, u'...abc...') self.assertEqual('...%(foo)s...' % {'foo':"abc"}, '...abc...') |