MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_helpers

Method test_helpers

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

Source from the content-addressed store, hash-verified

1065
1066class UtilTest(fixtures.ORMTest):
1067 def test_helpers(self):
1068 class Foo:
1069 pass
1070
1071 class Bar:
1072 pass
1073
1074 instrumentation.register_class(Foo)
1075 instrumentation.register_class(Bar)
1076 _register_attribute(Foo, "coll", uselist=True, useobject=True)
1077
1078 f1 = Foo()
1079 b1 = Bar()
1080 b2 = Bar()
1081 coll = attributes.init_collection(f1, "coll")
1082 assert coll.data is f1.coll
1083 assert attributes.get_attribute(f1, "coll") is f1.coll
1084 attributes.set_attribute(f1, "coll", [b1])
1085 assert f1.coll == [b1]
1086 eq_(attributes.get_history(f1, "coll"), ([b1], [], []))
1087 attributes.set_committed_value(f1, "coll", [b2])
1088 eq_(attributes.get_history(f1, "coll"), ((), [b2], ()))
1089
1090 attributes.del_attribute(f1, "coll")
1091 assert "coll" not in f1.__dict__
1092
1093 def test_set_committed_value_none_uselist(self):
1094 """test that set_committed_value->None to a uselist generates an

Callers

nothing calls this directly

Calls 7

eq_Function · 0.90
init_collectionMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70
BarClass · 0.70
get_historyMethod · 0.45
set_committed_valueMethod · 0.45

Tested by

no test coverage detected