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

Method test_repr

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

Source from the content-addressed store, hash-verified

759 self.assertRaises(OSError, mm.flush, 1, len(b'python'))
760
761 def test_repr(self):
762 open_mmap_repr_pat = re.compile(
763 r"<mmap.mmap closed=False, "
764 r"access=(?P<access>\S+), "
765 r"length=(?P<length>\d+), "
766 r"pos=(?P<pos>\d+), "
767 r"offset=(?P<offset>\d+)>")
768 closed_mmap_repr_pat = re.compile(r"<mmap.mmap closed=True>")
769 mapsizes = (50, 100, 1_000, 1_000_000, 10_000_000)
770 offsets = tuple((mapsize // 2 // mmap.ALLOCATIONGRANULARITY)
771 * mmap.ALLOCATIONGRANULARITY for mapsize in mapsizes)
772 for offset, mapsize in zip(offsets, mapsizes):
773 data = b'a' * mapsize
774 length = mapsize - offset
775 accesses = ('ACCESS_DEFAULT', 'ACCESS_READ',
776 'ACCESS_COPY', 'ACCESS_WRITE')
777 positions = (0, length//10, length//5, length//4)
778 with open(TESTFN, "wb+") as fp:
779 fp.write(data)
780 fp.flush()
781 for access, pos in itertools.product(accesses, positions):
782 accint = getattr(mmap, access)
783 with mmap.mmap(fp.fileno(),
784 length,
785 access=accint,
786 offset=offset) as mm:
787 mm.seek(pos)
788 match = open_mmap_repr_pat.match(repr(mm))
789 self.assertIsNotNone(match)
790 self.assertEqual(match.group('access'), access)
791 self.assertEqual(match.group('length'), str(length))
792 self.assertEqual(match.group('pos'), str(pos))
793 self.assertEqual(match.group('offset'), str(offset))
794 match = closed_mmap_repr_pat.match(repr(mm))
795 self.assertIsNotNone(match)
796
797 @unittest.skipUnless(hasattr(mmap.mmap, 'madvise'), 'needs madvise')
798 def test_madvise(self):

Callers

nothing calls this directly

Calls 13

getattrFunction · 0.85
reprFunction · 0.85
strFunction · 0.85
assertIsNotNoneMethod · 0.80
openFunction · 0.50
compileMethod · 0.45
writeMethod · 0.45
flushMethod · 0.45
filenoMethod · 0.45
seekMethod · 0.45
matchMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected