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

Method test_RawIOBase_read_bounds_checking

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

Source from the content-addressed store, hash-verified

594 self.assertEqual(rawio.read(2), b"")
595
596 def test_RawIOBase_read_bounds_checking(self):
597 # Make sure a `.readinto` call which returns a value outside
598 # (0, len(buffer)) raises.
599 class Misbehaved(self.io.RawIOBase):
600 def __init__(self, readinto_return) -> None:
601 self._readinto_return = readinto_return
602 def readinto(self, b):
603 return self._readinto_return
604
605 with self.assertRaises(ValueError) as cm:
606 Misbehaved(2).read(1)
607 self.assertEqual(str(cm.exception), "readinto returned 2 outside buffer size 1")
608 for bad_size in (2147483647, sys.maxsize, -1, -1000):
609 with self.assertRaises(ValueError):
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

Callers

nothing calls this directly

Calls 5

MisbehavedClass · 0.85
strFunction · 0.85
assertRaisesMethod · 0.45
readMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected