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

Method test_recipes

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

Source from the content-addressed store, hash-verified

1785 )
1786
1787 def test_recipes(self):
1788 class Custom:
1789 def __init__(self):
1790 self.data = []
1791
1792 @collection.appender
1793 @collection.adds("entity")
1794 def put(self, entity):
1795 self.data.append(entity)
1796
1797 @collection.remover
1798 @collection.removes(1)
1799 def remove(self, entity):
1800 self.data.remove(entity)
1801
1802 @collection.adds(1)
1803 def push(self, *args):
1804 self.data.append(args[0])
1805
1806 @collection.removes("entity")
1807 def yank(self, entity, arg):
1808 self.data.remove(entity)
1809
1810 @collection.replaces(2)
1811 def replace(self, arg, entity, **kw):
1812 self.data.insert(0, entity)
1813 return self.data.pop()
1814
1815 @collection.removes_return()
1816 def pop(self, key):
1817 return self.data.pop()
1818
1819 @collection.iterator
1820 def __iter__(self):
1821 return iter(self.data)
1822
1823 class Foo:
1824 pass
1825
1826 canary = Canary()
1827 instrumentation.register_class(Foo)
1828 d = _register_attribute(
1829 Foo, "attr", uselist=True, typecallable=Custom, useobject=True
1830 )
1831 canary.listen(d)
1832
1833 obj = Foo()
1834 adapter = collections.collection_adapter(obj.attr)
1835 direct = obj.attr
1836 control = list()
1837
1838 def assert_eq():
1839 self.assert_(set(direct) == canary.data)
1840 self.assert_(set(adapter) == canary.data)
1841 self.assert_(list(direct) == control)
1842
1843 creator = self.entity_maker
1844

Callers

nothing calls this directly

Calls 14

listenMethod · 0.95
CanaryClass · 0.85
creatorFunction · 0.85
yankMethod · 0.80
_register_attributeFunction · 0.70
FooClass · 0.70
putMethod · 0.45
appendMethod · 0.45
removeMethod · 0.45
pushMethod · 0.45
replaceMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected