MCPcopy Index your code
hub / github.com/python/cpython / test_truncate

Method test_truncate

Lib/test/test_io/test_bufferedio.py:831–840  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

829 self.assertEqual(b"abc", writer._write_stack[0])
830
831 def test_truncate(self):
832 # Truncate implicitly flushes the buffer.
833 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
834 with self.open(os_helper.TESTFN, self.write_mode, buffering=0) as raw:
835 bufio = self.tp(raw, 8)
836 bufio.write(b"abcdef")
837 self.assertEqual(bufio.truncate(3), 3)
838 self.assertEqual(bufio.tell(), 6)
839 with self.open(os_helper.TESTFN, "rb", buffering=0) as f:
840 self.assertEqual(f.read(), b"abc")
841
842 def test_truncate_after_write(self):
843 # Ensure that truncate preserves the file position after

Callers

nothing calls this directly

Calls 7

addCleanupMethod · 0.80
openMethod · 0.45
writeMethod · 0.45
assertEqualMethod · 0.45
truncateMethod · 0.45
tellMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected