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-27 21:48:46 +00:00
parent f333014467
commit ca5a06aaa9
7 changed files with 81 additions and 28 deletions

View file

@ -197,6 +197,17 @@ class OtherFileTests(unittest.TestCase):
f.close()
self.fail("no error for invalid mode: %s" % bad_mode)
def testTruncate(self):
f = _fileio._FileIO(TESTFN, 'w')
f.write(bytes(bytearray(range(10))))
self.assertEqual(f.tell(), 10)
f.truncate(5)
self.assertEqual(f.tell(), 10)
self.assertEqual(f.seek(0, os.SEEK_END), 5)
f.truncate(15)
self.assertEqual(f.tell(), 5)
self.assertEqual(f.seek(0, os.SEEK_END), 15)
def testTruncateOnWindows(self):
def bug801631():
# SF bug <http://www.python.org/sf/801631>