(self)
| 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 |
nothing calls this directly
no test coverage detected