diff options
Diffstat (limited to 'Lib/test')
| -rw-r--r-- | Lib/test/test_fileio.py | 11 | ||||
| -rw-r--r-- | Lib/test/test_io.py | 11 | ||||
| -rw-r--r-- | Lib/test/test_memoryio.py | 5 |
3 files changed, 23 insertions, 4 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> diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index f0b38b6..38c58c3 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -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") diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index d538a7e..85b5e13 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -32,7 +32,7 @@ class MemoryTestMixin: self.assertEqual(f.seek(0), 0) self.assertEqual(f.write(t("h")), 1) self.assertEqual(f.truncate(12), 12) - self.assertEqual(f.tell(), 12) + self.assertEqual(f.tell(), 1) def test_write(self): buf = self.buftype("hello world\n") @@ -83,7 +83,8 @@ class MemoryTestMixin: # truncate() accepts long objects self.assertEqual(memio.truncate(4L), 4) self.assertEqual(memio.getvalue(), buf[:4]) - self.assertEqual(memio.tell(), 4) + self.assertEqual(memio.tell(), 6) + memio.seek(0, 2) memio.write(buf) self.assertEqual(memio.getvalue(), buf[:4] + buf) pos = memio.tell() |
