MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_dict_emulates

Method test_dict_emulates

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

Source from the content-addressed store, hash-verified

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