Re: [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
On Tue, Sep 7, 2010 at 4:48 AM, antoine.pitrou <python-checkins@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@gmail.com | Brisbane, Australia
On Tue, 7 Sep 2010 23:01:17 +1000 Nick Coghlan <ncoghlan@gmail.com> wrote:
+ # 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.
There was already an issue open for the context management option: http://bugs.python.org/issue9757 Regards Antoine.
On Tue, Sep 7, 2010 at 11:09 PM, Antoine Pitrou <solipsis@pitrou.net> wrote:
On Tue, 7 Sep 2010 23:01:17 +1000 Nick Coghlan <ncoghlan@gmail.com> wrote:
+ # 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.
There was already an issue open for the context management option: http://bugs.python.org/issue9757
Yeah, I didn't even think to check if you'd already put that up there. I've now closed 9789 as a duplicate of that issue. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
2010/9/7 Nick Coghlan <ncoghlan@gmail.com>:
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
Why? You're testing garbage collection, so you should call garbage collection. -- Regards, Benjamin
On Wed, Sep 8, 2010 at 3:39 AM, Benjamin Peterson <benjamin@python.org> wrote:
2010/9/7 Nick Coghlan <ncoghlan@gmail.com>:
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
Why? You're testing garbage collection, so you should call garbage collection.
Having that test *as well* as a specific release test (to check implicit as well as explicit release) is a different story (we do that for generators, files and assorted other things). Having forced GC invocation be the only way to do explicit release is the part I found ugly. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (3)
-
Antoine Pitrou -
Benjamin Peterson -
Nick Coghlan