MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_setdefault_atomic

Method test_setdefault_atomic

Lib/test/test_dict.py:502–520  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

500 self.assertRaises(Exc, d.setdefault, x, [])
501
502 def test_setdefault_atomic(self):
503 # Issue #13521: setdefault() calls __hash__ and __eq__ only once.
504 class Hashed(object):
505 def __init__(self):
506 self.hash_count = 0
507 self.eq_count = 0
508 def __hash__(self):
509 self.hash_count += 1
510 return 42
511 def __eq__(self, other):
512 self.eq_count += 1
513 return id(self) == id(other)
514 hashed1 = Hashed()
515 y = {hashed1: 5}
516 hashed2 = Hashed()
517 y.setdefault(hashed2, [])
518 self.assertEqual(hashed1.hash_count, 1)
519 self.assertEqual(hashed2.hash_count, 1)
520 self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1)
521
522 def test_setitem_atomic_at_resize(self):
523 class Hashed(object):

Callers

nothing calls this directly

Calls 3

HashedClass · 0.85
setdefaultMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected