summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index caca033..3dc6e9f 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -2702,6 +2702,26 @@ class TextIOWrapperTest(unittest.TestCase):
#t = _make_illegal_wrapper()
#self.assertRaises(TypeError, t.read)
+ # Issue 31243: calling read() while the return value of decoder's
+ # getstate() is invalid should neither crash the interpreter nor
+ # raise a SystemError.
+ def _make_very_illegal_wrapper(getstate_ret_val):
+ class BadDecoder:
+ def getstate(self):
+ return getstate_ret_val
+ def _get_bad_decoder(dummy):
+ return BadDecoder()
+ quopri = codecs.lookup("quopri_codec")
+ with support.swap_attr(quopri, 'incrementaldecoder',
+ _get_bad_decoder):
+ return _make_illegal_wrapper()
+ t = _make_very_illegal_wrapper(42)
+ with self.maybeRaises(TypeError):
+ t.read(42)
+ t = _make_very_illegal_wrapper(())
+ with self.maybeRaises(TypeError):
+ t.read(42)
+
class CTextIOWrapperTest(TextIOWrapperTest):