mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Fix OrderedDic.pop() to work for subclasses that define __missing__().
This commit is contained in:
parent
32062e9be7
commit
345c49b16b
2 changed files with 27 additions and 2 deletions
|
@ -834,6 +834,10 @@ class TestOrderedDict(unittest.TestCase):
|
|||
self.assertEqual(list(d.items()),
|
||||
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7)])
|
||||
|
||||
def test_abc(self):
|
||||
self.assertIsInstance(OrderedDict(), MutableMapping)
|
||||
self.assertTrue(issubclass(OrderedDict, MutableMapping))
|
||||
|
||||
def test_clear(self):
|
||||
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
|
||||
shuffle(pairs)
|
||||
|
@ -892,6 +896,17 @@ class TestOrderedDict(unittest.TestCase):
|
|||
self.assertEqual(len(od), 0)
|
||||
self.assertEqual(od.pop(k, 12345), 12345)
|
||||
|
||||
# make sure pop still works when __missing__ is defined
|
||||
class Missing(OrderedDict):
|
||||
def __missing__(self, key):
|
||||
return 0
|
||||
m = Missing(a=1)
|
||||
self.assertEqual(m.pop('b', 5), 5)
|
||||
self.assertEqual(m.pop('a', 6), 1)
|
||||
self.assertEqual(m.pop('a', 6), 6)
|
||||
with self.assertRaises(KeyError):
|
||||
m.pop('a')
|
||||
|
||||
def test_equality(self):
|
||||
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
|
||||
shuffle(pairs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue