[pypy-commit] pypy dict-strategies: Added test for getitem-fallback in ModuleDictStrategy (still missing: tests for fallbacks setdefault, delitem; also in StringDictStrategy)

l.diekmann noreply at buildbot.pypy.org
Wed May 25 16:48:14 CEST 2011


Author: Lukas Diekmann <lukas.diekmann at uni-duesseldorf.de>
Branch: dict-strategies
Changeset: r44453:1d437de8e20e
Date: 2011-04-13 17:33 +0200
http://bitbucket.org/pypy/pypy/changeset/1d437de8e20e/

Log:	Added test for getitem-fallback in ModuleDictStrategy (still
	missing: tests for fallbacks setdefault, delitem; also in
	StringDictStrategy)

diff --git a/pypy/objspace/std/celldict.py b/pypy/objspace/std/celldict.py
--- a/pypy/objspace/std/celldict.py
+++ b/pypy/objspace/std/celldict.py
@@ -100,7 +100,8 @@
         elif _is_sane_hash(space, w_lookup_type):
             return None
         else:
-            return self._as_rdict().impl_fallback_getitem(w_lookup)
+            self.switch_to_object_strategy(w_dict)
+            return w_dict.getitem(w_lookup)
 
     def getitem_str(self, w_dict, lookup):
         res = self.getcell(w_dict, lookup, False)
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
@@ -726,6 +726,19 @@
         d = type(__builtins__)("abc").__dict__
         raises(KeyError, "d['def']")
 
+    def test_fallback_getitem(self):
+        class F(object):
+            def __hash__(self):
+                return hash("s")
+            def __eq__(self, other):
+                return other == "s"
+        d = type(__builtins__)("abc").__dict__
+        d["s"] = 12
+        assert d["s"] == 12
+        assert d[F()] == d["s"]
+
+    #XXX tests for fallbacks setdefault, delitem
+
 class FakeString(str):
     hash_count = 0
     def unwrap(self, space):
@@ -951,6 +964,8 @@
         assert self.impl.getitem(s) == 1000
         assert s.unwrapped
 
+    #XXX add tests for fallback getitem, delitem
+
 ## class TestMeasuringDictImplementation(BaseTestRDictImplementation):
 ##     ImplementionClass = MeasuringDictImplementation
 ##     DevolvedClass = MeasuringDictImplementation


More information about the pypy-commit mailing list