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

Method test_dict_wrapper

test/orm/test_collection.py:2461–2514  ·  view source on GitHub ↗

test that the supplied 'dict' wrapper can be used as a collection and can lazyload.

(self)

Source from the content-addressed store, hash-verified

2459 f.bars.clear()
2460
2461 def test_dict_wrapper(self):
2462 """test that the supplied 'dict' wrapper can be used as a
2463 collection and can lazyload."""
2464
2465 someothertable, sometable = (
2466 self.tables.someothertable,
2467 self.tables.sometable,
2468 )
2469
2470 class Foo:
2471 pass
2472
2473 class Bar:
2474 def __init__(self, data):
2475 self.data = data
2476
2477 self.mapper_registry.map_imperatively(
2478 Foo,
2479 sometable,
2480 properties={
2481 "bars": relationship(
2482 Bar,
2483 collection_class=collections.column_keyed_dict(
2484 someothertable.c.data
2485 ),
2486 )
2487 },
2488 )
2489 self.mapper_registry.map_imperatively(Bar, someothertable)
2490
2491 f = Foo()
2492 col = collections.collection_adapter(f.bars)
2493 col.append_with_event(Bar("a"))
2494 col.append_with_event(Bar("b"))
2495 sess = fixture_session()
2496 sess.add(f)
2497 sess.flush()
2498 sess.expunge_all()
2499 f = sess.get(Foo, f.col1)
2500 assert len(list(f.bars)) == 2
2501
2502 strongref = list(f.bars.values())
2503 existing = {id(b) for b in strongref}
2504
2505 col = collections.collection_adapter(f.bars)
2506 col.append_with_event(Bar("b"))
2507 f.bars["a"] = Bar("a")
2508 sess.flush()
2509 sess.expunge_all()
2510 f = sess.get(Foo, f.col1)
2511 assert len(list(f.bars)) == 2
2512
2513 replaced = {id(b) for b in list(f.bars.values())}
2514 ne_(existing, replaced)
2515
2516 @testing.combinations("direct", "as_callable", argnames="factory_type")
2517 def test_list(self, factory_type):

Callers

nothing calls this directly

Calls 12

relationshipFunction · 0.90
fixture_sessionFunction · 0.90
ne_Function · 0.90
map_imperativelyMethod · 0.80
append_with_eventMethod · 0.80
FooClass · 0.70
BarClass · 0.70
addMethod · 0.45
flushMethod · 0.45
expunge_allMethod · 0.45
getMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected