MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_dict_collections

Method test_dict_collections

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

Source from the content-addressed store, hash-verified

2570 )
2571
2572 def test_dict_collections(self):
2573 # TODO: break into individual tests
2574
2575 class Foo(BasicEntity):
2576 pass
2577
2578 class Bar(BasicEntity):
2579 pass
2580
2581 instrumentation.register_class(Foo)
2582 instrumentation.register_class(Bar)
2583 _register_attribute(
2584 Foo,
2585 "someattr",
2586 uselist=True,
2587 useobject=True,
2588 typecallable=attribute_keyed_dict("name"),
2589 )
2590 hi = Bar(name="hi")
2591 there = Bar(name="there")
2592 f = Foo()
2593 eq_(
2594 attributes.get_state_history(
2595 attributes.instance_state(f), "someattr"
2596 ),
2597 ((), [], ()),
2598 )
2599 f.someattr["hi"] = hi
2600 eq_(
2601 attributes.get_state_history(
2602 attributes.instance_state(f), "someattr"
2603 ),
2604 ([hi], [], []),
2605 )
2606 f.someattr["there"] = there
2607 eq_(
2608 tuple(
2609 [
2610 set(x)
2611 for x in attributes.get_state_history(
2612 attributes.instance_state(f), "someattr"
2613 )
2614 ]
2615 ),
2616 ({hi, there}, set(), set()),
2617 )
2618 self._commit_someattr(f)
2619 eq_(
2620 tuple(
2621 [
2622 set(x)
2623 for x in attributes.get_state_history(
2624 attributes.instance_state(f), "someattr"
2625 )
2626 ]
2627 ),
2628 (set(), {hi, there}, set()),
2629 )

Callers

nothing calls this directly

Calls 6

_commit_someattrMethod · 0.95
eq_Function · 0.90
attribute_keyed_dictFunction · 0.85
_register_attributeFunction · 0.70
BarClass · 0.70
FooClass · 0.70

Tested by

no test coverage detected