(self, typecallable, creator=None)
| 1391 | assert_eq() |
| 1392 | |
| 1393 | def _test_dict_bulk(self, typecallable, creator=None): |
| 1394 | if creator is None: |
| 1395 | creator = self.dictable_entity |
| 1396 | |
| 1397 | class Foo: |
| 1398 | pass |
| 1399 | |
| 1400 | canary = Canary() |
| 1401 | instrumentation.register_class(Foo) |
| 1402 | d = _register_attribute( |
| 1403 | Foo, |
| 1404 | "attr", |
| 1405 | uselist=True, |
| 1406 | typecallable=typecallable, |
| 1407 | useobject=True, |
| 1408 | ) |
| 1409 | canary.listen(d) |
| 1410 | |
| 1411 | obj = Foo() |
| 1412 | direct = obj.attr |
| 1413 | |
| 1414 | e1 = creator() |
| 1415 | collections.collection_adapter(direct).append_with_event(e1) |
| 1416 | |
| 1417 | like_me = typecallable() |
| 1418 | e2 = creator() |
| 1419 | like_me.set(e2) |
| 1420 | |
| 1421 | self.assert_(obj.attr is direct) |
| 1422 | obj.attr = like_me |
| 1423 | self.assert_(obj.attr is not direct) |
| 1424 | self.assert_(obj.attr is not like_me) |
| 1425 | self.assert_(set(collections.collection_adapter(obj.attr)) == {e2}) |
| 1426 | self.assert_(e1 in canary.removed) |
| 1427 | self.assert_(e2 in canary.added) |
| 1428 | |
| 1429 | # key validity on bulk assignment is a basic feature of |
| 1430 | # MappedCollection but is not present in basic, @converter-less |
| 1431 | # dict collections. |
| 1432 | e3 = creator() |
| 1433 | real_dict = dict(keyignored1=e3) |
| 1434 | obj.attr = real_dict |
| 1435 | self.assert_(obj.attr is not real_dict) |
| 1436 | self.assert_("keyignored1" not in obj.attr) |
| 1437 | eq_(set(collections.collection_adapter(obj.attr)), {e3}) |
| 1438 | self.assert_(e2 in canary.removed) |
| 1439 | self.assert_(e3 in canary.added) |
| 1440 | |
| 1441 | obj.attr = typecallable() |
| 1442 | eq_(list(collections.collection_adapter(obj.attr)), []) |
| 1443 | |
| 1444 | e4 = creator() |
| 1445 | try: |
| 1446 | obj.attr = [e4] |
| 1447 | self.assert_(False) |
| 1448 | except TypeError: |
| 1449 | self.assert_(e4 not in canary.data) |
| 1450 |
no test coverage detected