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

Method test_RawIOBase_read_gh60107

Lib/test/test_io/test_general.py:612–629  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

610 Misbehaved(bad_size).read()
611
612 def test_RawIOBase_read_gh60107(self):
613 # gh-60107: Ensure a "Raw I/O" which keeps a reference to the
614 # mutable memory doesn't allow making a mutable bytes.
615 class RawIOKeepsReference(self.MockRawIOWithoutRead):
616 def __init__(self, *args, **kwargs):
617 self.buf = None
618 super().__init__(*args, **kwargs)
619
620 def readinto(self, buf):
621 # buf is the bytearray so keeping a reference to it doesn't keep
622 # the memory alive; a memoryview does.
623 self.buf = memoryview(buf)
624 buf[0:4] = self._read_stack.pop()
625 return 3
626
627 with self.assertRaises(BufferError):
628 rawio = RawIOKeepsReference([b"1234"])
629 rawio.read(4)
630
631 def test_types_have_dict(self):
632 test = (

Callers

nothing calls this directly

Calls 3

RawIOKeepsReferenceClass · 0.85
assertRaisesMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected