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

Method test_mapping_getoptionalitem

Lib/test/test_capi/test_abstract.py:403–421  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

401 self.assertRaises(SystemError, getitemstring, NULL, b'a')
402
403 def test_mapping_getoptionalitem(self):
404 getitem = _testcapi.mapping_getoptionalitem
405 dct = {'a': 1, '\U0001f40d': 2}
406 self.assertEqual(getitem(dct, 'a'), 1)
407 self.assertEqual(getitem(dct, 'b'), KeyError)
408 self.assertEqual(getitem(dct, '\U0001f40d'), 2)
409
410 dct2 = ProxyGetItem(dct)
411 self.assertEqual(getitem(dct2, 'a'), 1)
412 self.assertEqual(getitem(dct2, 'b'), KeyError)
413
414 self.assertEqual(getitem(['a', 'b', 'c'], 1), 'b')
415
416 self.assertRaises(TypeError, getitem, 42, 'a')
417 self.assertRaises(TypeError, getitem, {}, []) # unhashable
418 self.assertRaises(IndexError, getitem, [], 1)
419 self.assertRaises(TypeError, getitem, [], 'a')
420 # CRASHES getitem({}, NULL)
421 # CRASHES getitem(NULL, 'a')
422
423 def test_mapping_getoptionalitemstring(self):
424 getitemstring = _testcapi.mapping_getoptionalitemstring

Callers

nothing calls this directly

Calls 4

getitemFunction · 0.85
ProxyGetItemClass · 0.85
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected