(self)
| 447 | EOF = b"" |
| 448 | |
| 449 | def test_getbuffer(self): |
| 450 | memio = self.ioclass(b"1234567890") |
| 451 | buf = memio.getbuffer() |
| 452 | self.assertEqual(bytes(buf), b"1234567890") |
| 453 | memio.seek(5) |
| 454 | buf = memio.getbuffer() |
| 455 | self.assertEqual(bytes(buf), b"1234567890") |
| 456 | # Trying to change the size of the BytesIO while a buffer is exported |
| 457 | # raises a BufferError. |
| 458 | self.assertRaises(BufferError, memio.write, b'x' * 100) |
| 459 | self.assertRaises(BufferError, memio.truncate) |
| 460 | self.assertRaises(BufferError, memio.close) |
| 461 | self.assertFalse(memio.closed) |
| 462 | # Mutating the buffer updates the BytesIO |
| 463 | buf[3:6] = b"abc" |
| 464 | self.assertEqual(bytes(buf), b"123abc7890") |
| 465 | self.assertEqual(memio.getvalue(), b"123abc7890") |
| 466 | # After the buffer gets released, we can resize and close the BytesIO |
| 467 | # again |
| 468 | del buf |
| 469 | support.gc_collect() |
| 470 | memio.truncate() |
| 471 | memio.close() |
| 472 | self.assertRaises(ValueError, memio.getbuffer) |
| 473 | |
| 474 | def test_getbuffer_empty(self): |
| 475 | memio = self.ioclass() |
nothing calls this directly
no test coverage detected