diff -r 5b43d7984a63 Lib/test/test_io.py --- a/Lib/test/test_io.py Wed Dec 30 01:42:43 2015 +0200 +++ b/Lib/test/test_io.py Tue Dec 29 21:24:05 2015 -0800 @@ -3015,6 +3015,42 @@ F.tell = lambda x: 0 t = self.TextIOWrapper(F(), encoding='utf-8') + def test_issue25863(self): + iso2022_charsets = ['utf-8', + 'iso-2022-jp', + 'iso-2022-jp-1', + 'iso-2022-jp-2', + 'iso-2022-jp-3', + 'iso-2022-jp-2004', + 'iso-2022-kr', + # These charsets aren't implemented currently + # but should also be tested if they are added + #'iso-2022-cn', + #'iso-2022-cn-ext' + ] + for charset in iso2022_charsets: + text = self.TextIOWrapper(io.BytesIO(), encoding=charset) + s = u"Panter 正孝" + + text.write(u"P") + + start = text.tell() + num_chars = text.write(u"anter 正") + pos = text.tell() + + text.write(u"孝") + text.seek(pos) + + # Report the encoding that failed + self.assertEqual(text.read(), u"孝") + + self.assertEqual(text.buffer.getvalue(), s.encode(encoding=charset)) + + # These lines test a bug where text.tell() raises a + # UnicodeDecodeError. + text.seek(start) + text.read(num_chars) + text.tell() class MemviewBytesIO(io.BytesIO): '''A BytesIO object whose read method returns memoryviews