def test_size_adjusting1(self): """mmapped files must be at least PAGESIZE in size""" fn = os.path.join(self.path, 'mmstats-test_size_adjusting-1') _, sz, m = _mmap.init_mmap(fn, size=1) self.assertEqual(sz, _mmap.PAGESIZE) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m + i).value, '\x00')
def test_size_adjusting2(self): """mmapped files must be multiples of PAGESIZE""" fn = os.path.join(self.path, 'mmstats-test_size_adjusting-2') _, sz, m = _mmap.init_mmap(fn, size=(_mmap.PAGESIZE + 1)) self.assertEqual(sz, _mmap.PAGESIZE * 2) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m + i).value, '\x00')
def test_size_adjusting1(self): """mmapped files must be at least PAGESIZE in size""" _, _, sz, m = _mmap.init_mmap(path=self.path, filename='mmstats-test_size_adjusting-1', size=1) self.assertEqual(sz, _mmap.PAGESIZE) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m+i).value, '\x00')
def test_init_alt_name(self): expected_fn = os.path.join(self.path, 'mmstats-test_init_alt_name') self.assertFalse(os.path.exists(expected_fn)) _, fn, sz, m = _mmap.init_mmap( path=self.path, filename='mmstats-test_init_alt_name') self.assertEqual(fn, expected_fn) self.assertTrue(os.path.exists(fn))
def test_size_adjusting2(self): """mmapped files must be multiples of PAGESIZE""" fn = os.path.join(self.path, 'test_size_adjusting-2.mmstats') _, sz, m = _mmap.init_mmap(fn, size=(_mmap.PAGESIZE + 1)) self.assertEqual(sz, _mmap.PAGESIZE * 2) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m+i).value, '\x00')
def test_size_adjusting1(self): """mmapped files must be at least PAGESIZE in size""" fn = os.path.join(self.path, 'test_size_adjusting-1.mmstats') _, sz, m = _mmap.init_mmap(fn, size=1) self.assertEqual(sz, _mmap.PAGESIZE) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m+i).value, '\x00')
def test_truncate(self): """mmapped files must be initialized with null bytes""" fn = os.path.join(self.path, 'mmstats-test_truncate') _, sz, m = _mmap.init_mmap(fn) first_byte = ctypes.c_char.from_address(m) first_byte.value = 'X' reopened_file = open(fn) self.assertEqual(reopened_file.read(1), 'X') self.assertEqual(reopened_file.read(1), '\x00')
def test_size_adjusting2(self): """mmapped files must be multiples of PAGESIZE""" _, _, sz, m = _mmap.init_mmap( path=self.path, filename='mmstats-test_size_adjusting-2', size=(_mmap.PAGESIZE + 1) ) self.assertEqual(sz, _mmap.PAGESIZE * 2) for i in range(sz): self.assertEqual(ctypes.c_char.from_address(m+i).value, '\x00')
def test_truncate(self): """mmapped files must be initialized with null bytes""" fn = os.path.join(self.path, 'test_truncate.mmstats') _, sz, m = _mmap.init_mmap(fn) first_byte = ctypes.c_char.from_address(m) first_byte.value = 'X' reopened_file = open(fn) self.assertEqual(reopened_file.read(1), 'X') self.assertEqual(reopened_file.read(1), '\x00')
def test_truncate(self): """mmapped files must be initialized with null bytes""" _, fn, sz, m = _mmap.init_mmap( path=self.path, filename='mmstats-test_truncate', ) first_byte = ctypes.c_char.from_address(m) first_byte.value = 'X' reopened_file = open(fn) self.assertEqual(reopened_file.read(1), 'X') self.assertEqual(reopened_file.read(1), '\x00')
def test_mmap_creation(self): expected_fn = os.path.join(self.path, 'mmstats-test_init_alt_name') self.assertFalse(os.path.exists(expected_fn)) _, sz, m = _mmap.init_mmap(expected_fn) self.assertTrue(os.path.exists(expected_fn))
def test_mmap_creation(self): expected_fn = os.path.join(self.path, 'test_init_alt_name.mmstats') self.assertFalse(os.path.exists(expected_fn)) _, sz, m = _mmap.init_mmap(expected_fn) self.assertTrue(os.path.exists(expected_fn))