Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,22 @@ class NonbytesStream(self.StringIO):
t = self.TextIOWrapper(NonbytesStream('a'))
self.assertEqual(t.read(), u'a')

def test_illegal_encoder(self):
# bpo-31271: A TypeError should be raised in case the return value of
# encoder's encode() is invalid.
class BadEncoder:
def encode(self, dummy):
return u'spam'
def get_bad_encoder(dummy):
return BadEncoder()
rot13 = codecs.lookup("rot13")
with support.swap_attr(rot13, '_is_text_encoding', True), \
support.swap_attr(rot13, 'incrementalencoder', get_bad_encoder):
t = io.TextIOWrapper(io.BytesIO(b'foo'), encoding="rot13")
with self.assertRaises(TypeError):
t.write('bar')
t.flush()

def test_illegal_decoder(self):
# Issue #17106
# Bypass the early encoding check added in issue 20404
Expand Down