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

Method test_mapping_haskey

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

Source from the content-addressed store, hash-verified

438 # CRASHES getitemstring(NULL, b'a')
439
440 def test_mapping_haskey(self):
441 haskey = _testlimitedcapi.mapping_haskey
442 dct = {'a': 1, '\U0001f40d': 2}
443 self.assertTrue(haskey(dct, 'a'))
444 self.assertFalse(haskey(dct, 'b'))
445 self.assertTrue(haskey(dct, '\U0001f40d'))
446
447 dct2 = ProxyGetItem(dct)
448 self.assertTrue(haskey(dct2, 'a'))
449 self.assertFalse(haskey(dct2, 'b'))
450
451 self.assertTrue(haskey(['a', 'b', 'c'], 1))
452
453 with support.catch_unraisable_exception() as cm:
454 self.assertFalse(haskey(42, 'a'))
455 self.assertEqual(cm.unraisable.exc_type, TypeError)
456 self.assertEqual(str(cm.unraisable.exc_value),
457 "'int' object is not subscriptable")
458
459 with support.catch_unraisable_exception() as cm:
460 self.assertFalse(haskey({}, []))
461 self.assertEqual(cm.unraisable.exc_type, TypeError)
462 self.assertEqual(str(cm.unraisable.exc_value),
463 "cannot use 'list' as a dict key "
464 "(unhashable type: 'list')")
465
466 with support.catch_unraisable_exception() as cm:
467 self.assertFalse(haskey([], 1))
468 self.assertEqual(cm.unraisable.exc_type, IndexError)
469 self.assertEqual(str(cm.unraisable.exc_value),
470 'list index out of range')
471
472 with support.catch_unraisable_exception() as cm:
473 self.assertFalse(haskey([], 'a'))
474 self.assertEqual(cm.unraisable.exc_type, TypeError)
475 self.assertEqual(str(cm.unraisable.exc_value),
476 'list indices must be integers or slices, not str')
477
478 with support.catch_unraisable_exception() as cm:
479 self.assertFalse(haskey({}, NULL))
480 self.assertEqual(cm.unraisable.exc_type, SystemError)
481 self.assertEqual(str(cm.unraisable.exc_value),
482 'null argument to internal routine')
483
484 with support.catch_unraisable_exception() as cm:
485 self.assertFalse(haskey(NULL, 'a'))
486 self.assertEqual(cm.unraisable.exc_type, SystemError)
487 self.assertEqual(str(cm.unraisable.exc_value),
488 'null argument to internal routine')
489
490 def test_mapping_haskeystring(self):
491 haskeystring = _testlimitedcapi.mapping_haskeystring

Callers

nothing calls this directly

Calls 5

ProxyGetItemClass · 0.85
strFunction · 0.85
assertTrueMethod · 0.80
assertFalseMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected