Kaydet (Commit) bb9c7398 authored tarafından Walter Dörwald's avatar Walter Dörwald

Add error checks for the bz2, cStringIO and operator modules.

Add function names to various PyArg_ParseTuple calls in bz2module.c.
üst bc1d1b80
......@@ -24,12 +24,14 @@ class TestGenericStringIO(unittest.TestCase):
def test_reads(self):
eq = self.assertEqual
self.assertRaises(TypeError, self._fp.seek)
eq(self._fp.read(10), self._line[:10])
eq(self._fp.readline(), self._line[10:] + '\n')
eq(len(self._fp.readlines(60)), 2)
def test_writes(self):
f = self.MODULE.StringIO()
self.assertRaises(TypeError, f.seek)
f.write(self._line[:6])
f.seek(3)
f.write(self._line[20:26])
......
......@@ -59,6 +59,7 @@ class BZ2FileTest(BaseTest):
# "Test BZ2File.read()"
self.createTempFile()
bz2f = BZ2File(self.filename)
self.assertRaises(TypeError, bz2f.read, None)
self.assertEqual(bz2f.read(), self.TEXT)
bz2f.close()
......@@ -86,6 +87,7 @@ class BZ2FileTest(BaseTest):
# "Test BZ2File.readline()"
self.createTempFile()
bz2f = BZ2File(self.filename)
self.assertRaises(TypeError, bz2f.readline, None)
sio = StringIO(self.TEXT)
for line in sio.readlines():
self.assertEqual(bz2f.readline(), line)
......@@ -95,6 +97,7 @@ class BZ2FileTest(BaseTest):
# "Test BZ2File.readlines()"
self.createTempFile()
bz2f = BZ2File(self.filename)
self.assertRaises(TypeError, bz2f.readlines, None)
sio = StringIO(self.TEXT)
self.assertEqual(bz2f.readlines(), sio.readlines())
bz2f.close()
......@@ -134,6 +137,7 @@ class BZ2FileTest(BaseTest):
def testWrite(self):
# "Test BZ2File.write()"
bz2f = BZ2File(self.filename, "w")
self.assertRaises(TypeError, bz2f.write)
bz2f.write(self.TEXT)
bz2f.close()
f = open(self.filename, 'rb')
......@@ -158,6 +162,7 @@ class BZ2FileTest(BaseTest):
def testWriteLines(self):
# "Test BZ2File.writelines()"
bz2f = BZ2File(self.filename, "w")
self.assertRaises(TypeError, bz2f.writelines)
sio = StringIO(self.TEXT)
bz2f.writelines(sio.readlines())
bz2f.close()
......@@ -169,6 +174,7 @@ class BZ2FileTest(BaseTest):
# "Test BZ2File.seek(150, 0)"
self.createTempFile()
bz2f = BZ2File(self.filename)
self.assertRaises(TypeError, bz2f.seek)
bz2f.seek(150)
self.assertEqual(bz2f.read(), self.TEXT[150:])
bz2f.close()
......@@ -233,6 +239,7 @@ class BZ2CompressorTest(BaseTest):
def testCompress(self):
# "Test BZ2Compressor.compress()/flush()"
bz2c = BZ2Compressor()
self.assertRaises(TypeError, bz2c.compress)
data = bz2c.compress(self.TEXT)
data += bz2c.flush()
self.assertEqual(self.decompress(data), self.TEXT)
......@@ -252,9 +259,13 @@ class BZ2CompressorTest(BaseTest):
self.assertEqual(self.decompress(data), self.TEXT)
class BZ2DecompressorTest(BaseTest):
def test_Constructor(self):
self.assertRaises(TypeError, BZ2Decompressor, 42)
def testDecompress(self):
# "Test BZ2Decompressor.decompress()"
bz2d = BZ2Decompressor()
self.assertRaises(TypeError, bz2d.decompress)
text = bz2d.decompress(self.DATA)
self.assertEqual(text, self.TEXT)
......
This diff is collapsed.
......@@ -787,7 +787,7 @@ BZ2File_write(BZ2FileObject *self, PyObject *args)
int len;
int bzerror;
if (!PyArg_ParseTuple(args, "s#", &buf, &len))
if (!PyArg_ParseTuple(args, "s#:write", &buf, &len))
return NULL;
ACQUIRE_LOCK(self);
......@@ -1500,7 +1500,7 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
bz_stream *bzs = &self->bzs;
int bzerror;
if (!PyArg_ParseTuple(args, "s#", &data, &datasize))
if (!PyArg_ParseTuple(args, "s#:compress", &data, &datasize))
return NULL;
if (datasize == 0)
......@@ -1781,7 +1781,7 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args)
bz_stream *bzs = &self->bzs;
int bzerror;
if (!PyArg_ParseTuple(args, "s#", &data, &datasize))
if (!PyArg_ParseTuple(args, "s#:decompress", &data, &datasize))
return NULL;
ACQUIRE_LOCK(self);
......@@ -2069,7 +2069,7 @@ bz2_decompress(PyObject *self, PyObject *args)
bz_stream *bzs = &_bzs;
int bzerror;
if (!PyArg_ParseTuple(args, "s#", &data, &datasize))
if (!PyArg_ParseTuple(args, "s#:decompress", &data, &datasize))
return NULL;
if (datasize == 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment