diff options
author | Benjamin Peterson <benjamin@python.org> | 2014-06-08 03:06:48 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2014-06-08 03:06:48 (GMT) |
commit | 10e847bbc7427e85f38191298275eaf14be625e5 (patch) | |
tree | be494f64eebfc2fdc0be613ddd0d73b2fe0033d0 /Lib/test/test_io.py | |
parent | 66f80e92c31cdcede9951d661b3538d862f632b1 (diff) | |
download | cpython-10e847bbc7427e85f38191298275eaf14be625e5.zip cpython-10e847bbc7427e85f38191298275eaf14be625e5.tar.gz cpython-10e847bbc7427e85f38191298275eaf14be625e5.tar.bz2 |
add BufferedIOBase.readinto1 (closes #20578)
Patch by Nikolaus Rath.
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 347832d..ee6db48 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -911,6 +911,29 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): self.assertEqual(bufio.readinto(b), 1) self.assertEqual(b, b"cb") + def test_readinto1(self): + buffer_size = 10 + rawio = self.MockRawIO((b"abc", b"de", b"fgh", b"jkl")) + bufio = self.tp(rawio, buffer_size=buffer_size) + b = bytearray(2) + self.assertEqual(bufio.peek(3), b'abc') + self.assertEqual(rawio._reads, 1) + self.assertEqual(bufio.readinto1(b), 2) + self.assertEqual(b, b"ab") + self.assertEqual(rawio._reads, 1) + self.assertEqual(bufio.readinto1(b), 1) + self.assertEqual(b[:1], b"c") + self.assertEqual(rawio._reads, 1) + self.assertEqual(bufio.readinto1(b), 2) + self.assertEqual(b, b"de") + self.assertEqual(rawio._reads, 2) + b = bytearray(2*buffer_size) + self.assertEqual(bufio.peek(3), b'fgh') + self.assertEqual(rawio._reads, 3) + self.assertEqual(bufio.readinto1(b), 6) + self.assertEqual(b[:6], b"fghjkl") + self.assertEqual(rawio._reads, 4) + def test_readlines(self): def bufio(): rawio = self.MockRawIO((b"abc\n", b"d\n", b"ef")) @@ -2985,6 +3008,8 @@ class MiscIOTest(unittest.TestCase): self.assertRaises(ValueError, f.readall) if hasattr(f, "readinto"): self.assertRaises(ValueError, f.readinto, bytearray(1024)) + if hasattr(f, "readinto1"): + self.assertRaises(ValueError, f.readinto1, bytearray(1024)) self.assertRaises(ValueError, f.readline) self.assertRaises(ValueError, f.readlines) self.assertRaises(ValueError, f.seek, 0) |