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