MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_initiator_arg

Method test_initiator_arg

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

Source from the content-addressed store, hash-verified

1115 eq_(f1.col_set, set())
1116
1117 def test_initiator_arg(self):
1118 class Foo:
1119 pass
1120
1121 class Bar:
1122 pass
1123
1124 instrumentation.register_class(Foo)
1125 instrumentation.register_class(Bar)
1126 _register_attribute(Foo, "a", uselist=False, useobject=False)
1127 _register_attribute(Bar, "b", uselist=False, useobject=False)
1128
1129 @event.listens_for(Foo.a, "set")
1130 def sync_a(target, value, oldvalue, initiator):
1131 parentclass = initiator.parent_token.class_
1132 if parentclass is Foo:
1133 attributes.set_attribute(target.bar, "b", value, initiator)
1134
1135 @event.listens_for(Bar.b, "set")
1136 def sync_b(target, value, oldvalue, initiator):
1137 parentclass = initiator.parent_token.class_
1138 if parentclass is Bar:
1139 attributes.set_attribute(target.foo, "a", value, initiator)
1140
1141 f1 = Foo()
1142 b1 = Bar()
1143 f1.bar = b1
1144 b1.foo = f1
1145
1146 f1.a = "x"
1147 eq_(b1.b, "x")
1148 b1.b = "y"
1149 eq_(f1.a, "y")
1150
1151
1152class BackrefTest(fixtures.ORMTest):

Callers

nothing calls this directly

Calls 4

eq_Function · 0.90
_register_attributeFunction · 0.70
FooClass · 0.70
BarClass · 0.70

Tested by

no test coverage detected