MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_getitem_knownhash

Method test_getitem_knownhash

Lib/test/test_dict.py:1694–1718  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1692 # Test _PyDict_GetItem_KnownHash()
1693 @support.cpython_only
1694 def test_getitem_knownhash(self):
1695 _testinternalcapi = import_helper.import_module('_testinternalcapi')
1696 dict_getitem_knownhash = _testinternalcapi.dict_getitem_knownhash
1697
1698 d = {'x': 1, 'y': 2, 'z': 3}
1699 self.assertEqual(dict_getitem_knownhash(d, 'x', hash('x')), 1)
1700 self.assertEqual(dict_getitem_knownhash(d, 'y', hash('y')), 2)
1701 self.assertEqual(dict_getitem_knownhash(d, 'z', hash('z')), 3)
1702
1703 # not a dict
1704 self.assertRaises(SystemError, dict_getitem_knownhash, [], 1, hash(1))
1705 # key does not exist
1706 self.assertRaises(KeyError, dict_getitem_knownhash, {}, 1, hash(1))
1707
1708 class Exc(Exception): pass
1709 class BadEq:
1710 def __eq__(self, other):
1711 raise Exc
1712 def __hash__(self):
1713 return 7
1714
1715 k1, k2 = BadEq(), BadEq()
1716 d = {k1: 1}
1717 self.assertEqual(dict_getitem_knownhash(d, k1, hash(k1)), 1)
1718 self.assertRaises(Exc, dict_getitem_knownhash, d, k2, hash(k2))
1719
1720
1721from test import mapping_tests

Callers

nothing calls this directly

Calls 5

hashFunction · 0.85
BadEqClass · 0.70
import_moduleMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected