Author: Brian Kearns <[email protected]>
Branch:
Changeset: r73132:c337d9417d2e
Date: 2014-08-28 21:20 -0400
http://bitbucket.org/pypy/pypy/changeset/c337d9417d2e/
Log: test/fix rfile.truncate
diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -233,6 +233,7 @@
if self.ll_file:
if arg == -1:
arg = self.tell()
+ self.flush()
res = c_ftruncate(self.fileno(), arg)
if res == -1:
errno = rposix.get_errno()
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -140,14 +140,14 @@
fname = str(self.tmpdir.join('file_trunc'))
def f():
- f = open(fname, "w")
- f.write("xyz")
+ f = open(fname, "w+b")
+ f.write("hello world")
+ f.seek(7)
+ f.truncate()
f.seek(0)
- f.truncate(2)
+ data = f.read()
+ assert data == "hello w"
f.close()
- f2 = open(fname)
- assert f2.read() == "xy"
- f2.close()
f()
self.interpret(f, [])
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit