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

Method test_offset

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

Source from the content-addressed store, hash-verified

501 access=mmap.ACCESS_READ)
502
503 def test_offset (self):
504 f = open (TESTFN, 'w+b')
505
506 try: # unlink TESTFN no matter what
507 halfsize = mmap.ALLOCATIONGRANULARITY
508 m = self.make_mmap_file (f, halfsize)
509 m.close ()
510 f.close ()
511
512 mapsize = halfsize * 2
513 # Try invalid offset
514 f = open(TESTFN, "r+b")
515 for offset in [-2, -1, None]:
516 try:
517 m = mmap.mmap(f.fileno(), mapsize, offset=offset)
518 self.assertEqual(0, 1)
519 except (ValueError, TypeError, OverflowError):
520 pass
521 else:
522 self.assertEqual(0, 0)
523 f.close()
524
525 # Try valid offset, hopefully 8192 works on all OSes
526 f = open(TESTFN, "r+b")
527 m = mmap.mmap(f.fileno(), mapsize - halfsize, offset=halfsize)
528 self.assertEqual(m[0:3], b'foo')
529 f.close()
530
531 # Try resizing map
532 try:
533 m.resize(512)
534 except SystemError:
535 pass
536 else:
537 # resize() is supported
538 self.assertEqual(len(m), 512)
539 # Check that we can no longer seek beyond the new size.
540 self.assertRaises(ValueError, m.seek, 513, 0)
541 # Check that the content is not changed
542 self.assertEqual(m[0:3], b'foo')
543
544 # Check that the underlying file is truncated too
545 f = open(TESTFN, 'rb')
546 f.seek(0, 2)
547 self.assertEqual(f.tell(), halfsize + 512)
548 f.close()
549 self.assertEqual(m.size(), halfsize + 512)
550
551 m.close()
552
553 finally:
554 f.close()
555 try:
556 os.unlink(TESTFN)
557 except OSError:
558 pass
559
560 def test_subclass(self):

Callers

nothing calls this directly

Calls 12

make_mmap_fileMethod · 0.95
lenFunction · 0.85
openFunction · 0.50
closeMethod · 0.45
filenoMethod · 0.45
assertEqualMethod · 0.45
resizeMethod · 0.45
assertRaisesMethod · 0.45
seekMethod · 0.45
tellMethod · 0.45
sizeMethod · 0.45
unlinkMethod · 0.45

Tested by

no test coverage detected