MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _test_object

Method _test_object

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

Source from the content-addressed store, hash-verified

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