Commit 15da8c11 authored by Tres Seaver's avatar Tres Seaver

Clarify tests for default comparison.

Fix them under Py3k.
parent 83029192
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include "Python.h" #include "Python.h"
#include "_compat.h" #include "_compat.h"
static PyObject *object_; static PyObject *object_; /* initialized in BTreeModuleTemplate init */
static int static int
check_argument_cmp(PyObject *arg) check_argument_cmp(PyObject *arg)
...@@ -16,12 +16,12 @@ check_argument_cmp(PyObject *arg) ...@@ -16,12 +16,12 @@ check_argument_cmp(PyObject *arg)
/* arg->ob_type->tp_compare, */ /* arg->ob_type->tp_compare, */
/* ((PyTypeObject *)object_)->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 if (Py_TYPE(arg)->tp_richcompare == NULL
#ifndef PY3K && Py_TYPE(arg)->tp_compare == Py_TYPE(object_)->tp_compare)
&& Py_TYPE(arg)->tp_compare ==
((PyTypeObject *)object_)->ob_type->tp_compare
#endif #endif
)
{ {
PyErr_SetString(PyExc_TypeError, "Object has default comparison"); PyErr_SetString(PyExc_TypeError, "Object has default comparison");
return 0; return 0;
......
...@@ -112,6 +112,7 @@ class OOBTreeTest(BTreeTests, unittest.TestCase): ...@@ -112,6 +112,7 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
# used in a function that's used in lots of places. # used in a function that's used in lots of places.
# Otherwise, there are many permutations that would have to be # Otherwise, there are many permutations that would have to be
# checked. # checked.
from .._compat import PY2
t = self._makeOne() t = self._makeOne()
class C(object): class C(object):
...@@ -119,30 +120,31 @@ class OOBTreeTest(BTreeTests, unittest.TestCase): ...@@ -119,30 +120,31 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
self.assertRaises(TypeError, lambda : t.__setitem__(C(), 1)) self.assertRaises(TypeError, lambda : t.__setitem__(C(), 1))
class C(object): if PY2: # we only check for __cmp__ on Python2
def __cmp__(*args):
return 1
c = C() class With___cmp__(object):
t[c] = 1 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): def __lt__(*args):
return 1 return 1
c = C() c = With___lt__()
t[c] = 1 t[c] = 1
t.clear() t.clear()
#class OOBTreePyTest(OOBTreeTest): class OOBTreePyTest(OOBTreeTest):
# #
# Right now, we can't match the C extension's test / prohibition of the # Right now, we can't match the C extension's test / prohibition of the
# default 'object' comparison semantics. # default 'object' comparison semantics.
class OOBTreePyTest(BTreeTests, unittest.TestCase): #class OOBTreePyTest(BTreeTests, unittest.TestCase):
def _makeOne(self): def _makeOne(self):
from BTrees.OOBTree import OOBTreePy from BTrees.OOBTree import OOBTreePy
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment