summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOren Milman <orenmn@gmail.com>2017-11-07 00:17:54 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2017-11-07 00:17:54 (GMT)
commit30537698b607d53fa9ce18522abb88469d5814b6 (patch)
tree9bbb8579b052d3b79412dde525fccd7a4f90f0c0
parent4376a2275967971a2f9586028347d6ed4ed6ef13 (diff)
downloadcpython-30537698b607d53fa9ce18522abb88469d5814b6.zip
cpython-30537698b607d53fa9ce18522abb88469d5814b6.tar.gz
cpython-30537698b607d53fa9ce18522abb88469d5814b6.tar.bz2
[2.7] bpo-31271: Fix an assertion failure in io.TextIOWrapper.write. (GH-3201) (#3951)
-rw-r--r--Lib/test/test_io.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 3dc6e9f..ea5ec65 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2666,6 +2666,22 @@ class TextIOWrapperTest(unittest.TestCase):
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