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

Method test_mapping_haskeystring

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

Source from the content-addressed store, hash-verified

488 'null argument to internal routine')
489
490 def test_mapping_haskeystring(self):
491 haskeystring = _testlimitedcapi.mapping_haskeystring
492 dct = {'a': 1, '\U0001f40d': 2}
493 self.assertTrue(haskeystring(dct, b'a'))
494 self.assertFalse(haskeystring(dct, b'b'))
495 self.assertTrue(haskeystring(dct, '\U0001f40d'.encode()))
496
497 dct2 = ProxyGetItem(dct)
498 self.assertTrue(haskeystring(dct2, b'a'))
499 self.assertFalse(haskeystring(dct2, b'b'))
500
501 with support.catch_unraisable_exception() as cm:
502 self.assertFalse(haskeystring(42, b'a'))
503 self.assertEqual(cm.unraisable.exc_type, TypeError)
504 self.assertEqual(str(cm.unraisable.exc_value),
505 "'int' object is not subscriptable")
506
507 with support.catch_unraisable_exception() as cm:
508 self.assertFalse(haskeystring({}, b'\xff'))
509 self.assertEqual(cm.unraisable.exc_type, UnicodeDecodeError)
510 self.assertRegex(str(cm.unraisable.exc_value),
511 "'utf-8' codec can't decode")
512
513 with support.catch_unraisable_exception() as cm:
514 self.assertFalse(haskeystring({}, NULL))
515 self.assertEqual(cm.unraisable.exc_type, SystemError)
516 self.assertEqual(str(cm.unraisable.exc_value),
517 "null argument to internal routine")
518
519 with support.catch_unraisable_exception() as cm:
520 self.assertFalse(haskeystring([], b'a'))
521 self.assertEqual(cm.unraisable.exc_type, TypeError)
522 self.assertEqual(str(cm.unraisable.exc_value),
523 'list indices must be integers or slices, not str')
524
525 with support.catch_unraisable_exception() as cm:
526 self.assertFalse(haskeystring(NULL, b'a'))
527 self.assertEqual(cm.unraisable.exc_type, SystemError)
528 self.assertEqual(str(cm.unraisable.exc_value),
529 "null argument to internal routine")
530
531 def test_mapping_haskeywitherror(self):
532 haskey = _testlimitedcapi.mapping_haskeywitherror

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected