MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_deferred_pickleable

Method test_deferred_pickleable

test/orm/test_attributes.py:505–527  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

503 eq_(f.b, 12)
504
505 def test_deferred_pickleable(self):
506 data = {"a": "this is a", "b": 12}
507
508 def loader(state, keys, passive):
509 for k in keys:
510 state.dict[k] = data[k]
511 return attributes.ATTR_WAS_SET
512
513 instrumentation.register_class(MyTest)
514 manager = attributes.manager_of_class(MyTest)
515 manager.expired_attribute_loader = loader
516 _register_attribute(MyTest, "a", uselist=False, useobject=False)
517 _register_attribute(MyTest, "b", uselist=False, useobject=False)
518
519 m = MyTest()
520 attributes.instance_state(m)._expire(
521 attributes.instance_dict(m), set()
522 )
523 assert "a" not in m.__dict__
524 m2 = pickle.loads(pickle.dumps(m))
525 assert "a" not in m2.__dict__
526 eq_(m2.a, "this is a")
527 eq_(m2.b, 12)
528
529 def test_list(self):
530 class User:

Callers

nothing calls this directly

Calls 7

eq_Function · 0.90
MyTestClass · 0.85
manager_of_classMethod · 0.80
_expireMethod · 0.80
_register_attributeFunction · 0.70
loadsMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected