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

Method test_popitem

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

Source from the content-addressed store, hash-verified

540 self.assertEqual(hashed1.eq_count + hashed2.eq_count, 1)
541
542 def test_popitem(self):
543 # dict.popitem()
544 for copymode in -1, +1:
545 # -1: b has same structure as a
546 # +1: b is a.copy()
547 for log2size in range(12):
548 size = 2**log2size
549 a = {}
550 b = {}
551 for i in range(size):
552 a[repr(i)] = i
553 if copymode < 0:
554 b[repr(i)] = i
555 if copymode > 0:
556 b = a.copy()
557 for i in range(size):
558 ka, va = ta = a.popitem()
559 self.assertEqual(va, int(ka))
560 kb, vb = tb = b.popitem()
561 self.assertEqual(vb, int(kb))
562 self.assertFalse(copymode < 0 and ta != tb)
563 self.assertFalse(a)
564 self.assertFalse(b)
565
566 d = {}
567 self.assertRaises(KeyError, d.popitem)
568
569 def test_pop(self):
570 # Tests for pop with specified key

Callers

nothing calls this directly

Calls 5

assertFalseMethod · 0.80
copyMethod · 0.45
popitemMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected