[pypy-commit] pypy default: another test and fix for BytesIO.truncate()
bdkearns
noreply at buildbot.pypy.org
Fri Apr 12 08:50:26 CEST 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r63265:7c83049dafd8
Date: 2013-04-12 02:49 -0400
http://bitbucket.org/pypy/pypy/changeset/7c83049dafd8/
Log: another test and fix for BytesIO.truncate()
diff --git a/pypy/module/_io/interp_bytesio.py b/pypy/module/_io/interp_bytesio.py
--- a/pypy/module/_io/interp_bytesio.py
+++ b/pypy/module/_io/interp_bytesio.py
@@ -62,8 +62,9 @@
def truncate_w(self, space, w_size=None):
self._check_closed(space)
+ pos = self.tell()
if space.is_none(w_size):
- size = self.tell()
+ size = pos
else:
size = space.r_longlong_w(w_size)
@@ -72,6 +73,7 @@
"negative size value"))
self.truncate(size)
+ self.seek(pos)
return space.wrap(size)
def getvalue_w(self, space):
diff --git a/pypy/module/_io/test/test_bytesio.py b/pypy/module/_io/test/test_bytesio.py
--- a/pypy/module/_io/test/test_bytesio.py
+++ b/pypy/module/_io/test/test_bytesio.py
@@ -48,7 +48,12 @@
def test_truncate(self):
import _io
- f = _io.BytesIO("hello")
+ f = _io.BytesIO()
+ f.write("hello")
+ assert f.truncate(0) == 0
+ assert f.tell() == 5
+ f.seek(0)
+ f.write("hello")
f.seek(3)
assert f.truncate() == 3
assert f.getvalue() == "hel"
More information about the pypy-commit
mailing list