diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-27 21:48:46 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-01-27 21:48:46 (GMT) |
| commit | ca5a06aaa968ae767329f8afedbaf17fc337416f (patch) | |
| tree | 1c0f8bfdd0469ce707d41b99371855f6f3f8ae91 /Lib/test/test_fileio.py | |
| parent | f3330144679453a66b9baf54963462d8cbd095f8 (diff) | |
| download | cpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.zip cpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.tar.gz cpython-ca5a06aaa968ae767329f8afedbaf17fc337416f.tar.bz2 | |
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.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_fileio.py b/Lib/test/test_fileio.py index 928fbec..0eea86b 100644 --- a/Lib/test/test_fileio.py +++ b/Lib/test/test_fileio.py @@ -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> |
