summaryrefslogtreecommitdiff
path: root/Lib/test/test_fileio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-31 22:26:04 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-31 22:26:04 +0000
commitf3fa07470381b4f54b2d3f911fc22624e9b0b27d (patch)
tree5368b993641d34b3824a79896bf18c8f9097ce5c /Lib/test/test_fileio.py
parente70c72c06b169a36170ab68ec52bda9a87c16274 (diff)
downloadcpython-git-f3fa07470381b4f54b2d3f911fc22624e9b0b27d.tar.gz
- 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.
Diffstat (limited to 'Lib/test/test_fileio.py')
-rw-r--r--Lib/test/test_fileio.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py
index 91c5251d42..cdc3123718 100644
--- a/Lib/test/test_fileio.py
+++ b/Lib/test/test_fileio.py
@@ -329,6 +329,17 @@ class OtherFileTests(unittest.TestCase):
f.close()
self.fail("no error for invalid mode: %s" % bad_mode)
+ def testTruncate(self):
+ f = _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>