MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _test_object

Method _test_object

test/orm/test_collection.py:1659–1711  ·  view source on GitHub ↗
(self, typecallable, creator=None)

Source from the content-addressed store, hash-verified

1657 self.assert_(getattr(DictIsh, "_sa_instrumented") == id(DictIsh))
1658
1659 def _test_object(self, typecallable, creator=None):
1660 if creator is None:
1661 creator = self.entity_maker
1662
1663 class Foo:
1664 pass
1665
1666 canary = Canary()
1667 instrumentation.register_class(Foo)
1668 d = _register_attribute(
1669 Foo,
1670 "attr",
1671 uselist=True,
1672 typecallable=typecallable,
1673 useobject=True,
1674 )
1675 canary.listen(d)
1676
1677 obj = Foo()
1678 adapter = collections.collection_adapter(obj.attr)
1679 direct = obj.attr
1680 control = set()
1681
1682 def assert_eq():
1683 self.assert_(set(direct) == canary.data)
1684 self.assert_(set(adapter) == canary.data)
1685 self.assert_(direct == control)
1686
1687 # There is no API for object collections. We'll make one up
1688 # for the purposes of the test.
1689 e = creator()
1690 direct.push(e)
1691 control.add(e)
1692 assert_eq()
1693
1694 direct.zark(e)
1695 control.remove(e)
1696 assert_eq()
1697
1698 e = creator()
1699 direct.maybe_zark(e)
1700 control.discard(e)
1701 assert_eq()
1702
1703 e = creator()
1704 direct.push(e)
1705 control.add(e)
1706 assert_eq()
1707
1708 e = creator()
1709 direct.maybe_zark(e)
1710 control.discard(e)
1711 assert_eq()
1712
1713 def test_object_duck(self):
1714 class MyCollection:

Callers 2

test_object_duckMethod · 0.95
test_object_emulatesMethod · 0.95

Calls 11

listenMethod · 0.95
CanaryClass · 0.85
creatorFunction · 0.85
_register_attributeFunction · 0.70
FooClass · 0.70
pushMethod · 0.45
addMethod · 0.45
zarkMethod · 0.45
removeMethod · 0.45
maybe_zarkMethod · 0.45
discardMethod · 0.45

Tested by

no test coverage detected