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

Method test_pop

Lib/test/test_ordered_dict.py:255–279  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

253 self.assertEqual(len(obj), 20)
254
255 def test_pop(self):
256 OrderedDict = self.OrderedDict
257 pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
258 shuffle(pairs)
259 od = OrderedDict(pairs)
260 shuffle(pairs)
261 while pairs:
262 k, v = pairs.pop()
263 self.assertEqual(od.pop(k), v)
264 with self.assertRaises(KeyError):
265 od.pop('xyz')
266 self.assertEqual(len(od), 0)
267 self.assertEqual(od.pop(k, 12345), 12345)
268
269 # make sure pop still works when __missing__ is defined
270 class Missing(OrderedDict):
271 def __missing__(self, key):
272 return 0
273 m = Missing(a=1)
274 self.assertEqual(m.pop('b', 5), 5)
275 self.assertEqual(m.pop('a', 6), 1)
276 self.assertEqual(m.pop('a', 6), 6)
277 self.assertEqual(m.pop('a', default=6), 6)
278 with self.assertRaises(KeyError):
279 m.pop('a')
280
281 def test_equality(self):
282 OrderedDict = self.OrderedDict

Callers

nothing calls this directly

Calls 6

popMethod · 0.95
OrderedDictClass · 0.70
MissingClass · 0.70
popMethod · 0.45
assertEqualMethod · 0.45
assertRaisesMethod · 0.45

Tested by

no test coverage detected