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
commit46d79021d4dca43e8b9059564afd18537894090b (patch)
treed3800e3e8111fae53103a5df5fe0c98007281789 /Lib/test/test_fileio.py
parentde899d655b7e67cb3de58b5732ed48bd8f8dd98a (diff)
downloadcpython-46d79021d4dca43e8b9059564afd18537894090b.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>