(self, typecallable, creator=None)
| 1263 | assert e in canary.appended_wo_mutation |
| 1264 | |
| 1265 | def _test_dict(self, typecallable, creator=None): |
| 1266 | if creator is None: |
| 1267 | creator = self.dictable_entity |
| 1268 | |
| 1269 | class Foo: |
| 1270 | pass |
| 1271 | |
| 1272 | canary = Canary() |
| 1273 | instrumentation.register_class(Foo) |
| 1274 | d = _register_attribute( |
| 1275 | Foo, |
| 1276 | "attr", |
| 1277 | uselist=True, |
| 1278 | typecallable=typecallable, |
| 1279 | useobject=True, |
| 1280 | ) |
| 1281 | canary.listen(d) |
| 1282 | |
| 1283 | obj = Foo() |
| 1284 | adapter = collections.collection_adapter(obj.attr) |
| 1285 | direct = obj.attr |
| 1286 | control = dict() |
| 1287 | |
| 1288 | def assert_eq(): |
| 1289 | self.assert_(set(direct.values()) == canary.data) |
| 1290 | self.assert_(set(adapter) == canary.data) |
| 1291 | self.assert_(direct == control) |
| 1292 | |
| 1293 | def addall(*values): |
| 1294 | for item in values: |
| 1295 | direct.set(item) |
| 1296 | control[item.a] = item |
| 1297 | assert_eq() |
| 1298 | |
| 1299 | def zap(): |
| 1300 | for item in list(adapter): |
| 1301 | direct.remove(item) |
| 1302 | control.clear() |
| 1303 | |
| 1304 | # assume an 'set' method is available for tests |
| 1305 | addall(creator()) |
| 1306 | |
| 1307 | if hasattr(direct, "__setitem__"): |
| 1308 | e = creator() |
| 1309 | direct[e.a] = e |
| 1310 | control[e.a] = e |
| 1311 | assert_eq() |
| 1312 | |
| 1313 | e = creator(e.a, e.b) |
| 1314 | direct[e.a] = e |
| 1315 | control[e.a] = e |
| 1316 | assert_eq() |
| 1317 | |
| 1318 | if hasattr(direct, "__delitem__"): |
| 1319 | e = creator() |
| 1320 | addall(e) |
| 1321 | |
| 1322 | del direct[e.a] |
no test coverage detected