diff -r 7757e98a9f3b Lib/test/test_gzip.py --- a/Lib/test/test_gzip.py Tue Mar 17 06:56:11 2015 +0200 +++ b/Lib/test/test_gzip.py Tue Mar 17 16:44:51 2015 +0100 @@ -130,6 +130,21 @@ if not ztxt: break self.assertEqual(contents, b'a'*201) + def test_memoryview_write(self): + # Test that write accepts a memoryview instead of bytes + # and that the data written equals memoryview.tobytes() + m = memoryview(data1 * 50) + with gzip.GzipFile(self.filename, 'wb') as f: + f.write(m) + with gzip.GzipFile(self.filename, 'rb') as f: + self.assertEqual(f.read(), data1 * 50) + m = memoryview(bytes(range(256))) + n = m.cast('B', shape=[8,8,4]) + with gzip.GzipFile(self.filename, 'wb') as f: + f.write(n) + with gzip.GzipFile(self.filename, 'rb') as f: + self.assertEqual(f.read(), m.tobytes()) + def test_exclusive_write(self): with gzip.GzipFile(self.filename, 'xb') as f: f.write(data1 * 50)