Skip to content

Commit af73f20

Browse files
committed
Split BytesIO.close test for _pyio and _io
1 parent 9e3dd1a commit af73f20

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

Lib/test/test_io/test_memoryio.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,9 @@ def test_getbuffer(self):
457457
# raises a BufferError.
458458
self.assertRaises(BufferError, memio.write, b'x' * 100)
459459
self.assertRaises(BufferError, memio.truncate)
460-
self.assertRaises(BufferError, memio.close)
460+
# gh-111049: _io.BytesIO detach on close would lead to corruption.
461+
if self.ioclass is io.BytesIO:
462+
self.assertRaises(BufferError, memio.close)
461463
self.assertFalse(memio.closed)
462464
# Mutating the buffer updates the BytesIO
463465
buf[3:6] = b"abc"
@@ -471,6 +473,23 @@ def test_getbuffer(self):
471473
memio.close()
472474
self.assertRaises(ValueError, memio.getbuffer)
473475

476+
def test_getbuffer_delete(self):
477+
# gh-111330: _pyio .close() works and the buffer stays working
478+
if self.ioclass is io.BytesIO:
479+
# gh-111049: _io.BytesIO detach on close would lead to corruption.
480+
# gh-111331: It would be nice to support this.
481+
self.skipTest("io.BytesIO does not support, gh-111049")
482+
483+
memio = self.ioclass(b"1234567890")
484+
buf = memio.getbuffer()
485+
self.assertEqual(bytes(buf), b"1234567890")
486+
memio.close()
487+
self.assertTrue(memio.closed)
488+
self.assertEqual(bytes(buf), b"1234567890")
489+
buf[3:6] = b"abc"
490+
self.assertEqual(bytes(buf), b"123abc7890")
491+
self.assertRaises(ValueError, memio.getbuffer)
492+
474493
def test_getbuffer_empty(self):
475494
memio = self.ioclass()
476495
buf = memio.getbuffer()

0 commit comments

Comments
 (0)