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

Method test_getbuffer

Lib/test/test_io/test_memoryio.py:449–472  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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()

Callers

nothing calls this directly

Calls 9

assertFalseMethod · 0.80
ioclassMethod · 0.45
getbufferMethod · 0.45
assertEqualMethod · 0.45
seekMethod · 0.45
assertRaisesMethod · 0.45
getvalueMethod · 0.45
truncateMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected