mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
BZ2File.read(0) should return b"" rather than raising ValueError.
This fixes test_tarfile.py. I've added a unit test for the correct bz2 behavior.
This commit is contained in:
parent
a05577059d
commit
75c26bc6a7
2 changed files with 9 additions and 1 deletions
|
@ -65,6 +65,14 @@ class BZ2FileTest(BaseTest):
|
||||||
self.assertEqual(bz2f.read(), self.TEXT)
|
self.assertEqual(bz2f.read(), self.TEXT)
|
||||||
bz2f.close()
|
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):
|
def testReadChunk10(self):
|
||||||
# "Test BZ2File.read() in chunks of 10 bytes"
|
# "Test BZ2File.read() in chunks of 10 bytes"
|
||||||
self.createTempFile()
|
self.createTempFile()
|
||||||
|
|
|
@ -431,7 +431,7 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
|
ret = PyBytes_FromStringAndSize((char *)NULL, buffersize);
|
||||||
if (ret == NULL)
|
if (ret == NULL || buffersize == 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
bytesread = 0;
|
bytesread = 0;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue