Author: Brian Kearns <[email protected]>
Branch:
Changeset: r63264:f2929b44b45b
Date: 2013-04-12 00:58 -0400
http://bitbucket.org/pypy/pypy/changeset/f2929b44b45b/
Log: test and fix for truncate differences between cStringIO and BytesIO
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
@@ -52,6 +52,8 @@
f.seek(3)
assert f.truncate() == 3
assert f.getvalue() == "hel"
+ assert f.truncate(2) == 2
+ assert f.tell() == 3
def test_setstate(self):
# state is (content, position, __dict__)
diff --git a/pypy/module/cStringIO/interp_stringio.py
b/pypy/module/cStringIO/interp_stringio.py
--- a/pypy/module/cStringIO/interp_stringio.py
+++ b/pypy/module/cStringIO/interp_stringio.py
@@ -159,6 +159,7 @@
if size < 0:
raise OperationError(space.w_IOError, space.wrap("negative size"))
self.truncate(size)
+ self.seek(0, 2)
@unwrap_spec(buffer='bufferstr')
def descr_write(self, buffer):
diff --git a/pypy/module/cStringIO/test/test_interp_stringio.py
b/pypy/module/cStringIO/test/test_interp_stringio.py
--- a/pypy/module/cStringIO/test/test_interp_stringio.py
+++ b/pypy/module/cStringIO/test/test_interp_stringio.py
@@ -142,8 +142,11 @@
f.write(' world')
f.truncate(30)
assert f.getvalue() == '\x00' * 20 + 'hello worl'
+ assert f.tell() == 30
+ f.seek(0)
f.truncate(25)
assert f.getvalue() == '\x00' * 20 + 'hello'
+ assert f.tell() == 25
f.write('baz')
f.write('egg')
f.truncate(3)
diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py
--- a/rpython/rlib/rStringIO.py
+++ b/rpython/rlib/rStringIO.py
@@ -163,9 +163,6 @@
return ''.join(self.__bigbuffer[p:i])
def truncate(self, size):
- # NB. 'size' is mandatory. This has the same un-Posix-y semantics
- # than CPython: it never grows the buffer, and it sets the current
- # position to the end.
assert size >= 0
if self.__bigbuffer is None or size > len(self.__bigbuffer):
self.__copy_into_bigbuffer()
@@ -177,4 +174,3 @@
del self.__bigbuffer[size:]
if len(self.__bigbuffer) == 0:
self.__bigbuffer = None
- self.__pos = AT_END
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit