summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_io.py
diff options
context:
space:
mode:
authorKa-Ping Yee <ping@zesty.ca>2008-03-18 07:01:49 (GMT)
committerKa-Ping Yee <ping@zesty.ca>2008-03-18 07:01:49 (GMT)
commit30cc83832dc6911c1c35ed05500829c235f92587 (patch)
treeec618c20a3385b2c8a6b2b34e2aa0c1cca4d21d4 /Lib/test/test_io.py
parentf44c7e8996d8115739b52fa52896f2f9f7d94142 (diff)
downloadcpython-30cc83832dc6911c1c35ed05500829c235f92587.zip
cpython-30cc83832dc6911c1c35ed05500829c235f92587.tar.gz
cpython-30cc83832dc6911c1c35ed05500829c235f92587.tar.bz2
In TextIOWrapper:
- Switch from consuming _decoded_text to advancing an offset into it. - Fix readline() interaction with seek/tell. - Fix readline() handling of 'limit' argument. Add tests for seek/tell after readline().
Diffstat (limited to 'Lib/test/test_io.py')
-rw-r--r--Lib/test/test_io.py38
1 files changed, 33 insertions, 5 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py
index 49404e1..27814a0 100644
--- a/Lib/test/test_io.py
+++ b/Lib/test/test_io.py
@@ -590,7 +590,9 @@ class StatefulIncrementalDecoderTest(unittest.TestCase):
# I=0, O=3
(b'i.o3.x.xyz.toolong.', False, 'x--.xyz.too.'),
# I=6, O=3
- (b'i.o3.i6.abcdefghijklmnop', True, 'abc.ghi.mno.')
+ (b'i.o3.i6.abcdefghijklmnop', True, 'abc.ghi.mno.'),
+ # I=5, O=8 with newlines
+ (b'i.o8.i5.abc\ndef\nghy\nz', True, 'abc\nd---.ef\ngh---.y\nz-----.')
]
def testDecoder(self):
@@ -890,8 +892,8 @@ class TextIOWrapperTest(unittest.TestCase):
return codecs.CodecInfo(
name='test_decoder', encode=None, decode=None,
incrementalencoder=None,
- streamreader=None, streamwriter=None,
- incrementaldecoder=StatefulIncrementalDecoder)
+ incrementaldecoder=StatefulIncrementalDecoder,
+ streamreader=None, streamwriter=None)
def testSeekAndTellWithData(data, min_pos=0):
"""Tell/seek to various points within a data stream and ensure
@@ -903,16 +905,42 @@ class TextIOWrapperTest(unittest.TestCase):
decoded = f.read()
f.close()
- for i in range(min_pos, len(decoded) + 1): # seek positions
- for j in [1, 5, len(decoded) - i]: # read lengths
+ # Use read() to move to various positions in the input;
+ # then tell, read some more data, and seek back.
+ for i in range(min_pos, len(decoded) + 1): # to read before tell
+ for j in [1, 5, len(decoded)]: # to read after tell
f = io.open(test_support.TESTFN, encoding='test_decoder')
self.assertEquals(f.read(i), decoded[:i])
cookie = f.tell()
self.assertEquals(f.read(j), decoded[i:i + j])
f.seek(cookie)
+ self.assertEquals(f.tell(), cookie)
self.assertEquals(f.read(), decoded[i:])
f.close()
+ lines = len(decoded.split('\n'))
+
+ # Use readline() to move to various positions in the input;
+ # then tell, read some more data, and seek back.
+ for limit in [-1, 4, 128]: # 'limit' argument for readline()
+ for j in [1, 5, len(decoded)]: # to read after tell()
+ f = io.open(test_support.TESTFN, encoding='test_decoder')
+ text = ''
+ for k in range(lines): # repeatedly call readline()
+ line = f.readline(limit=limit)
+ if limit >= 0:
+ self.assert_(len(line) <= limit)
+ text += line
+ i = len(text)
+ self.assertEquals(text, decoded[:i])
+ cookie = f.tell()
+ self.assertEquals(f.read(j), decoded[i:i + j])
+ f.seek(cookie)
+ self.assertEquals(f.tell(), cookie)
+ self.assertEquals(f.read(), decoded[i:])
+ f.seek(cookie)
+ f.close()
+
# Register a special incremental decoder for testing.
codecs.register(lookupTestDecoder)
self.codecEnabled = 1