MCPcopy Index your code
hub / github.com/python/cpython / test_getitem

Method test_getitem

Lib/test/mapping_tests.py:545–571  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

543class TestHashMappingProtocol(TestMappingProtocol):
544
545 def test_getitem(self):
546 TestMappingProtocol.test_getitem(self)
547 class Exc(Exception): pass
548
549 class BadEq(object):
550 def __eq__(self, other):
551 raise Exc()
552 def __hash__(self):
553 return 24
554
555 d = self._empty_mapping()
556 d[BadEq()] = 42
557 self.assertRaises(KeyError, d.__getitem__, 23)
558
559 class BadHash(object):
560 fail = False
561 def __hash__(self):
562 if self.fail:
563 raise Exc()
564 else:
565 return 42
566
567 d = self._empty_mapping()
568 x = BadHash()
569 d[x] = 42
570 x.fail = True
571 self.assertRaises(Exc, d.__getitem__, x)
572
573 def test_fromkeys(self):
574 TestMappingProtocol.test_fromkeys(self)

Callers

nothing calls this directly

Calls 5

BadEqClass · 0.70
BadHashClass · 0.70
test_getitemMethod · 0.45
_empty_mappingMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected