(self, typecallable, creator=None, to_set=None)
| 147 | return cls.Entity(a or str(id_), b or "value %s" % id, c) |
| 148 | |
| 149 | def _test_adapter(self, typecallable, creator=None, to_set=None): |
| 150 | if creator is None: |
| 151 | creator = self.entity_maker |
| 152 | |
| 153 | class Foo: |
| 154 | pass |
| 155 | |
| 156 | canary = Canary() |
| 157 | instrumentation.register_class(Foo) |
| 158 | d = _register_attribute( |
| 159 | Foo, |
| 160 | "attr", |
| 161 | uselist=True, |
| 162 | typecallable=typecallable, |
| 163 | useobject=True, |
| 164 | ) |
| 165 | canary.listen(d) |
| 166 | |
| 167 | obj = Foo() |
| 168 | adapter = collections.collection_adapter(obj.attr) |
| 169 | direct = obj.attr |
| 170 | if to_set is None: |
| 171 | |
| 172 | def to_set(col): |
| 173 | return set(col) |
| 174 | |
| 175 | def assert_eq(): |
| 176 | self.assert_(to_set(direct) == canary.data) |
| 177 | self.assert_(set(adapter) == canary.data) |
| 178 | |
| 179 | def assert_ne(): |
| 180 | self.assert_(to_set(direct) != canary.data) |
| 181 | |
| 182 | e1, e2 = creator(), creator() |
| 183 | |
| 184 | adapter.append_with_event(e1) |
| 185 | assert_eq() |
| 186 | |
| 187 | adapter.append_without_event(e2) |
| 188 | assert_ne() |
| 189 | canary.data.add(e2) |
| 190 | assert_eq() |
| 191 | |
| 192 | adapter.remove_without_event(e2) |
| 193 | assert_ne() |
| 194 | canary.data.remove(e2) |
| 195 | assert_eq() |
| 196 | |
| 197 | adapter.remove_with_event(e1) |
| 198 | assert_eq() |
| 199 | |
| 200 | self._test_empty_init(typecallable, creator=creator) |
| 201 | |
| 202 | def _test_empty_init(self, typecallable, creator=None): |
| 203 | if creator is None: |
no test coverage detected