[Checkins] SVN: BTrees/branches/py3k/ Clarify tests for default comparison.

Tres Seaver cvs-admin at zope.org
Fri Dec 14 23:48:59 UTC 2012


Log message for revision 128674:
  Clarify tests for default comparison.
  
  Fix them under Py3k.

Changed:
  _U  BTrees/branches/py3k/
  U   BTrees/branches/py3k/BTrees/objectkeymacros.h
  U   BTrees/branches/py3k/BTrees/tests/test_OOBTree.py

-=-
Modified: BTrees/branches/py3k/BTrees/objectkeymacros.h
===================================================================
--- BTrees/branches/py3k/BTrees/objectkeymacros.h	2012-12-14 22:37:21 UTC (rev 128673)
+++ BTrees/branches/py3k/BTrees/objectkeymacros.h	2012-12-14 23:48:58 UTC (rev 128674)
@@ -5,7 +5,7 @@
 #include "Python.h"
 #include "_compat.h"
 
-static PyObject *object_;
+static PyObject *object_; /* initialized in BTreeModuleTemplate init */
 
 static int
 check_argument_cmp(PyObject *arg)
@@ -16,12 +16,12 @@
     /*        arg->ob_type->tp_compare, */
     /*        ((PyTypeObject *)object_)->ob_type->tp_compare); */
 
+#ifdef PY3K
+    if (Py_TYPE(arg)->tp_richcompare == Py_TYPE(object_)->tp_richcompare)
+#else
     if (Py_TYPE(arg)->tp_richcompare == NULL
-#ifndef PY3K
-        && Py_TYPE(arg)->tp_compare ==
-                ((PyTypeObject *)object_)->ob_type->tp_compare
+        && Py_TYPE(arg)->tp_compare == Py_TYPE(object_)->tp_compare)
 #endif
-    )
     {
         PyErr_SetString(PyExc_TypeError, "Object has default comparison");
         return 0;

Modified: BTrees/branches/py3k/BTrees/tests/test_OOBTree.py
===================================================================
--- BTrees/branches/py3k/BTrees/tests/test_OOBTree.py	2012-12-14 22:37:21 UTC (rev 128673)
+++ BTrees/branches/py3k/BTrees/tests/test_OOBTree.py	2012-12-14 23:48:58 UTC (rev 128674)
@@ -112,6 +112,7 @@
         # used in a function that's used in lots of places.
         # Otherwise, there are many permutations that would have to be
         # checked.
+        from .._compat import PY2
         t = self._makeOne()
 
         class C(object):
@@ -119,30 +120,31 @@
 
         self.assertRaises(TypeError, lambda : t.__setitem__(C(), 1))
 
-        class C(object):
-            def __cmp__(*args):
-                return 1
+        if PY2: # we only check for __cmp__ on Python2
 
-        c = C()
-        t[c] = 1
+            class With___cmp__(object):
+                def __cmp__(*args):
+                    return 1
+            c = With___cmp__()
+            t[c] = 1
 
-        t.clear()
+            t.clear()
 
-        class C(object):
+        class With___lt__(object):
             def __lt__(*args):
                 return 1
 
-        c = C()
+        c = With___lt__()
         t[c] = 1
 
         t.clear()
 
 
-#class OOBTreePyTest(OOBTreeTest):
+class OOBTreePyTest(OOBTreeTest):
 #
 # Right now, we can't match the C extension's test / prohibition of the
 # default 'object' comparison semantics.
-class OOBTreePyTest(BTreeTests, unittest.TestCase):
+#class OOBTreePyTest(BTreeTests, unittest.TestCase):
 
     def _makeOne(self):
         from BTrees.OOBTree import OOBTreePy



More information about the checkins mailing list