[pypy-svn] r78385 - in pypy/branch/fast-forward/pypy/module/_io: . test
afa at codespeak.net
afa at codespeak.net
Thu Oct 28 10:19:35 CEST 2010
Author: afa
Date: Thu Oct 28 10:19:33 2010
New Revision: 78385
Modified:
pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py
pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py
Log:
file.read(n) may return a shorter string at end of file.
This also fixes readlines() when there is no \n at the end.
Too much code, and not enough tests :-(
Modified: pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/interp_bufferedio.py Thu Oct 28 10:19:33 2010
@@ -371,12 +371,14 @@
self.read_end = 0
while remaining > 0 and self.read_end < self.buffer_size:
- # Read until EOF or until read() would block
try:
size = self._fill_buffer(space)
except BlockingIOError:
+ # EOF or read() would block
if written == 0:
return None
+ size = 0
+ if size == 0:
break
if remaining > 0:
Modified: pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py
==============================================================================
--- pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py (original)
+++ pypy/branch/fast-forward/pypy/module/_io/test/test_bufferedio.py Thu Oct 28 10:19:33 2010
@@ -22,6 +22,16 @@
assert r == "a\nb\n"
f.close()
+ def test_read_pieces(self):
+ import _io
+ raw = _io.FileIO(self.tmpfile)
+ f = _io.BufferedReader(raw)
+ assert f.read(3) == "a\nb"
+ assert f.read(3) == "\nc"
+ assert f.read(3) == ""
+ assert f.read(3) == ""
+ f.close()
+
def test_seek(self):
import _io
raw = _io.FileIO(self.tmpfile)
@@ -33,6 +43,12 @@
assert f.read() == "\nc"
f.close()
+ def test_readlines(self):
+ import _io
+ raw = _io.FileIO(self.tmpfile)
+ f = _io.BufferedReader(raw)
+ assert f.readlines() == ['a\n', 'b\n', 'c']
+
class AppTestBufferedWriter:
def setup_class(cls):
cls.space = gettestobjspace(usemodules=['_io'])
More information about the Pypy-commit
mailing list