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

Method test_pop

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

Source from the content-addressed store, hash-verified

567 self.assertRaises(KeyError, d.popitem)
568
569 def test_pop(self):
570 # Tests for pop with specified key
571 d = {}
572 k, v = 'abc', 'def'
573 d[k] = v
574 self.assertRaises(KeyError, d.pop, 'ghi')
575
576 self.assertEqual(d.pop(k), v)
577 self.assertEqual(len(d), 0)
578
579 self.assertRaises(KeyError, d.pop, k)
580
581 self.assertEqual(d.pop(k, v), v)
582 d[k] = v
583 self.assertEqual(d.pop(k, 1), v)
584
585 self.assertRaises(TypeError, d.pop)
586
587 class Exc(Exception): pass
588
589 class BadHash(object):
590 fail = False
591 def __hash__(self):
592 if self.fail:
593 raise Exc()
594 else:
595 return 42
596
597 x = BadHash()
598 d[x] = 42
599 x.fail = True
600 self.assertRaises(Exc, d.pop, x)
601
602 def test_mutating_iteration(self):
603 # changing dict size during iteration

Callers

nothing calls this directly

Calls 4

BadHashClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected