python-benedict/tests/dicts/io/test_pickle.py

32 lines
798 B
Python
Raw Normal View History

2020-01-07 15:00:06 +00:00
import pickle
import unittest
from benedict import benedict
2020-01-07 15:00:06 +00:00
class pickle_test_case(unittest.TestCase):
2022-02-13 10:35:43 +00:00
"""
This class describes a pickle test case.
"""
2020-01-07 15:00:06 +00:00
def test_pickle(self):
d = {
2022-02-13 10:35:43 +00:00
"a": {},
"b": {"x": 1},
"c": [],
"d": [0, 1],
"e": 0.0,
"f": "",
"g": None,
"h": "0",
2020-01-07 15:00:06 +00:00
}
2022-02-13 10:35:43 +00:00
b = benedict(d, keypath_separator="/")
2020-01-07 15:00:06 +00:00
b_encoded = pickle.dumps(b)
# print(b_encoded)
b_decoded = pickle.loads(b_encoded)
# print(b_decoded)
# print(b_decoded.keypath_separator)
self.assertTrue(isinstance(b_decoded, benedict))
self.assertEqual(b_decoded.keypath_separator, b.keypath_separator)
self.assertEqual(b_decoded, b)