Commits

Lukas Diekmann committed 1d437de

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

Comments (0)

Files changed (2)

pypy/objspace/std/celldict.py

         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)

pypy/objspace/std/test/test_dictmultiobject.py

         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):
         assert self.impl.getitem(s) == 1000
         assert s.unwrapped
 
+    #XXX add tests for fallback getitem, delitem
+
 ## class TestMeasuringDictImplementation(BaseTestRDictImplementation):
 ##     ImplementionClass = MeasuringDictImplementation
 ##     DevolvedClass = MeasuringDictImplementation