[pypy-commit] pypy py3k: fix tests with py2 metaclass syntax that's broken on py3

pjenvey noreply at buildbot.pypy.org
Mon Aug 4 01:55:52 CEST 2014


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r72688:437cea3ad956
Date: 2014-08-03 16:54 -0700
http://bitbucket.org/pypy/pypy/changeset/437cea3ad956/

Log:	fix tests with py2 metaclass syntax that's broken on py3

diff --git a/pypy/interpreter/test/test_raise.py b/pypy/interpreter/test/test_raise.py
--- a/pypy/interpreter/test/test_raise.py
+++ b/pypy/interpreter/test/test_raise.py
@@ -256,6 +256,7 @@
             fail("Did not raise")
 
     def test_obscure_bases(self):
+        """
         # this test checks bug-to-bug cpython compatibility
         e = ValueError()
         e.__bases__ = (5,)
@@ -267,20 +268,21 @@
         # explodes on CPython and py.test, not sure why
 
         flag = False
-        class A(BaseException):
-            class __metaclass__(type):
-                def __getattribute__(self, name):
-                    if flag and name == '__bases__':
-                        fail("someone read bases attr")
-                    else:
-                        return type.__getattribute__(self, name)
-
+        class metaclass(type):
+            def __getattribute__(self, name):
+                if flag and name == '__bases__':
+                    fail("someone read bases attr")
+                else:
+                    return type.__getattribute__(self, name)
+        class A(BaseException, metaclass=metaclass):
+            pass
         try:
             a = A()
             flag = True
             raise a
         except A:
             pass
+        """
 
     def test_new_returns_bad_instance(self):
         class MyException(Exception):
diff --git a/pypy/module/__builtin__/test/test_builtin.py b/pypy/module/__builtin__/test/test_builtin.py
--- a/pypy/module/__builtin__/test/test_builtin.py
+++ b/pypy/module/__builtin__/test/test_builtin.py
@@ -224,13 +224,15 @@
         assert dir(Foo("a_mod")) == ["blah"]
 
     def test_dir_custom_lookup(self):
+        """
         class M(type):
             def __dir__(self, *args): return ["14"]
-        class X(object):
-            __metaclass__ = M
+        class X(metaclass=M):
+            pass
         x = X()
         x.__dir__ = lambda x: ["14"]
         assert dir(x) != ["14"]
+        """
 
     def test_format(self):
         assert format(4) == "4"
diff --git a/pypy/objspace/std/test/test_mapdict.py b/pypy/objspace/std/test/test_mapdict.py
--- a/pypy/objspace/std/test/test_mapdict.py
+++ b/pypy/objspace/std/test/test_mapdict.py
@@ -852,9 +852,11 @@
         assert res == (0, 1, 0)
 
     def test_custom_metaclass(self):
-        class A(object):
-            class __metaclass__(type):
-                pass
+        """
+        class metaclass(type):
+            pass
+        class A(metaclass=metaclass):
+            pass
         a = A()
         a.x = 42
         def f():
@@ -866,6 +868,7 @@
         assert res == (0, 1, 0)
         res = self.check(f, 'x')
         assert res == (0, 1, 0)
+        """
 
     def test_old_style_base(self):
         skip('py3k no longer has old style classes')
diff --git a/pypy/objspace/test/test_descroperation.py b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -19,8 +19,8 @@
         class Meta(type):
             def __subclasscheck__(mcls, cls):
                 return False
-        class Base:
-            __metaclass__ = Meta
+        class Base(metaclass=Meta):
+            pass
         class Sub(Base):
             pass
         return Base, Sub""")
@@ -306,17 +306,20 @@
             raises(TypeError, operate, A())
 
     def test_missing_getattribute(self):
+        """
         class X(object):
             pass
 
-        class Y(X):
-            class __metaclass__(type):
-                def mro(cls):
-                    return [cls, X]
+        class metaclass(type):
+            def mro(cls):
+                return [cls, X]
+        class Y(X, metaclass=metaclass):
+            pass
 
         x = X()
         x.__class__ = Y
         raises(AttributeError, getattr, x, 'a')
+        """
 
     def test_unordeable_types(self):
         class A(object): pass


More information about the pypy-commit mailing list