diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-01-11 11:03:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-11 11:03:20 (GMT) |
commit | 0a2da50e1867831251fad75377d0f10713eb6301 (patch) | |
tree | 4a4f07b2488a4eed222060dc45a05430340a0ad3 /Lib/test | |
parent | cb3ae5588bd7733e76dc09277bb7626652d9bb64 (diff) | |
download | cpython-0a2da50e1867831251fad75377d0f10713eb6301.zip cpython-0a2da50e1867831251fad75377d0f10713eb6301.tar.gz cpython-0a2da50e1867831251fad75377d0f10713eb6301.tar.bz2 |
bpo-31993: Do not create frames for large bytes and str objects (#5114)
when serialize into memory buffer with C pickle implementations.
This optimization already is performed when serialize into memory
with Python pickle implementations or into a file with both
implementations.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/pickletester.py | 17 | ||||
-rw-r--r-- | Lib/test/test_pickle.py | 4 |
2 files changed, 11 insertions, 10 deletions
diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 5d983eb..f4e3f81 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -2097,20 +2097,21 @@ class AbstractPickleTests(unittest.TestCase): N = 1024 * 1024 obj = [b'x' * N, b'y' * N, 'z' * N] for proto in range(4, pickle.HIGHEST_PROTOCOL + 1): - for fast in [True, False]: + for fast in [False, True]: with self.subTest(proto=proto, fast=fast): - if hasattr(self, 'pickler'): + if not fast: + # fast=False by default. + # This covers in-memory pickling with pickle.dumps(). + pickled = self.dumps(obj, proto) + else: + # Pickler is required when fast=True. + if not hasattr(self, 'pickler'): + continue buf = io.BytesIO() pickler = self.pickler(buf, protocol=proto) pickler.fast = fast pickler.dump(obj) pickled = buf.getvalue() - elif fast: - continue - else: - # Fallback to self.dumps when fast=False and - # self.pickler is not available. - pickled = self.dumps(obj, proto) unpickled = self.loads(pickled) # More informative error message in case of failure. self.assertEqual([len(x) for x in obj], diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 895ed48..0051a01 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -71,8 +71,6 @@ class PyPicklerTests(AbstractPickleTests): class InMemoryPickleTests(AbstractPickleTests, AbstractUnpickleTests, BigmemPickleTests): - pickler = pickle._Pickler - unpickler = pickle._Unpickler bad_stack_errors = (pickle.UnpicklingError, IndexError) truncated_errors = (pickle.UnpicklingError, EOFError, AttributeError, ValueError, @@ -84,6 +82,8 @@ class InMemoryPickleTests(AbstractPickleTests, AbstractUnpickleTests, def loads(self, buf, **kwds): return pickle.loads(buf, **kwds) + test_framed_write_sizes_with_delayed_writer = None + class PersistentPicklerUnpicklerMixin(object): |