summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_richcmp.py
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2003-10-28 12:05:48 (GMT)
committerArmin Rigo <arigo@tunes.org>2003-10-28 12:05:48 (GMT)
commit2b3eb4062c5e50abf854f7e68038243ca7c07217 (patch)
treefc5a73861c6e4feb4f4bc497165fa28d9c81d79f /Lib/test/test_richcmp.py
parent0e4f76405d79e95abfdda21b9dfc10c7f32340e8 (diff)
downloadcpython-2b3eb4062c5e50abf854f7e68038243ca7c07217.zip
cpython-2b3eb4062c5e50abf854f7e68038243ca7c07217.tar.gz
cpython-2b3eb4062c5e50abf854f7e68038243ca7c07217.tar.bz2
Deleting cyclic object comparison.
SF patch 825639 http://mail.python.org/pipermail/python-dev/2003-October/039445.html
Diffstat (limited to 'Lib/test/test_richcmp.py')
-rw-r--r--Lib/test/test_richcmp.py63
1 files changed, 21 insertions, 42 deletions
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
index 5ade8ed..006b152 100644
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -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):