From 6bb91f3b6e51352f91bcf785d3f6fe160ed2cd85 Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Sat, 28 May 2016 00:41:57 +0000 Subject: =?UTF-8?q?Issue=20#20699:=20Document=20that=20=E2=80=9Cio?= =?UTF-8?q?=E2=80=9D=20methods=20accept=20bytes-like=20objects?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This matches the usage of ZipFile and BufferedWriter. This still requires return values to be bytes() objects. Also document and test that the write() methods should only access their argument before they return. --- Lib/test/test_memoryio.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'Lib/test/test_memoryio.py') diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index 812db4cfa8..55b693e564 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -399,7 +399,16 @@ class MemoryTestMixin: del __main__.PickleTestMemIO -class BytesIOMixin: +class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase): + # Test _pyio.BytesIO; class also inherited for testing C implementation + + UnsupportedOperation = pyio.UnsupportedOperation + + @staticmethod + def buftype(s): + return s.encode("ascii") + ioclass = pyio.BytesIO + EOF = b"" def test_getbuffer(self): memio = self.ioclass(b"1234567890") @@ -426,18 +435,6 @@ class BytesIOMixin: memio.close() self.assertRaises(ValueError, memio.getbuffer) - -class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, - BytesIOMixin, unittest.TestCase): - - UnsupportedOperation = pyio.UnsupportedOperation - - @staticmethod - def buftype(s): - return s.encode("ascii") - ioclass = pyio.BytesIO - EOF = b"" - def test_read1(self): buf = self.buftype("1234567890") memio = self.ioclass(buf) -- cgit v1.2.1