diff options
author | Armin Rigo <arigo@tunes.org> | 2003-10-28 12:05:48 +0000 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2003-10-28 12:05:48 +0000 |
commit | 8cbe70f474e47964f45a14a4e265a30ce2fedac9 (patch) | |
tree | 27ae29f45de7f7075c4b4a1ee153496b21c28acb /Lib/test/test_richcmp.py | |
parent | f426ab0fb21e06f226e83a2f59ec7c1e8d523661 (diff) | |
download | cpython-8cbe70f474e47964f45a14a4e265a30ce2fedac9.tar.gz |
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.py | 63 |
1 files changed, 21 insertions, 42 deletions
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py index 5ade8ede56..006b1528c9 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): |