[pypy-svn] r70755 - in pypy/trunk/pypy/objspace: std/test test

afa at codespeak.net afa at codespeak.net
Thu Jan 21 18:00:00 CET 2010


Author: afa
Date: Thu Jan 21 17:59:58 2010
New Revision: 70755

Modified:
   pypy/trunk/pypy/objspace/std/test/test_userobject.py
   pypy/trunk/pypy/objspace/test/test_descriptor.py
Log:
Add a descriptor test that fails when objspace.std.getattributeshortcut is True.

Also repair AppTestWithGetAttributeShortcut, which was not really testing the option:
setup_class() is defined in the base class, so the one from mix-in is ignored.

I could not find an easy fix.
Remember to run both test_descriptor.py and test_userobject.py...


Modified: pypy/trunk/pypy/objspace/std/test/test_userobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_userobject.py	(original)
+++ pypy/trunk/pypy/objspace/std/test/test_userobject.py	Thu Jan 21 17:59:58 2010
@@ -295,19 +295,13 @@
         multimethod.Installer = cls.prev_installer
 
 
-class GetAttributeShortcutTest:
-
-    def setup_class(cls):
-        from pypy import conftest
-        options = {"objspace.std.getattributeshortcut" : True}
-        cls.space = conftest.gettestobjspace(**options)
-
-
-class AppTestWithGetAttributeShortcut(AppTestUserObject,
-                                      GetAttributeShortcutTest):
-    pass
+class AppTestWithGetAttributeShortcut(AppTestUserObject):
+    OPTIONS = {"objspace.std.getattributeshortcut": True}
 
 
 class AppTestDescriptorWithGetAttributeShortcut(
-    test_descriptor.AppTest_Descriptor, GetAttributeShortcutTest):
-    pass
+    test_descriptor.AppTest_Descriptor):
+    # for the individual tests see
+    # ====> ../../test/test_descriptor.py
+
+    OPTIONS = {"objspace.std.getattributeshortcut": True}

Modified: pypy/trunk/pypy/objspace/test/test_descriptor.py
==============================================================================
--- pypy/trunk/pypy/objspace/test/test_descriptor.py	(original)
+++ pypy/trunk/pypy/objspace/test/test_descriptor.py	Thu Jan 21 17:59:58 2010
@@ -1,6 +1,12 @@
+from pypy.conftest import gettestobjspace
 
 class AppTest_Descriptor:
 
+    OPTIONS = {}
+
+    def setup_class(cls):
+        cls.space = gettestobjspace(**cls.OPTIONS)
+
     def test_non_data_descr(self):
         class X(object):
             def f(self):
@@ -30,6 +36,31 @@
         x.a = 42
         assert x.a == 42
 
+    def test_failing_get(self):
+        # when __get__() raises AttributeError,
+        # __getattr__ is called...
+        class X(object):
+            def get_v(self):
+                raise AttributeError
+            v = property(get_v)
+
+            def __getattr__(self, name):
+                if name == 'v':
+                    return 42
+        x = X()
+        assert x.v == 42
+
+        # ... but the __dict__ is not searched
+        class Y(object):
+            def get_w(self):
+                raise AttributeError
+            def set_w(self, value):
+                raise AttributeError
+            w = property(get_w, set_w)
+        y = Y()
+        y.__dict__['w'] = 42
+        raises(AttributeError, getattr, y, 'w')
+
     def test_member(self):
         class X(object):
             def __init__(self):



More information about the Pypy-commit mailing list