MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_inheritance2

Method test_inheritance2

test/orm/test_attributes.py:738–769  ·  view source on GitHub ↗

test that the attribute manager can properly traverse the managed attributes of an object, if the object is of a descendant class with managed attributes in the parent class

(self)

Source from the content-addressed store, hash-verified

736 eq_(list(states)[0].obj(), b)
737
738 def test_inheritance2(self):
739 """test that the attribute manager can properly traverse the
740 managed attributes of an object, if the object is of a
741 descendant class with managed attributes in the parent class"""
742
743 class Foo:
744 pass
745
746 class Bar(Foo):
747 pass
748
749 class Element:
750 _state = True
751
752 instrumentation.register_class(Foo)
753 instrumentation.register_class(Bar)
754 _register_attribute(Foo, "element", uselist=False, useobject=True)
755 el = Element()
756 x = Bar()
757 x.element = el
758 eq_(
759 attributes.get_state_history(
760 attributes.instance_state(x), "element"
761 ),
762 ([el], (), ()),
763 )
764 attributes.instance_state(x)._commit_all(attributes.instance_dict(x))
765 added, unchanged, deleted = attributes.get_state_history(
766 attributes.instance_state(x), "element"
767 )
768 assert added == ()
769 assert unchanged == [el]
770
771 def test_lazyhistory(self):
772 """tests that history functions work with lazy-loading attributes"""

Callers

nothing calls this directly

Calls 5

eq_Function · 0.90
_commit_allMethod · 0.80
_register_attributeFunction · 0.70
ElementClass · 0.70
BarClass · 0.70

Tested by

no test coverage detected