MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_pickle

Method test_pickle

test/test_binary.py:237–260  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

235 self.assertEqual(data, encoded)
236
237 def test_pickle(self):
238 b1 = Binary(b"123", 2)
239
240 # For testing backwards compatibility with pre-2.4 pymongo
241 p = (
242 b"\x80\x03cbson.binary\nBinary\nq\x00C\x03123q\x01\x85q"
243 b"\x02\x81q\x03}q\x04X\x10\x00\x00\x00_Binary__subtypeq"
244 b"\x05K\x02sb."
245 )
246
247 if not sys.version.startswith("3.0"):
248 self.assertEqual(b1, pickle.loads(p))
249
250 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
251 self.assertEqual(b1, pickle.loads(pickle.dumps(b1, proto)))
252
253 uu = uuid.uuid4()
254 uul = Binary.from_uuid(uu, UuidRepresentation.PYTHON_LEGACY)
255
256 self.assertEqual(uul, copy.copy(uul))
257 self.assertEqual(uul, copy.deepcopy(uul))
258
259 for proto in range(pickle.HIGHEST_PROTOCOL + 1):
260 self.assertEqual(uul, pickle.loads(pickle.dumps(uul, proto)))
261
262 def test_buffer_protocol(self):
263 b0 = Binary(b"123", 2)

Callers

nothing calls this directly

Calls 3

BinaryClass · 0.85
from_uuidMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected