[Python-Dev] [Python-checkins] r84562 - in python/branches/py3k: Doc/library/io.rst Lib/_pyio.py Lib/test/test_memoryio.py Misc/NEWS Modules/_io/_iomodule.c Modules/_io/_iomodule.h Modules/_io/bytesio.c
Nick Coghlan
ncoghlan at gmail.com
Tue Sep 7 15:01:17 CEST 2010
On Tue, Sep 7, 2010 at 4:48 AM, antoine.pitrou
<python-checkins at python.org> wrote:
> Modified: python/branches/py3k/Lib/test/test_memoryio.py
> ==============================================================================
> --- python/branches/py3k/Lib/test/test_memoryio.py (original)
> +++ python/branches/py3k/Lib/test/test_memoryio.py Mon Sep 6 20:48:21 2010
> @@ -384,7 +384,31 @@
> del __main__.PickleTestMemIO
>
>
> -class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
> +class BytesIOMixin:
> +
> + def test_getbuffer(self):
> + memio = self.ioclass(b"1234567890")
> + buf = memio.getbuffer()
> + self.assertEqual(bytes(buf), b"1234567890")
> + memio.seek(5)
> + buf = memio.getbuffer()
> + self.assertEqual(bytes(buf), b"1234567890")
> + # Trying to change the size of the BytesIO while a buffer is exported
> + # raises a BufferError.
> + self.assertRaises(BufferError, memio.write, b'x' * 100)
> + self.assertRaises(BufferError, memio.truncate)
> + # Mutating the buffer updates the BytesIO
> + buf[3:6] = b"abc"
> + self.assertEqual(bytes(buf), b"123abc7890")
> + self.assertEqual(memio.getvalue(), b"123abc7890")
> + # After the buffer gets released, we can resize the BytesIO again
> + del buf
> + support.gc_collect()
> + memio.truncate()
I've raised an RFE (http://bugs.python.org/issue9789) to point out
that the need for that GC collect call in there to make the test
portable to other implementations is rather ugly and supporting an
explicit "buf.release()" call may be a nicer option. (And added Guido
to the nosy list, since he wasn't keen on supporting the context
management protocol idea, but I don't believe he said anything one way
or the other about an ordinary method).
> +class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin,
> + BytesIOMixin, unittest.TestCase):
I was going to ask why CBytesIOTest wasn't affected, but checking the
full source of the test file made everything clear :)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list