mirror of
https://github.com/python/cpython.git
synced 2025-08-15 14:20:55 +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
|
@ -87,6 +87,12 @@ class IOTest(unittest.TestCase):
|
|||
test_support.unlink(test_support.TESTFN)
|
||||
|
||||
def write_ops(self, f):
|
||||
|
||||
self.assertEqual(f.write(b"blah."), 5)
|
||||
f.truncate(0)
|
||||
self.assertEqual(f.tell(), 5)
|
||||
f.seek(0)
|
||||
|
||||
self.assertEqual(f.write(b"blah."), 5)
|
||||
self.assertEqual(f.seek(0), 0)
|
||||
self.assertEqual(f.write(b"Hello."), 6)
|
||||
|
@ -98,8 +104,9 @@ class IOTest(unittest.TestCase):
|
|||
self.assertEqual(f.write(b"h"), 1)
|
||||
self.assertEqual(f.seek(-1, 2), 13)
|
||||
self.assertEqual(f.tell(), 13)
|
||||
|
||||
self.assertEqual(f.truncate(12), 12)
|
||||
self.assertEqual(f.tell(), 12)
|
||||
self.assertEqual(f.tell(), 13)
|
||||
self.assertRaises(TypeError, f.seek, 0.0)
|
||||
|
||||
def read_ops(self, f, buffered=False):
|
||||
|
@ -144,7 +151,7 @@ class IOTest(unittest.TestCase):
|
|||
self.assertEqual(f.tell(), self.LARGE + 2)
|
||||
self.assertEqual(f.seek(0, 2), self.LARGE + 2)
|
||||
self.assertEqual(f.truncate(self.LARGE + 1), self.LARGE + 1)
|
||||
self.assertEqual(f.tell(), self.LARGE + 1)
|
||||
self.assertEqual(f.tell(), self.LARGE + 2)
|
||||
self.assertEqual(f.seek(0, 2), self.LARGE + 1)
|
||||
self.assertEqual(f.seek(-1, 2), self.LARGE)
|
||||
self.assertEqual(f.read(2), b"x")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue