[pypy-commit] pypy default: Complete the tests, and fix them with a bit of special-casing.

arigo noreply at buildbot.pypy.org
Fri Aug 26 14:55:47 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r46790:869f78b680d2
Date: 2011-08-26 15:01 +0200
http://bitbucket.org/pypy/pypy/changeset/869f78b680d2/

Log:	Complete the tests, and fix them with a bit of special-casing. XXX
	and all that. Oh well.

diff --git a/pypy/module/__builtin__/test/test_classobj.py b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -981,62 +981,85 @@
         assert a.x == 2
         raises(TypeError, descr.__delete__, a)
 
+    def test_partial_ordering(self):
+        class A:
+            def __lt__(self, other):
+                return self
+        a1 = A()
+        a2 = A()
+        assert (a1 < a2) is a1
+        assert (a1 > a2) is a2
+
     def test_eq_order(self):
         # this gives the ordering of equality-related functions on top of
-        # CPython **for old-style classes**.  This test passes on CPython2.7
-        # but fails on PyPy.  If you run the same test with new-style classes,
-        # it fails on CPython too.
-        skip("far too obscure")
+        # CPython **for old-style classes**.
         class A:
-            def __eq__(self, other): return True
-            def __ne__(self, other): return True
-            def __lt__(self, other): return True
-            def __le__(self, other): return True
-            def __gt__(self, other): return True
-            def __ge__(self, other): return True
+            def __eq__(self, other): return self.__class__.__name__+':A.eq'
+            def __ne__(self, other): return self.__class__.__name__+':A.ne'
+            def __lt__(self, other): return self.__class__.__name__+':A.lt'
+            def __le__(self, other): return self.__class__.__name__+':A.le'
+            def __gt__(self, other): return self.__class__.__name__+':A.gt'
+            def __ge__(self, other): return self.__class__.__name__+':A.ge'
         class B:
-            def __eq__(self, other): return False
-            def __ne__(self, other): return False
-            def __lt__(self, other): return False
-            def __le__(self, other): return False
-            def __gt__(self, other): return False
-            def __ge__(self, other): return False
+            def __eq__(self, other): return self.__class__.__name__+':B.eq'
+            def __ne__(self, other): return self.__class__.__name__+':B.ne'
+            def __lt__(self, other): return self.__class__.__name__+':B.lt'
+            def __le__(self, other): return self.__class__.__name__+':B.le'
+            def __gt__(self, other): return self.__class__.__name__+':B.gt'
+            def __ge__(self, other): return self.__class__.__name__+':B.ge'
         #
-        assert A() == B()
-        assert A() != B()
-        assert A() <  B()
-        assert A() <= B()
-        assert A() >  B()
-        assert A() >= B()
+        assert (A() == B()) == 'A:A.eq'
+        assert (A() != B()) == 'A:A.ne'
+        assert (A() <  B()) == 'A:A.lt'
+        assert (A() <= B()) == 'A:A.le'
+        assert (A() >  B()) == 'A:A.gt'
+        assert (A() >= B()) == 'A:A.ge'
         #
-        assert not (B() == A())
-        assert not (B() != A())
-        assert not (B() <  A())
-        assert not (B() <= A())
-        assert not (B() >  A())
-        assert not (B() >= A())
+        assert (B() == A()) == 'B:B.eq'
+        assert (B() != A()) == 'B:B.ne'
+        assert (B() <  A()) == 'B:B.lt'
+        assert (B() <= A()) == 'B:B.le'
+        assert (B() >  A()) == 'B:B.gt'
+        assert (B() >= A()) == 'B:B.ge'
         #
         class C(A):
-            def __eq__(self, other): return False
-            def __ne__(self, other): return False
-            def __lt__(self, other): return False
-            def __le__(self, other): return False
-            def __gt__(self, other): return False
-            def __ge__(self, other): return False
+            def __eq__(self, other): return self.__class__.__name__+':C.eq'
+            def __ne__(self, other): return self.__class__.__name__+':C.ne'
+            def __lt__(self, other): return self.__class__.__name__+':C.lt'
+            def __le__(self, other): return self.__class__.__name__+':C.le'
+            def __gt__(self, other): return self.__class__.__name__+':C.gt'
+            def __ge__(self, other): return self.__class__.__name__+':C.ge'
         #
-        assert A() == C()
-        assert A() != C()
-        assert A() <  C()
-        assert A() <= C()
-        assert A() >  C()
-        assert A() >= C()
+        assert (A() == C()) == 'A:A.eq'
+        assert (A() != C()) == 'A:A.ne'
+        assert (A() <  C()) == 'A:A.lt'
+        assert (A() <= C()) == 'A:A.le'
+        assert (A() >  C()) == 'A:A.gt'
+        assert (A() >= C()) == 'A:A.ge'
         #
-        assert not (C() == A())
-        assert not (C() != A())
-        assert not (C() <  A())
-        assert not (C() <= A())
-        assert not (C() >  A())
-        assert not (C() >= A())
+        assert (C() == A()) == 'C:C.eq'
+        assert (C() != A()) == 'C:C.ne'
+        assert (C() <  A()) == 'C:C.lt'
+        assert (C() <= A()) == 'C:C.le'
+        assert (C() >  A()) == 'C:C.gt'
+        assert (C() >= A()) == 'C:C.ge'
+        #
+        class D(A):
+            pass
+        #
+        assert (A() == D()) == 'A:A.eq'
+        assert (A() != D()) == 'A:A.ne'
+        assert (A() <  D()) == 'A:A.lt'
+        assert (A() <= D()) == 'A:A.le'
+        assert (A() >  D()) == 'A:A.gt'
+        assert (A() >= D()) == 'A:A.ge'
+        #
+        assert (D() == A()) == 'D:A.eq'
+        assert (D() != A()) == 'D:A.ne'
+        assert (D() <  A()) == 'D:A.lt'
+        assert (D() <= A()) == 'D:A.le'
+        assert (D() >  A()) == 'D:A.gt'
+        assert (D() >= A()) == 'D:A.ge'
 
 
 class AppTestOldStyleClassStrDict(object):
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -724,13 +724,29 @@
         w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
         w_first = w_obj1
         w_second = w_obj2
-
-        if _same_class_w(space, w_obj1, w_obj2, w_typ1, w_typ2):
+        #
+        # special-case... :-(
+        if (space.is_oldstyle_instance(w_obj1) and
+            space.is_oldstyle_instance(w_obj2)):
+            assert isinstance(w_obj1, W_InstanceObject)
+            assert isinstance(w_obj2, W_InstanceObject)
+            w_class1 = w_obj1.w_class
+            w_class2 = w_obj2.w_class
+            if left == right and w_class1 is w_class2:
+                w_right_impl = None
+            else:
+                # Note that there is no revertion logic in this case.
+                w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2,
+                                                                       right)
+        # end of the special case
+        #
+        elif left == right and space.is_w(w_typ1, w_typ2):
             w_right_impl = None
         else:
             w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, right)
-            # XXX see binop_impl
-            if space.is_true(space.issubtype(w_typ2, w_typ1)):
+            if left != right and space.is_w(w_typ1, w_typ2):
+                pass
+            elif space.is_true(space.issubtype(w_typ2, w_typ1)):
                 w_obj1, w_obj2 = w_obj2, w_obj1
                 w_left_impl, w_right_impl = w_right_impl, w_left_impl
 
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
@@ -473,57 +473,83 @@
         assert not(C(1) == D(2))
         assert not(D(1) == C(2))
 
+    def test_partial_ordering(self):
+        class A(object):
+            def __lt__(self, other):
+                return self
+        a1 = A()
+        a2 = A()
+        assert (a1 < a2) is a1
+        assert (a1 > a2) is a2
+
     def test_eq_order(self):
         class A(object):
-            def __eq__(self, other): return True
-            def __ne__(self, other): return True
-            def __lt__(self, other): return True
-            def __le__(self, other): return True
-            def __gt__(self, other): return True
-            def __ge__(self, other): return True
+            def __eq__(self, other): return self.__class__.__name__+':A.eq'
+            def __ne__(self, other): return self.__class__.__name__+':A.ne'
+            def __lt__(self, other): return self.__class__.__name__+':A.lt'
+            def __le__(self, other): return self.__class__.__name__+':A.le'
+            def __gt__(self, other): return self.__class__.__name__+':A.gt'
+            def __ge__(self, other): return self.__class__.__name__+':A.ge'
         class B(object):
-            def __eq__(self, other): return False
-            def __ne__(self, other): return False
-            def __lt__(self, other): return False
-            def __le__(self, other): return False
-            def __gt__(self, other): return False
-            def __ge__(self, other): return False
+            def __eq__(self, other): return self.__class__.__name__+':B.eq'
+            def __ne__(self, other): return self.__class__.__name__+':B.ne'
+            def __lt__(self, other): return self.__class__.__name__+':B.lt'
+            def __le__(self, other): return self.__class__.__name__+':B.le'
+            def __gt__(self, other): return self.__class__.__name__+':B.gt'
+            def __ge__(self, other): return self.__class__.__name__+':B.ge'
         #
-        assert A() == B()
-        assert A() != B()
-        assert A() <  B()
-        assert A() <= B()
-        assert A() >  B()
-        assert A() >= B()
+        assert (A() == B()) == 'A:A.eq'
+        assert (A() != B()) == 'A:A.ne'
+        assert (A() <  B()) == 'A:A.lt'
+        assert (A() <= B()) == 'A:A.le'
+        assert (A() >  B()) == 'A:A.gt'
+        assert (A() >= B()) == 'A:A.ge'
         #
-        assert not (B() == A())
-        assert not (B() != A())
-        assert not (B() <  A())
-        assert not (B() <= A())
-        assert not (B() >  A())
-        assert not (B() >= A())
+        assert (B() == A()) == 'B:B.eq'
+        assert (B() != A()) == 'B:B.ne'
+        assert (B() <  A()) == 'B:B.lt'
+        assert (B() <= A()) == 'B:B.le'
+        assert (B() >  A()) == 'B:B.gt'
+        assert (B() >= A()) == 'B:B.ge'
         #
         class C(A):
-            def __eq__(self, other): return False
-            def __ne__(self, other): return False
-            def __lt__(self, other): return False
-            def __le__(self, other): return False
-            def __gt__(self, other): return False
-            def __ge__(self, other): return False
+            def __eq__(self, other): return self.__class__.__name__+':C.eq'
+            def __ne__(self, other): return self.__class__.__name__+':C.ne'
+            def __lt__(self, other): return self.__class__.__name__+':C.lt'
+            def __le__(self, other): return self.__class__.__name__+':C.le'
+            def __gt__(self, other): return self.__class__.__name__+':C.gt'
+            def __ge__(self, other): return self.__class__.__name__+':C.ge'
         #
-        assert not (A() == C())
-        assert not (A() != C())
-        assert not (A() <  C())
-        assert not (A() <= C())
-        assert not (A() >  C())
-        assert not (A() >= C())
+        assert (A() == C()) == 'C:C.eq'
+        assert (A() != C()) == 'C:C.ne'
+        assert (A() <  C()) == 'C:C.gt'
+        assert (A() <= C()) == 'C:C.ge'
+        assert (A() >  C()) == 'C:C.lt'
+        assert (A() >= C()) == 'C:C.le'
         #
-        assert not (C() == A())
-        assert not (C() != A())
-        assert not (C() <  A())
-        assert not (C() <= A())
-        assert not (C() >  A())
-        assert not (C() >= A())
+        assert (C() == A()) == 'C:C.eq'
+        assert (C() != A()) == 'C:C.ne'
+        assert (C() <  A()) == 'C:C.lt'
+        assert (C() <= A()) == 'C:C.le'
+        assert (C() >  A()) == 'C:C.gt'
+        assert (C() >= A()) == 'C:C.ge'
+        #
+        class D(A):
+            pass
+        #
+        assert (A() == D()) == 'D:A.eq'
+        assert (A() != D()) == 'D:A.ne'
+        assert (A() <  D()) == 'D:A.gt'
+        assert (A() <= D()) == 'D:A.ge'
+        assert (A() >  D()) == 'D:A.lt'
+        assert (A() >= D()) == 'D:A.le'
+        #
+        assert (D() == A()) == 'D:A.eq'
+        assert (D() != A()) == 'D:A.ne'
+        assert (D() <  A()) == 'D:A.lt'
+        assert (D() <= A()) == 'D:A.le'
+        assert (D() >  A()) == 'D:A.gt'
+        assert (D() >= A()) == 'D:A.ge'
 
     def test_addition(self):
         # Old-style


More information about the pypy-commit mailing list