Exemple #1
0
    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')
Exemple #2
0
    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')
Exemple #3
0
    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')
Exemple #4
0
    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))
Exemple #5
0
    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')
Exemple #6
0
    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')
Exemple #7
0
    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')
Exemple #8
0
    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')
Exemple #9
0
    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')
Exemple #10
0
    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')
Exemple #11
0
    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))
Exemple #12
0
    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))