-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify our unpickling logic and add tests for Python 2 pickles
- Loading branch information
1 parent
4a2fc47
commit c54bebe
Showing
4 changed files
with
170 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
python/tests/unit/arcticdb/version_store/pickles_generation/python2_pickles.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""How some of the Python 2 pickles in test_normalization.py were created. | ||
Executed from a Python 2 env with msgpack 0.6.2 | ||
""" | ||
from email import errors # arbitrary module with some custom types to pickle | ||
import pickle | ||
import msgpack | ||
import sys | ||
|
||
major_version = sys.version[0] | ||
|
||
|
||
def custom_pack(obj): | ||
# 102 is our extension code for pickled in Python 2 | ||
return msgpack.ExtType(102, msgpack.packb(pickle.dumps(obj))) | ||
|
||
|
||
def msgpack_packb(obj): | ||
return msgpack.packb(obj, use_bin_type=True, strict_types=True, default=custom_pack) | ||
|
||
|
||
obj = errors.BoundaryError("bananas") | ||
title = "py" + major_version + "_obj.bin" | ||
with open(title, "wb") as f: | ||
msgpack.dump(obj, f, default=custom_pack) | ||
|
||
obj = {"dict_key": errors.BoundaryError("bananas")} | ||
title = "py" + major_version + "_dict.bin" | ||
with open(title, "wb") as f: | ||
msgpack.dump(obj, f, default=custom_pack) | ||
|
||
obj = "my_string" | ||
title = "py" + major_version + "_str.bin" | ||
with open(title, "wb") as f: | ||
msgpack.dump(obj, f, default=custom_pack) | ||
|
||
obj = b"my_bytes" | ||
title = "py" + major_version + "_str_bytes.bin" | ||
with open(title, "wb") as f: | ||
msgpack.dump(obj, f, default=custom_pack) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters