MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_move

Method test_move

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

Source from the content-addressed store, hash-verified

361 offset=2147418112)
362
363 def test_move(self):
364 # make move works everywhere (64-bit format problem earlier)
365 with open(TESTFN, 'wb+') as f:
366
367 f.write(b"ABCDEabcde") # Arbitrary character
368 f.flush()
369
370 mf = mmap.mmap(f.fileno(), 10)
371 mf.move(5, 0, 5)
372 self.assertEqual(mf[:], b"ABCDEABCDE", "Map move should have duplicated front 5")
373 mf.close()
374
375 # more excessive test
376 data = b"0123456789"
377 for dest in range(len(data)):
378 for src in range(len(data)):
379 for count in range(len(data) - max(dest, src)):
380 expected = data[:dest] + data[src:src+count] + data[dest+count:]
381 m = mmap.mmap(-1, len(data))
382 m[:] = data
383 m.move(dest, src, count)
384 self.assertEqual(m[:], expected)
385 m.close()
386
387 # segfault test (Issue 5387)
388 m = mmap.mmap(-1, 100)
389 offsets = [-100, -1, 0, 1, 100]
390 for source, dest, size in itertools.product(offsets, offsets, offsets):
391 try:
392 m.move(source, dest, size)
393 except ValueError:
394 pass
395
396 offsets = [(-1, -1, -1), (-1, -1, 0), (-1, 0, -1), (0, -1, -1),
397 (-1, 0, 0), (0, -1, 0), (0, 0, -1)]
398 for source, dest, size in offsets:
399 self.assertRaises(ValueError, m.move, source, dest, size)
400
401 m.close()
402
403 m = mmap.mmap(-1, 1) # single byte
404 self.assertRaises(ValueError, m.move, 0, 0, 2)
405 self.assertRaises(ValueError, m.move, 1, 0, 1)
406 self.assertRaises(ValueError, m.move, 0, 1, 1)
407 m.move(0, 0, 1)
408 m.move(0, 0, 0)
409
410
411 def test_anonymous(self):

Callers

nothing calls this directly

Calls 10

lenFunction · 0.85
maxFunction · 0.85
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