]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
BZ2File.read(0) should return b"" rather than raising ValueError.
authorGuido van Rossum <guido@python.org>
Tue, 7 Aug 2007 23:29:20 +0000 (23:29 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 7 Aug 2007 23:29:20 +0000 (23:29 +0000)
This fixes test_tarfile.py.
I've added a unit test for the correct bz2 behavior.

Lib/test/test_bz2.py
Modules/bz2module.c

index 28af42e2631ef77d4668ea0f0b717f796956d0bf..06293f5265b1a242c6751bfe2c3058753c644bba 100644 (file)
@@ -65,6 +65,14 @@ class BZ2FileTest(BaseTest):
         self.assertEqual(bz2f.read(), self.TEXT)
         bz2f.close()
 
+    def testRead0(self):
+        # Test BBZ2File.read(0)"
+        self.createTempFile()
+        bz2f = BZ2File(self.filename)
+        self.assertRaises(TypeError, bz2f.read, None)
+        self.assertEqual(bz2f.read(0), b"")
+        bz2f.close()
+
     def testReadChunk10(self):
         # "Test BZ2File.read() in chunks of 10 bytes"
         self.createTempFile()
index ee2186eb1c5f2c8dcc64f49917f0f7856db7e8b0..954c9147c0b21a068a0341d0e09b93f36bc3f568 100644 (file)
@@ -431,7 +431,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
                goto cleanup;
        }
        ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
-       if (ret == NULL)
+       if (ret == NULL || buffersize == 0)
                goto cleanup;
        bytesread = 0;