MCPcopy
hub / github.com/dask/dask / test_pickle

Function test_pickle

dask/tests/test_task_spec.py:249–285  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

247
248
249def test_pickle():
250
251 def assert_slots_equal(a, b):
252 def get_all_slots(obj):
253 slots = set()
254 for cls in obj.__class__.mro():
255 slots.update(getattr(cls, "__slots__", ()))
256 return slots
257
258 all_slots = get_all_slots(a) | get_all_slots(a)
259 assert all_slots == get_all_slots(a) == get_all_slots(a)
260 assert all(getattr(a, slot) == getattr(b, slot) for slot in all_slots)
261 assert not hasattr(a, "__dict__")
262 assert not hasattr(b, "__dict__")
263
264 t1 = Task("key-1", func, "a", "b")
265 t2 = Task("key-2", func, "c", "d")
266
267 rtt1 = pickle.loads(pickle.dumps(t1))
268 assert repr(rtt1) == repr(t1)
269 rtt2 = pickle.loads(pickle.dumps(t2))
270
271 assert_slots_equal(t1, rtt1)
272 assert_slots_equal(t2, rtt2)
273 assert t1 == rtt1
274 assert t1.func == rtt1.func
275 assert t1.func is rtt1.func
276 assert t1.func is rtt2.func
277
278 l = Tuple(t1, t2)
279 rtl = pickle.loads(pickle.dumps(l))
280 assert l == rtl
281 assert l() == rtl()
282 d = Dict(key=t1)
283 rtd = pickle.loads(pickle.dumps(d))
284 assert d == rtd
285 assert d() == rtd()
286
287
288def test_pickle_size():

Callers

nothing calls this directly

Calls 4

TaskClass · 0.90
TupleClass · 0.90
DictClass · 0.90
assert_slots_equalFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…