summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-01-01 23:51:55 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-01-01 23:51:55 (GMT)
commit345c49b16b093399ad504711d55bad700ad7a33b (patch)
tree4bba38bffe4a5f85fbe9dfc3b1b95b980842d3ac /Lib/test
parent32062e9be78ee49b563d1b7eb290a00e6fe16c0f (diff)
downloadcpython-345c49b16b093399ad504711d55bad700ad7a33b.zip
cpython-345c49b16b093399ad504711d55bad700ad7a33b.tar.gz
cpython-345c49b16b093399ad504711d55bad700ad7a33b.tar.bz2
Fix OrderedDic.pop() to work for subclasses that define __missing__().
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_collections.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 8c95979..deda1cd 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -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)