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

Method test_setitem_atomic_at_resize

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

Source from the content-addressed store, hash-verified

519 self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1)
520
521 def test_setitem_atomic_at_resize(self):
522 class Hashed(object):
523 def __init__(self):
524 self.hash_count = 0
525 self.eq_count = 0
526 def __hash__(self):
527 self.hash_count += 1
528 return 42
529 def __eq__(self, other):
530 self.eq_count += 1
531 return id(self) == id(other)
532 hashed1 = Hashed()
533 # 5 items
534 y = {hashed1: 5, 0: 0, 1: 1, 2: 2, 3: 3}
535 hashed2 = Hashed()
536 # 6th item forces a resize
537 y[hashed2] = []
538 self.assertEqual(hashed1.hash_count, 1)
539 self.assertEqual(hashed2.hash_count, 1)
540 self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1)
541
542 def test_popitem(self):
543 # dict.popitem()

Callers

nothing calls this directly

Calls 2

HashedClass · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected