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

Method test_pop

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

lenFunction · 0.85
BadHashClass · 0.70
assertRaisesMethod · 0.45
assertEqualMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected