[pypy-svn] pypy default: * add a test about __missing__.

arigo commits-noreply at bitbucket.org
Sat Jan 29 19:35:05 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41455:67d7305f08df
Date: 2011-01-29 19:33 +0100
http://bitbucket.org/pypy/pypy/changeset/67d7305f08df/

Log:	* add a test about __missing__.
	* add a failing test about a more advanced use case of __missing__.

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
@@ -501,6 +501,27 @@
         iterable = {}
         raises(TypeError, len, iter(iterable))
 
+    def test_missing(self):
+        class X(dict):
+            def __missing__(self, x):
+                assert x == 'hi'
+                return 42
+        assert X()['hi'] == 42
+
+    def test_missing_more(self):
+        def missing(self, x):
+            assert x == 'hi'
+            return 42
+        class SpecialDescr(object):
+            def __init__(self, impl):
+                self.impl = impl
+            def __get__(self, obj, owner):
+                return self.impl.__get__(obj, owner)
+        class X(dict):
+            __missing__ = SpecialDescr(missing)
+        assert X()['hi'] == 42
+
+
 class AppTest_DictMultiObject(AppTest_DictObject):
 
     def test_emptydict_unhashable(self):


More information about the Pypy-commit mailing list