MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_object_duck

Method test_object_duck

test/orm/test_collection.py:1713–1745  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1711 assert_eq()
1712
1713 def test_object_duck(self):
1714 class MyCollection:
1715 def __init__(self):
1716 self.data = set()
1717
1718 @collection.appender
1719 def push(self, item):
1720 self.data.add(item)
1721
1722 @collection.remover
1723 def zark(self, item):
1724 self.data.remove(item)
1725
1726 @collection.removes_return()
1727 def maybe_zark(self, item):
1728 if item in self.data:
1729 self.data.remove(item)
1730 return item
1731
1732 @collection.iterator
1733 def __iter__(self):
1734 return iter(self.data)
1735
1736 __hash__ = object.__hash__
1737
1738 def __eq__(self, other):
1739 return self.data == other
1740
1741 self._test_adapter(MyCollection)
1742 self._test_object(MyCollection)
1743 self.assert_(
1744 getattr(MyCollection, "_sa_instrumented") == id(MyCollection)
1745 )
1746
1747 def test_object_emulates(self):
1748 class MyCollection2:

Callers

nothing calls this directly

Calls 3

_test_adapterMethod · 0.95
_test_objectMethod · 0.95
assert_Method · 0.45

Tested by

no test coverage detected