diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-13 19:30:15 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-13 19:30:15 (GMT) |
commit | 6b59f77c43c492f4c707ad4d8e2d2b0b871414e8 (patch) | |
tree | 68d0d1953d03c1dda5c0f9ebc8c346f63d6e70ad /Lib/test/test_io.py | |
parent | bb4cd51982df53099990a11969afe57beae2d912 (diff) | |
download | cpython-6b59f77c43c492f4c707ad4d8e2d2b0b871414e8.zip cpython-6b59f77c43c492f4c707ad4d8e2d2b0b871414e8.tar.gz cpython-6b59f77c43c492f4c707ad4d8e2d2b0b871414e8.tar.bz2 |
Merged revisions 76806,76808 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76806 | benjamin.peterson | 2009-12-13 13:25:34 -0600 (Sun, 13 Dec 2009) | 14 lines
Merged revisions 76805 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76805 | benjamin.peterson | 2009-12-13 13:19:07 -0600 (Sun, 13 Dec 2009) | 7 lines
accept None as the same as having passed no argument in file types #7349
This is for consistency with imitation file objects like StringIO and BytesIO.
This commit also adds a few tests, where they were lacking for concerned
methods.
........
................
r76808 | benjamin.peterson | 2009-12-13 13:28:09 -0600 (Sun, 13 Dec 2009) | 9 lines
Merged revisions 76807 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76807 | benjamin.peterson | 2009-12-13 13:27:02 -0600 (Sun, 13 Dec 2009) | 1 line
remove unused variable
........
................
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r-- | Lib/test/test_io.py | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index 150eff4..2f76fed 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -336,7 +336,7 @@ class IOTest(unittest.TestCase): self.assertEqual(f.readline(2), b"xy") self.assertEqual(f.readline(4), b"zzy\n") self.assertEqual(f.readline(), b"foo\x00bar\n") - self.assertEqual(f.readline(), b"another line") + self.assertEqual(f.readline(None), b"another line") self.assertRaises(TypeError, f.readline, 5.3) with self.open(support.TESTFN, "r") as f: self.assertRaises(TypeError, f.readline, 5.3) @@ -647,9 +647,10 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): self.assertEquals(b"abc", bufio.read()) def test_read(self): - rawio = self.MockRawIO((b"abc", b"d", b"efg")) - bufio = self.tp(rawio) - self.assertEquals(b"abcdef", bufio.read(6)) + for arg in (None, 7): + rawio = self.MockRawIO((b"abc", b"d", b"efg")) + bufio = self.tp(rawio) + self.assertEquals(b"abcdefg", bufio.read(arg)) # Invalid args self.assertRaises(ValueError, bufio.read, -2) @@ -666,6 +667,7 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): self.assertEquals(b"efg", bufio.read1(100)) self.assertEquals(rawio._reads, 3) self.assertEquals(b"", bufio.read1(100)) + self.assertEquals(rawio._reads, 4) # Invalid args self.assertRaises(ValueError, bufio.read1, -1) @@ -684,6 +686,14 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests): self.assertEquals(bufio.readinto(b), 0) self.assertEquals(b, b"gf") + def test_readlines(self): + def bufio(): + rawio = self.MockRawIO((b"abc\n", b"d\n", b"ef")) + return self.tp(rawio) + self.assertEquals(bufio().readlines(), [b"abc\n", b"d\n", b"ef"]) + self.assertEquals(bufio().readlines(5), [b"abc\n", b"d\n"]) + self.assertEquals(bufio().readlines(None), [b"abc\n", b"d\n", b"ef"]) + def test_buffering(self): data = b"abcdefghi" dlen = len(data) @@ -1123,6 +1133,14 @@ class BufferedRWPairTest(unittest.TestCase): self.assertEqual(pair.read(3), b"abc") self.assertEqual(pair.read(1), b"d") self.assertEqual(pair.read(), b"ef") + pair = self.tp(self.BytesIO(b"abc"), self.MockRawIO()) + self.assertEqual(pair.read(None), b"abc") + + def test_readlines(self): + pair = lambda: self.tp(self.BytesIO(b"abc\ndef\nh"), self.MockRawIO()) + self.assertEqual(pair().readlines(), [b"abc\n", b"def\n", b"h"]) + self.assertEqual(pair().readlines(), [b"abc\n", b"def\n", b"h"]) + self.assertEqual(pair().readlines(5), [b"abc\n", b"def\n"]) def test_read1(self): # .read1() is delegated to the underlying reader object, so this test @@ -1773,6 +1791,8 @@ class TextIOWrapperTest(unittest.TestCase): self.assertEquals(f.read(), "abc") cookie = f.tell() self.assertEquals(f.seek(0), 0) + self.assertEquals(f.read(None), "abc") + f.seek(0) self.assertEquals(f.read(2), "ab") self.assertEquals(f.read(1), "c") self.assertEquals(f.read(1), "") @@ -1943,6 +1963,14 @@ class TextIOWrapperTest(unittest.TestCase): reads += c self.assertEquals(reads, "AA\nBB") + def test_readlines(self): + txt = self.TextIOWrapper(self.BytesIO(b"AA\nBB\nCC")) + self.assertEqual(txt.readlines(), ["AA\n", "BB\n", "CC"]) + txt.seek(0) + self.assertEqual(txt.readlines(None), ["AA\n", "BB\n", "CC"]) + txt.seek(0) + self.assertEqual(txt.readlines(5), ["AA\n", "BB\n"]) + # read in amounts equal to TextIOWrapper._CHUNK_SIZE which is 128. def test_read_by_chunk(self): # make sure "\r\n" straddles 128 char boundary. |