MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_dict_emulates

Method test_dict_emulates

test/orm/test_collection.py:1605–1657  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1603 self.assert_(getattr(DictLike, "_sa_instrumented") == id(DictLike))
1604
1605 def test_dict_emulates(self):
1606 class DictIsh:
1607 __emulates__ = dict
1608
1609 def __init__(self, *args):
1610 self.data = dict(*args)
1611
1612 @collection.appender
1613 @collection.replaces(1)
1614 def set(self, item):
1615 current = self.data.get(item.a, None)
1616 self.data[item.a] = item
1617 return current
1618
1619 @collection.remover
1620 def _remove(self, item):
1621 del self.data[item.a]
1622
1623 def __setitem__(self, key, value):
1624 self.data[key] = value
1625
1626 def __getitem__(self, key):
1627 return self.data[key]
1628
1629 def __delitem__(self, key):
1630 del self.data[key]
1631
1632 def values(self):
1633 return list(self.data.values())
1634
1635 def __contains__(self, key):
1636 return key in self.data
1637
1638 @collection.iterator
1639 def itervalues(self):
1640 return iter(self.data.values())
1641
1642 __hash__ = object.__hash__
1643
1644 def __eq__(self, other):
1645 return self.data == other
1646
1647 def __repr__(self):
1648 return "DictIsh(%s)" % repr(self.data)
1649
1650 self._test_adapter(
1651 DictIsh, self.dictable_entity, to_set=lambda c: set(c.values())
1652 )
1653 self._test_dict(DictIsh)
1654 self._test_dict_bulk(DictIsh)
1655 self._test_dict_wo_mutation(DictIsh)
1656 self._test_dict_dataclasses(DictIsh)
1657 self.assert_(getattr(DictIsh, "_sa_instrumented") == id(DictIsh))
1658
1659 def _test_object(self, typecallable, creator=None):
1660 if creator is None:

Callers

nothing calls this directly

Calls 7

_test_adapterMethod · 0.95
_test_dictMethod · 0.95
_test_dict_bulkMethod · 0.95
valuesMethod · 0.45
assert_Method · 0.45

Tested by

no test coverage detected