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

Method test_repr

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

Source from the content-addressed store, hash-verified

832 self.assertRaises(OSError, mm.flush, 1, len(b'python'))
833
834 def test_repr(self):
835 open_mmap_repr_pat = re.compile(
836 r"<mmap.mmap closed=False, "
837 r"access=(?P<access>\S+), "
838 r"length=(?P<length>\d+), "
839 r"pos=(?P<pos>\d+), "
840 r"offset=(?P<offset>\d+)>")
841 closed_mmap_repr_pat = re.compile(r"<mmap.mmap closed=True>")
842 mapsizes = (50, 100, 1_000, 1_000_000, 10_000_000)
843 offsets = tuple((mapsize // 2 // mmap.ALLOCATIONGRANULARITY)
844 * mmap.ALLOCATIONGRANULARITY for mapsize in mapsizes)
845 for offset, mapsize in zip(offsets, mapsizes):
846 data = b'a' * mapsize
847 length = mapsize - offset
848 accesses = ('ACCESS_DEFAULT', 'ACCESS_READ',
849 'ACCESS_COPY', 'ACCESS_WRITE')
850 positions = (0, length//10, length//5, length//4)
851 with open(TESTFN, "wb+") as fp:
852 fp.write(data)
853 fp.flush()
854 for access, pos in itertools.product(accesses, positions):
855 accint = getattr(mmap, access)
856 with mmap.mmap(fp.fileno(),
857 length,
858 access=accint,
859 offset=offset) as mm:
860 mm.seek(pos)
861 match = open_mmap_repr_pat.match(repr(mm))
862 self.assertIsNotNone(match)
863 self.assertEqual(match.group('access'), access)
864 self.assertEqual(match.group('length'), str(length))
865 self.assertEqual(match.group('pos'), str(pos))
866 self.assertEqual(match.group('offset'), str(offset))
867 match = closed_mmap_repr_pat.match(repr(mm))
868 self.assertIsNotNone(match)
869
870 @unittest.skipUnless(hasattr(mmap.mmap, 'madvise'), 'needs madvise')
871 def test_madvise(self):

Callers

nothing calls this directly

Calls 11

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
groupMethod · 0.45

Tested by

no test coverage detected