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

Method test_dict_getitemwitherror

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

Source from the content-addressed store, hash-verified

213 # CRASHES getitemstring(NULL, b'a')
214
215 def test_dict_getitemwitherror(self):
216 # Test PyDict_GetItemWithError()
217 getitem = _testlimitedcapi.dict_getitemwitherror
218 for dict_type in ANYDICT_TYPES:
219 dct = dict_type({'a': 1, '\U0001f40d': 2})
220 self.assertEqual(getitem(dct, 'a'), 1)
221 self.assertIs(getitem(dct, 'b'), KeyError)
222 self.assertEqual(getitem(dct, '\U0001f40d'), 2)
223
224 self.assertRaises(TypeError, getitem, {}, []) # unhashable
225 for test_type in NOT_ANYDICT_TYPES + OTHER_TYPES:
226 self.assertRaises(SystemError, getitem, [], 'a')
227 # CRASHES getitem({}, NULL)
228 # CRASHES getitem(NULL, 'a')
229
230 def test_dict_contains(self):
231 # Test PyDict_Contains()

Callers

nothing calls this directly

Calls 4

getitemFunction · 0.85
assertEqualMethod · 0.45
assertIsMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected