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 @@
#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 @@ check_argument_cmp(PyObject *arg)
/* 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;
......
......@@ -112,6 +112,7 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
# 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 @@ class OOBTreeTest(BTreeTests, unittest.TestCase):
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
......
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