MCPcopy Create free account
hub / github.com/zzzeek/sqlalchemy / test_lazyload

Method test_lazyload

test/orm/test_collection.py:2387–2416  ·  view source on GitHub ↗

test that a 'set' can be used as a collection and can lazyload.

(self)

Source from the content-addressed store, hash-verified

2385 assert isinstance(f.bars, MyList)
2386
2387 def test_lazyload(self):
2388 """test that a 'set' can be used as a collection and can lazyload."""
2389
2390 someothertable, sometable = (
2391 self.tables.someothertable,
2392 self.tables.sometable,
2393 )
2394
2395 class Foo:
2396 pass
2397
2398 class Bar:
2399 pass
2400
2401 self.mapper_registry.map_imperatively(
2402 Foo,
2403 sometable,
2404 properties={"bars": relationship(Bar, collection_class=set)},
2405 )
2406 self.mapper_registry.map_imperatively(Bar, someothertable)
2407 f = Foo()
2408 f.bars.add(Bar())
2409 f.bars.add(Bar())
2410 sess = fixture_session()
2411 sess.add(f)
2412 sess.flush()
2413 sess.expunge_all()
2414 f = sess.get(Foo, f.col1)
2415 assert len(list(f.bars)) == 2
2416 f.bars.clear()
2417
2418 def test_dict(self):
2419 """test that a 'dict' can be used as a collection and can lazyload."""

Callers

nothing calls this directly

Calls 10

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
map_imperativelyMethod · 0.80
FooClass · 0.70
BarClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected