Repository navigation
Conversation
| for method in ("readinto", "readinto1"): | ||
| for buffer in (b"xxx", memoryview(b"xxx"), | ||
| b"", memoryview(b"")): |
There was a problem hiding this comment.
Use support.subTests() for parametrizing the method and buffer. It would be easier.
There was a problem hiding this comment.
Updated the test to use support.subTests() in 3831e0c, keeping all parameter combinations. The full test_io suite passes.
cmaloney
left a comment
There was a problem hiding this comment.
Overall looking good to me, I think the test should go a more general location for buffered I/O classes
| b"xxx", memoryview(b"xxx"), b"", memoryview(b""), | ||
| )) | ||
| @support.subTests("position", (0, 4, 10)) | ||
| def test_readinto_readonly_buffer(self, method, buffer, position): |
There was a problem hiding this comment.
I think this would fit better in test_bufferedio. Goal for me is to test all the Buffered I/O implementations readinto a readonly buffer doesn't advance. That the others implement it right already is nice, but a good thing to make sure we keep.
test_general IOTest would also work well as a spot but I don't like it quite as much just because it keeps adding to the big ball of general tests.
There was a problem hiding this comment.
Thanks! Added a shared test in BufferedReaderTest in f46989f, covering both BufferedReader and BufferedRandom in the C and Python implementations. It checks readinto and readinto1, readonly bytes and memoryviews, and both prefilled and unfilled read buffers. The test verifies that the failed call preserves the logical position and subsequent readable data. I retained the BytesIO regression test to cover the original bug directly.
The shared test uses nonempty targets with data remaining: the Python buffered readers currently return 0 for empty targets or at EOF, whereas the C implementations reject them. The existing BytesIO regression still covers those edge cases.
The full test_io suite passes (1,047 tests, 35 skipped).
Passing a read-only destination to
_pyio.BytesIO.readinto()orreadinto1()currently consumes input before raisingTypeError. The C implementation rejects the argument without moving the stream position. For example,readinto(b"xxx")on_pyio.BytesIO(b"abcdef")raises but leaves onlyb"def"unread.Check the destination memoryview's
readonlyflag inBufferedIOBase._readinto()before callingread()orread1(). This prevents the pure Python fallback from consuming input on an invalid destination.The shared C/Python BytesIO regression test covers both methods, bytes and read-only memoryviews, empty destinations, and initial positions at the beginning, near EOF, and beyond EOF. It checks both the position and the remaining input after the error.
Validation on a locally built Windows x64 debug CPython 3.16.0a0 at main
2639fd65ff8e0c1949c480a8e670fe9c2467a1f8:python_d.exe -m test -v test_io: 1,043 tests run, 35 skipped, success.git diff --checkpass.Linux and macOS validation has not been run locally.
Fixes #158952.