| 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: |