MCPcopy Create free account
hub / github.com/python/cpython / test_dict_getitem

Method test_dict_getitem

Lib/test/test_capi/test_dict.py:144–163  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

142 self.assertRaises(SystemError, size, NULL)
143
144 def test_dict_getitem(self):
145 # Test PyDict_GetItem()
146 getitem = _testlimitedcapi.dict_getitem
147 for dict_type in ANYDICT_TYPES:
148 dct = dict_type({'a': 1, '\U0001f40d': 2})
149 self.assertEqual(getitem(dct, 'a'), 1)
150 self.assertIs(getitem(dct, 'b'), KeyError)
151 self.assertEqual(getitem(dct, '\U0001f40d'), 2)
152
153 with support.catch_unraisable_exception() as cm:
154 self.assertIs(getitem({}, []), KeyError) # unhashable
155 self.assertEqual(cm.unraisable.exc_type, TypeError)
156 self.assertEqual(str(cm.unraisable.exc_value),
157 "unhashable type: 'list'")
158
159 for test_type in NOT_ANYDICT_TYPES + OTHER_TYPES:
160 self.assertIs(getitem(test_type(), 'a'), KeyError)
161
162 # CRASHES getitem({}, NULL)
163 # CRASHES getitem(NULL, 'a')
164
165 def test_dict_getitemstring(self):
166 # Test PyDict_GetItemString()

Callers

nothing calls this directly

Calls 4

getitemFunction · 0.85
strFunction · 0.85
assertEqualMethod · 0.45
assertIsMethod · 0.45

Tested by

no test coverage detected