summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 20:35:23 (GMT)
committerNadeem Vawda <nadeem.vawda@gmail.com>2013-10-28 20:35:23 (GMT)
commit3797065ac55997741fd625a30a8308c04ee5c9b9 (patch)
treecf67e5dabe3bfcab16f64afa5118fd8b207c6da6 /Lib/test
parentba4e58a02172df294f16c68f0b0c4ac80184e4b0 (diff)
downloadcpython-3797065ac55997741fd625a30a8308c04ee5c9b9.zip
cpython-3797065ac55997741fd625a30a8308c04ee5c9b9.tar.gz
cpython-3797065ac55997741fd625a30a8308c04ee5c9b9.tar.bz2
#19395: Raise exception when pickling a (BZ2|LZMA)(Compressor|Decompressor).
The underlying C libraries provide no mechanism for serializing compressor and decompressor objects, so actually pickling these classes is impractical. Previously, these objects would be pickled without error, but attempting to use a deserialized instance would segfault the interpreter.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_bz2.py10
-rw-r--r--Lib/test/test_lzma.py9
2 files changed, 19 insertions, 0 deletions
diff --git a/Lib/test/test_bz2.py b/Lib/test/test_bz2.py
index 912fac1..6764e59 100644
--- a/Lib/test/test_bz2.py
+++ b/Lib/test/test_bz2.py
@@ -5,6 +5,7 @@ from test.support import TESTFN, bigmemtest, _4G
import unittest
from io import BytesIO
import os
+import pickle
import random
import subprocess
import sys
@@ -621,6 +622,11 @@ class BZ2CompressorTest(BaseTest):
finally:
data = None
+ def testPickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(BZ2Compressor())
+
+
class BZ2DecompressorTest(BaseTest):
def test_Constructor(self):
self.assertRaises(TypeError, BZ2Decompressor, 42)
@@ -672,6 +678,10 @@ class BZ2DecompressorTest(BaseTest):
compressed = None
decompressed = None
+ def testPickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(BZ2Decompressor())
+
class CompressDecompressTest(BaseTest):
def testCompress(self):
diff --git a/Lib/test/test_lzma.py b/Lib/test/test_lzma.py
index a13cf3b..ad90456 100644
--- a/Lib/test/test_lzma.py
+++ b/Lib/test/test_lzma.py
@@ -1,5 +1,6 @@
from io import BytesIO, UnsupportedOperation
import os
+import pickle
import random
import unittest
@@ -216,6 +217,14 @@ class CompressorDecompressorTestCase(unittest.TestCase):
finally:
input = cdata = ddata = None
+ # Pickling raises an exception; there's no way to serialize an lzma_stream.
+
+ def test_pickle(self):
+ with self.assertRaises(TypeError):
+ pickle.dumps(LZMACompressor())
+ with self.assertRaises(TypeError):
+ pickle.dumps(LZMADecompressor())
+
class CompressDecompressFunctionTestCase(unittest.TestCase):