mirror of
https://github.com/python/cpython.git
synced 2025-10-04 22:20:46 +00:00
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:
parent
f333014467
commit
ca5a06aaa9
7 changed files with 81 additions and 28 deletions
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue