diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-11-28 23:30:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-28 23:30:00 (GMT) |
commit | 219c2de5ad0fdac825298bed1bb251f16956c04a (patch) | |
tree | 728e8ffcfecbf1bc12aefaff2dad81720058f775 /Lib/test | |
parent | 23df2d1304ece169d7e0dfc843dfb8026b413d9f (diff) | |
download | cpython-219c2de5ad0fdac825298bed1bb251f16956c04a.zip cpython-219c2de5ad0fdac825298bed1bb251f16956c04a.tar.gz cpython-219c2de5ad0fdac825298bed1bb251f16956c04a.tar.bz2 |
bpo-32110: codecs.StreamReader.read(n) now returns not more than n (#4499)
characters/bytes for non-negative n. This makes it compatible with
read() methods of other file-like objects.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_codecs.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index de6868a..eb21a39 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -196,19 +196,33 @@ class ReadTest(MixInCheckStateHandling): self.assertEqual(f.read(), ''.join(lines[1:])) self.assertEqual(f.read(), '') + # Issue #32110: Test readline() followed by read(n) + f = getreader() + self.assertEqual(f.readline(), lines[0]) + self.assertEqual(f.read(1), lines[1][0]) + self.assertEqual(f.read(0), '') + self.assertEqual(f.read(100), data[len(lines[0]) + 1:][:100]) + # Issue #16636: Test readline() followed by readlines() f = getreader() self.assertEqual(f.readline(), lines[0]) self.assertEqual(f.readlines(), lines[1:]) self.assertEqual(f.read(), '') - # Test read() followed by read() + # Test read(n) followed by read() f = getreader() self.assertEqual(f.read(size=40, chars=5), data[:5]) self.assertEqual(f.read(), data[5:]) self.assertEqual(f.read(), '') - # Issue #12446: Test read() followed by readlines() + # Issue #32110: Test read(n) followed by read(n) + f = getreader() + self.assertEqual(f.read(size=40, chars=5), data[:5]) + self.assertEqual(f.read(1), data[5]) + self.assertEqual(f.read(0), '') + self.assertEqual(f.read(100), data[6:106]) + + # Issue #12446: Test read(n) followed by readlines() f = getreader() self.assertEqual(f.read(size=40, chars=5), data[:5]) self.assertEqual(f.readlines(), [lines[0][5:]] + lines[1:]) |