- Issue #6939: Fix file I/O objects in the io module to keep the original

file position when calling `truncate()`.  It would previously change the
  file position to the given argument, which goes against the tradition of
  ftruncate() and other truncation APIs.  Patch by Pascal Chambon.
This commit is contained in:
Antoine Pitrou 2010-01-31 22:26:04 +00:00
parent e70c72c06b
commit f3fa074703
12 changed files with 97 additions and 47 deletions

View file

@ -76,7 +76,7 @@ class MemoryTestMixin:
self.assertEqual(f.seek(0), 0)
self.assertEqual(f.write(t("h")), 1)
self.assertEqual(f.truncate(12), 12)
self.assertEqual(f.tell(), 12)
self.assertEqual(f.tell(), 1)
def test_write(self):
buf = self.buftype("hello world\n")
@ -127,7 +127,8 @@ class MemoryTestMixin:
# truncate() accepts long objects
self.assertEqual(memio.truncate(4L), 4)
self.assertEqual(memio.getvalue(), buf[:4])
self.assertEqual(memio.tell(), 4)
self.assertEqual(memio.tell(), 6)
memio.seek(0, 2)
memio.write(buf)
self.assertEqual(memio.getvalue(), buf[:4] + buf)
pos = memio.tell()