MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_lazyhistory

Method test_lazyhistory

test/orm/test_attributes.py:771–803  ·  view source on GitHub ↗

tests that history functions work with lazy-loading attributes

(self)

Source from the content-addressed store, hash-verified

769 assert unchanged == [el]
770
771 def test_lazyhistory(self):
772 """tests that history functions work with lazy-loading attributes"""
773
774 class Foo(BasicEntity):
775 pass
776
777 class Bar(BasicEntity):
778 pass
779
780 instrumentation.register_class(Foo)
781 instrumentation.register_class(Bar)
782 bar1, bar2, bar3, bar4 = [Bar(id=1), Bar(id=2), Bar(id=3), Bar(id=4)]
783
784 def func1(state, passive):
785 return "this is func 1"
786
787 def func2(state, passive):
788 return [bar1, bar2, bar3]
789
790 _register_attribute(
791 Foo, "col1", uselist=False, callable_=func1, useobject=True
792 )
793 _register_attribute(
794 Foo, "col2", uselist=True, callable_=func2, useobject=True
795 )
796 _register_attribute(Bar, "id", uselist=False, useobject=True)
797 x = Foo()
798 attributes.instance_state(x)._commit_all(attributes.instance_dict(x))
799 x.col2.append(bar4)
800 eq_(
801 attributes.get_state_history(attributes.instance_state(x), "col2"),
802 ([bar4], [bar1, bar2, bar3], []),
803 )
804
805 def test_parenttrack(self):
806 class Foo:

Callers

nothing calls this directly

Calls 6

eq_Function · 0.90
_commit_allMethod · 0.80
BarClass · 0.70
_register_attributeFunction · 0.70
FooClass · 0.70
appendMethod · 0.45

Tested by

no test coverage detected