(self)
| 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 |
nothing calls this directly
no test coverage detected