(self)
| 1211 | assert a1.b_single is None |
| 1212 | |
| 1213 | def test_custom_getset(self): |
| 1214 | metadata = MetaData() |
| 1215 | p = Table( |
| 1216 | "p", |
| 1217 | metadata, |
| 1218 | Column("id", Integer, primary_key=True), |
| 1219 | Column("cid", Integer, ForeignKey("c.id")), |
| 1220 | ) |
| 1221 | c = Table( |
| 1222 | "c", |
| 1223 | metadata, |
| 1224 | Column("id", Integer, primary_key=True), |
| 1225 | Column("foo", String(128)), |
| 1226 | ) |
| 1227 | |
| 1228 | get = Mock() |
| 1229 | set_ = Mock() |
| 1230 | |
| 1231 | class Parent: |
| 1232 | foo = association_proxy( |
| 1233 | "child", "foo", getset_factory=lambda cc, parent: (get, set_) |
| 1234 | ) |
| 1235 | |
| 1236 | class Child: |
| 1237 | def __init__(self, foo): |
| 1238 | self.foo = foo |
| 1239 | |
| 1240 | self.mapper_registry.map_imperatively( |
| 1241 | Parent, p, properties={"child": relationship(Child)} |
| 1242 | ) |
| 1243 | self.mapper_registry.map_imperatively(Child, c) |
| 1244 | |
| 1245 | p1 = Parent() |
| 1246 | |
| 1247 | eq_(p1.foo, get(None)) |
| 1248 | p1.child = child = Child(foo="x") |
| 1249 | eq_(p1.foo, get(child)) |
| 1250 | p1.foo = "y" |
| 1251 | eq_(set_.mock_calls, [call(child, "y")]) |
| 1252 | |
| 1253 | |
| 1254 | class LazyLoadTest(fixtures.MappedTest): |
nothing calls this directly
no test coverage detected