summaryrefslogtreecommitdiff
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorAmmar Askar <ammar_askar@hotmail.com>2019-05-31 12:44:01 -0700
committerBerker Peksag <berker.peksag@gmail.com>2019-05-31 22:44:00 +0300
commita6ec1ce1ac05b1258931422e96eac215b6a05459 (patch)
tree55a15df467b1e34a37f408524035495e4572c502 /Lib/test/test_codecs.py
parentaac4d0342c3e692731c189d003dbd73a8c681a34 (diff)
downloadcpython-git-a6ec1ce1ac05b1258931422e96eac215b6a05459.tar.gz
bpo-33361: Fix bug with seeking in StreamRecoders (GH-8278)
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index f665febfc9..47df88ceda 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -3166,6 +3166,31 @@ class StreamRecoderTest(unittest.TestCase):
sr.write(text.encode('latin1'))
self.assertEqual(bio.getvalue(), text.encode('utf-8'))
+ def test_seeking_read(self):
+ bio = io.BytesIO('line1\nline2\nline3\n'.encode('utf-16-le'))
+ sr = codecs.EncodedFile(bio, 'utf-8', 'utf-16-le')
+
+ self.assertEqual(sr.readline(), b'line1\n')
+ sr.seek(0)
+ self.assertEqual(sr.readline(), b'line1\n')
+ self.assertEqual(sr.readline(), b'line2\n')
+ self.assertEqual(sr.readline(), b'line3\n')
+ self.assertEqual(sr.readline(), b'')
+
+ def test_seeking_write(self):
+ bio = io.BytesIO('123456789\n'.encode('utf-16-le'))
+ sr = codecs.EncodedFile(bio, 'utf-8', 'utf-16-le')
+
+ # Test that seek() only resets its internal buffer when offset
+ # and whence are zero.
+ sr.seek(2)
+ sr.write(b'\nabc\n')
+ self.assertEqual(sr.readline(), b'789\n')
+ sr.seek(0)
+ self.assertEqual(sr.readline(), b'1\n')
+ self.assertEqual(sr.readline(), b'abc\n')
+ self.assertEqual(sr.readline(), b'789\n')
+
@unittest.skipIf(_testcapi is None, 'need _testcapi module')
class LocaleCodecTest(unittest.TestCase):