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