Deleting cyclic object comparison.

SF patch 825639
http://mail.python.org/pipermail/python-dev/2003-October/039445.html
This commit is contained in:
Armin Rigo 2003-10-28 12:05:48 +00:00
parent 0e4f76405d
commit 2b3eb4062c
9 changed files with 109 additions and 275 deletions

View file

@ -224,57 +224,36 @@ class MiscTest(unittest.TestCase):
self.assertRaises(Exc, func, Bad())
def test_recursion(self):
# Check comparison for recursive objects
# Check that comparison for recursive objects fails gracefully
from UserList import UserList
a = UserList(); a.append(a)
b = UserList(); b.append(b)
self.assert_(a == b)
self.assert_(not a != b)
a.append(1)
self.assert_(a == a[0])
self.assert_(not a != a[0])
self.assert_(a != b)
self.assert_(not a == b)
b.append(0)
self.assert_(a != b)
self.assert_(not a == b)
a[1] = -1
self.assert_(a != b)
self.assert_(not a == b)
a = UserList()
b = UserList()
a.append(b)
b.append(a)
self.assert_(a == b)
self.assert_(not a != b)
self.assertRaises(RuntimeError, operator.eq, a, b)
self.assertRaises(RuntimeError, operator.ne, a, b)
self.assertRaises(RuntimeError, operator.lt, a, b)
self.assertRaises(RuntimeError, operator.le, a, b)
self.assertRaises(RuntimeError, operator.gt, a, b)
self.assertRaises(RuntimeError, operator.ge, a, b)
b.append(17)
# Even recursive lists of different lengths are different,
# but they cannot be ordered
self.assert_(not (a == b))
self.assert_(a != b)
self.assert_(not a == b)
self.assertRaises(RuntimeError, operator.lt, a, b)
self.assertRaises(RuntimeError, operator.le, a, b)
self.assertRaises(RuntimeError, operator.gt, a, b)
self.assertRaises(RuntimeError, operator.ge, a, b)
a.append(17)
self.assert_(a == b)
self.assert_(not a != b)
def test_recursion2(self):
# This test exercises the circular structure handling code
# in PyObject_RichCompare()
class Weird(object):
def __eq__(self, other):
return self != other
def __ne__(self, other):
return self == other
def __lt__(self, other):
return self > other
def __gt__(self, other):
return self < other
self.assert_(Weird() == Weird())
self.assert_(not (Weird() != Weird()))
for op in opmap["lt"]:
self.assertRaises(ValueError, op, Weird(), Weird())
self.assertRaises(RuntimeError, operator.eq, a, b)
self.assertRaises(RuntimeError, operator.ne, a, b)
a.insert(0, 11)
b.insert(0, 12)
self.assert_(not (a == b))
self.assert_(a != b)
self.assert_(a < b)
class DictTest(unittest.TestCase):