MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_truncate_after_write

Method test_truncate_after_write

Lib/test/test_io.py:2059–2075  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2057 self.assertEqual(f.read(), b"abc")
2058
2059 def test_truncate_after_write(self):
2060 # Ensure that truncate preserves the file position after
2061 # writes longer than the buffer size.
2062 # Issue: https://bugs.python.org/issue32228
2063 self.addCleanup(os_helper.unlink, os_helper.TESTFN)
2064 with self.open(os_helper.TESTFN, "wb") as f:
2065 # Fill with some buffer
2066 f.write(b'\x00' * 10000)
2067 buffer_sizes = [8192, 4096, 200]
2068 for buffer_size in buffer_sizes:
2069 with self.open(os_helper.TESTFN, "r+b", buffering=buffer_size) as f:
2070 f.write(b'\x00' * (buffer_size + 1))
2071 # After write write_pos and write_end are set to 0
2072 f.read(1)
2073 # read operation makes sure that pos != raw_pos
2074 f.truncate()
2075 self.assertEqual(f.tell(), buffer_size + 2)
2076
2077 @threading_helper.requires_working_threading()
2078 @support.requires_resource('cpu')

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected