Author: Lukas Diekmann <[email protected]>
Branch: dict-strategies
Changeset: r44781:568c8b8b84c0
Date: 2011-06-07 13:48 +0200
http://bitbucket.org/pypy/pypy/changeset/568c8b8b84c0/
Log: popitem was not defined for emptydictstrategy
diff --git a/pypy/objspace/std/dictmultiobject.py
b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -214,7 +214,8 @@
def clear(self, w_dict):
return
-
+ def popitem(self, w_dict):
+ raise KeyError
registerimplementation(W_DictMultiObject)
diff --git a/pypy/objspace/std/test/test_dictmultiobject.py
b/pypy/objspace/std/test/test_dictmultiobject.py
--- a/pypy/objspace/std/test/test_dictmultiobject.py
+++ b/pypy/objspace/std/test/test_dictmultiobject.py
@@ -233,6 +233,31 @@
assert it1 == ('x', 5)
raises(KeyError, d.popitem)
+ def test_popitem3(self):
+ #object
+ d = {"a": 1, 2:2, "c":3}
+ l = []
+ while True:
+ try:
+ l.append(d.popitem())
+ except KeyError:
+ break;
+ assert ("a",1) in l
+ assert (2,2) in l
+ assert ("c",3) in l
+
+ #string
+ d = {"a": 1, "b":2, "c":3}
+ l = []
+ while True:
+ try:
+ l.append(d.popitem())
+ except KeyError:
+ break;
+ assert ("a",1) in l
+ assert ("b",2) in l
+ assert ("c",3) in l
+
def test_setdefault(self):
d = {1:2, 3:4}
dd = d.copy()
@@ -527,6 +552,12 @@
__missing__ = SpecialDescr(missing)
assert X()['hi'] == 42
+ def test_empty_dict(self):
+ d = {}
+ raises(KeyError, d.popitem)
+ assert d.items() == []
+ assert d.values() == []
+ assert d.keys() == []
class AppTest_DictMultiObject(AppTest_DictObject):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit