(self, typecallable, creator=None)
| 759 | assert e in canary.appended_wo_mutation |
| 760 | |
| 761 | def _test_set(self, typecallable, creator=None): |
| 762 | if creator is None: |
| 763 | creator = self.entity_maker |
| 764 | |
| 765 | class Foo: |
| 766 | pass |
| 767 | |
| 768 | canary = Canary() |
| 769 | instrumentation.register_class(Foo) |
| 770 | d = _register_attribute( |
| 771 | Foo, |
| 772 | "attr", |
| 773 | uselist=True, |
| 774 | typecallable=typecallable, |
| 775 | useobject=True, |
| 776 | ) |
| 777 | canary.listen(d) |
| 778 | |
| 779 | obj = Foo() |
| 780 | adapter = collections.collection_adapter(obj.attr) |
| 781 | direct = obj.attr |
| 782 | control = set() |
| 783 | |
| 784 | def assert_eq(): |
| 785 | eq_(set(direct), canary.data) |
| 786 | eq_(set(adapter), canary.data) |
| 787 | eq_(direct, control) |
| 788 | |
| 789 | def addall(*values): |
| 790 | for item in values: |
| 791 | direct.add(item) |
| 792 | control.add(item) |
| 793 | assert_eq() |
| 794 | |
| 795 | def zap(): |
| 796 | for item in list(direct): |
| 797 | direct.remove(item) |
| 798 | control.clear() |
| 799 | |
| 800 | addall(creator()) |
| 801 | |
| 802 | e = creator() |
| 803 | addall(e) |
| 804 | addall(e) |
| 805 | |
| 806 | if hasattr(direct, "remove"): |
| 807 | e = creator() |
| 808 | addall(e) |
| 809 | |
| 810 | direct.remove(e) |
| 811 | control.remove(e) |
| 812 | assert_eq() |
| 813 | |
| 814 | e = creator() |
| 815 | try: |
| 816 | direct.remove(e) |
| 817 | except KeyError: |
| 818 | assert_eq() |
no test coverage detected