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

Method test_move

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

Source from the content-addressed store, hash-verified

438 offset=2147418112)
439
440 def test_move(self):
441 # make move works everywhere (64-bit format problem earlier)
442 with open(TESTFN, 'wb+') as f:
443
444 f.write(b"ABCDEabcde") # Arbitrary character
445 f.flush()
446
447 mf = mmap.mmap(f.fileno(), 10)
448 mf.move(5, 0, 5)
449 self.assertEqual(mf[:], b"ABCDEABCDE", "Map move should have duplicated front 5")
450 mf.close()
451
452 # more excessive test
453 data = b"0123456789"
454 for dest in range(len(data)):
455 for src in range(len(data)):
456 for count in range(len(data) - max(dest, src)):
457 expected = data[:dest] + data[src:src+count] + data[dest+count:]
458 m = mmap.mmap(-1, len(data))
459 m[:] = data
460 m.move(dest, src, count)
461 self.assertEqual(m[:], expected)
462 m.close()
463
464 # segfault test (Issue 5387)
465 m = mmap.mmap(-1, 100)
466 offsets = [-100, -1, 0, 1, 100]
467 for source, dest, size in itertools.product(offsets, offsets, offsets):
468 try:
469 m.move(source, dest, size)
470 except ValueError:
471 pass
472
473 offsets = [(-1, -1, -1), (-1, -1, 0), (-1, 0, -1), (0, -1, -1),
474 (-1, 0, 0), (0, -1, 0), (0, 0, -1)]
475 for source, dest, size in offsets:
476 self.assertRaises(ValueError, m.move, source, dest, size)
477
478 m.close()
479
480 m = mmap.mmap(-1, 1) # single byte
481 self.assertRaises(ValueError, m.move, 0, 0, 2)
482 self.assertRaises(ValueError, m.move, 1, 0, 1)
483 self.assertRaises(ValueError, m.move, 0, 1, 1)
484 m.move(0, 0, 1)
485 m.move(0, 0, 0)
486
487 def test_anonymous(self):
488 # anonymous mmap.mmap(-1, PAGE)

Callers

nothing calls this directly

Calls 8

openFunction · 0.50
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45
moveMethod · 0.45
assertEqualMethod · 0.45
closeMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected