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

Method test_resize

Lib/test/test_mmap.py:120–140  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

118
119 @unittest.skipUnless(hasattr(mmap.mmap, 'resize'), 'requires mmap.resize')
120 def test_resize(self):
121 # Create a file to be mmap'ed.
122 with open(TESTFN, 'bw+') as f:
123 # Write 2 pages worth of data to the file
124 f.write(b'\0'* 2 * PAGESIZE)
125 f.flush()
126 m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
127 self.addCleanup(m.close)
128
129 # Try resizing map
130 m.resize(512)
131 self.assertEqual(len(m), 512)
132 # Check that we can no longer seek beyond the new size.
133 self.assertRaises(ValueError, m.seek, 513, 0)
134
135 # Check that the underlying file is truncated too
136 # (bug #728515)
137 with open(TESTFN, 'rb') as f:
138 f.seek(0, 2)
139 self.assertEqual(f.tell(), 512)
140 self.assertEqual(m.size(), 512)
141
142 def test_access_parameter(self):
143 # Test for "access" keyword parameter

Callers

nothing calls this directly

Calls 11

addCleanupMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45
resizeMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45
seekMethod · 0.45
tellMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected