summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2019-05-22 15:18:26 (GMT)
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-05-22 15:18:26 (GMT)
commitb3be4072888a4ce054993c2801802721466ea02d (patch)
treef59540b9a13da03566d2a9121ceb87ad6b1dcf88 /Lib/test/test_codecs.py
parent933e1509ec6efa8e6ab8c8c7ce02059ce2b6d9b9 (diff)
downloadcpython-b3be4072888a4ce054993c2801802721466ea02d.zip
cpython-b3be4072888a4ce054993c2801802721466ea02d.tar.gz
cpython-b3be4072888a4ce054993c2801802721466ea02d.tar.bz2
bpo-33482: fix codecs.StreamRecoder.writelines (GH-6779)
A very simple fix. I found this while writing typeshed stubs for StreamRecoder. https://bugs.python.org/issue33482
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 8c14f59..f665feb 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -3146,6 +3146,27 @@ class Latin1Test(unittest.TestCase):
self.assertEqual(data.decode('latin1'), expected)
+class StreamRecoderTest(unittest.TestCase):
+ def test_writelines(self):
+ bio = io.BytesIO()
+ codec = codecs.lookup('ascii')
+ sr = codecs.StreamRecoder(bio, codec.encode, codec.decode,
+ encodings.ascii.StreamReader, encodings.ascii.StreamWriter)
+ sr.writelines([b'a', b'b'])
+ self.assertEqual(bio.getvalue(), b'ab')
+
+ def test_write(self):
+ bio = io.BytesIO()
+ codec = codecs.lookup('latin1')
+ # Recode from Latin-1 to utf-8.
+ sr = codecs.StreamRecoder(bio, codec.encode, codec.decode,
+ encodings.utf_8.StreamReader, encodings.utf_8.StreamWriter)
+
+ text = 'àñé'
+ sr.write(text.encode('latin1'))
+ self.assertEqual(bio.getvalue(), text.encode('utf-8'))
+
+
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
class LocaleCodecTest(unittest.TestCase):
"""