mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Merged revisions 77895-77896 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r77895 | antoine.pitrou | 2010-01-31 23:47:27 +0100 (dim., 31 janv. 2010) | 12 lines Merged revisions 77890 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r77890 | antoine.pitrou | 2010-01-31 23:26:04 +0100 (dim., 31 janv. 2010) | 7 lines - 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. ........ ................ r77896 | antoine.pitrou | 2010-02-01 00:12:29 +0100 (lun., 01 févr. 2010) | 3 lines r77895 broke doctest. ................
This commit is contained in:
parent
1665a8d931
commit
66f9fea782
13 changed files with 99 additions and 48 deletions
|
@ -228,6 +228,11 @@ class IOTest(unittest.TestCase):
|
|||
support.unlink(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)
|
||||
|
@ -239,8 +244,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):
|
||||
|
@ -285,7 +291,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")
|
||||
|
@ -980,7 +986,7 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
|
|||
bufio = self.tp(raw, 8)
|
||||
bufio.write(b"abcdef")
|
||||
self.assertEqual(bufio.truncate(3), 3)
|
||||
self.assertEqual(bufio.tell(), 3)
|
||||
self.assertEqual(bufio.tell(), 6)
|
||||
with self.open(support.TESTFN, "rb", buffering=0) as f:
|
||||
self.assertEqual(f.read(), b"abc")
|
||||
|
||||
|
@ -1366,6 +1372,14 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest):
|
|||
self.assertEqual(s,
|
||||
b"A" + b"B" * overwrite_size + b"A" * (9 - overwrite_size))
|
||||
|
||||
def test_truncate_after_read_or_write(self):
|
||||
raw = self.BytesIO(b"A" * 10)
|
||||
bufio = self.tp(raw, 100)
|
||||
self.assertEqual(bufio.read(2), b"AA") # the read buffer gets filled
|
||||
self.assertEqual(bufio.truncate(), 2)
|
||||
self.assertEqual(bufio.write(b"BB"), 2) # the write buffer increases
|
||||
self.assertEqual(bufio.truncate(), 4)
|
||||
|
||||
def test_misbehaved_io(self):
|
||||
BufferedReaderTest.test_misbehaved_io(self)
|
||||
BufferedWriterTest.test_misbehaved_io(self)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue