MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_last_known_tracking

Method test_last_known_tracking

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

Source from the content-addressed store, hash-verified

949 assert False
950
951 def test_last_known_tracking(self):
952 class Foo:
953 pass
954
955 instrumentation.register_class(Foo)
956 _register_attribute(Foo, "a", useobject=False)
957 _register_attribute(Foo, "b", useobject=False)
958 _register_attribute(Foo, "c", useobject=False)
959
960 f1 = Foo()
961 state = attributes.instance_state(f1)
962
963 f1.a = "a1"
964 f1.b = "b1"
965 f1.c = "c1"
966
967 assert not state._last_known_values
968
969 state._track_last_known_value("b")
970 state._track_last_known_value("c")
971
972 eq_(
973 state._last_known_values,
974 {"b": attributes.NO_VALUE, "c": attributes.NO_VALUE},
975 )
976
977 state._expire_attributes(state.dict, ["b"])
978 eq_(state._last_known_values, {"b": "b1", "c": attributes.NO_VALUE})
979
980 state._expire(state.dict, set())
981 eq_(state._last_known_values, {"b": "b1", "c": "c1"})
982
983 f1.b = "b2"
984
985 eq_(state._last_known_values, {"b": attributes.NO_VALUE, "c": "c1"})
986
987 f1.c = "c2"
988
989 eq_(
990 state._last_known_values,
991 {"b": attributes.NO_VALUE, "c": attributes.NO_VALUE},
992 )
993
994 state._expire(state.dict, set())
995 eq_(state._last_known_values, {"b": "b2", "c": "c2"})
996
997
998class GetNoValueTest(fixtures.ORMTest):

Callers

nothing calls this directly

Calls 6

eq_Function · 0.90
_expire_attributesMethod · 0.80
_expireMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70

Tested by

no test coverage detected