summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-10-16 19:34:46 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-10-16 19:34:46 (GMT)
commit60192084c405292f874d886eed05ed83614d20c4 (patch)
tree390e2ac0930a866fb1a97d35b469109f09df3ecc /Lib
parentaaebe1c11d0eccc067cb6e5bb4e28543441fd2df (diff)
downloadcpython-60192084c405292f874d886eed05ed83614d20c4.zip
cpython-60192084c405292f874d886eed05ed83614d20c4.tar.gz
cpython-60192084c405292f874d886eed05ed83614d20c4.tar.bz2
remove some more references to __cmp__ #1717
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_class.py9
-rw-r--r--Lib/test/test_descr.py59
-rw-r--r--Lib/test/test_hash.py1
-rw-r--r--Lib/test/test_long.py14
-rw-r--r--Lib/test/test_richcmp.py2
-rw-r--r--Lib/test/test_set.py3
6 files changed, 26 insertions, 62 deletions
diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py
index cabf715..552c521 100644
--- a/Lib/test/test_class.py
+++ b/Lib/test/test_class.py
@@ -92,10 +92,6 @@ def __float__(self, *args):
return 1.0
@trackCall
-def __cmp__(self, *args):
- return 0
-
-@trackCall
def __eq__(self, *args):
return True
@@ -465,11 +461,6 @@ class ClassTests(unittest.TestCase):
hash(C0()) # This should work; the next two should raise TypeError
- class C1:
- def __cmp__(self, other): return 0
-
- self.assertRaises(TypeError, hash, C1())
-
class C2:
def __eq__(self, other): return 1
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 3c0bae0..85df9dc 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -1566,7 +1566,7 @@ order (MRO) for bases """
for i in range(10):
self.assert_(i in d1)
self.assertFalse(10 in d1)
- # Test overridden behavior for static classes
+ # Test overridden behavior
class Proxy(object):
def __init__(self, x):
self.x = x
@@ -1578,8 +1578,14 @@ order (MRO) for bases """
return self.x == other
def __ne__(self, other):
return self.x != other
- def __cmp__(self, other):
- return cmp(self.x, other.x)
+ def __ge__(self, other):
+ return self.x >= other
+ def __gt__(self, other):
+ return self.x > other
+ def __le__(self, other):
+ return self.x <= other
+ def __lt__(self, other):
+ return self.x < other
def __str__(self):
return "Proxy:%s" % self.x
def __repr__(self):
@@ -1596,9 +1602,10 @@ order (MRO) for bases """
self.assertNotEqual(p0, p1)
self.assert_(not p0 != p0)
self.assertEqual(not p0, p1)
- self.assertEqual(cmp(p0, p1), -1)
- self.assertEqual(cmp(p0, p0), 0)
- self.assertEqual(cmp(p0, p_1), 1)
+ self.assert_(p0 < p1)
+ self.assert_(p0 <= p1)
+ self.assert_(p1 > p0)
+ self.assert_(p1 >= p0)
self.assertEqual(str(p0), "Proxy:0")
self.assertEqual(repr(p0), "Proxy(0)")
p10 = Proxy(range(10))
@@ -1606,46 +1613,6 @@ order (MRO) for bases """
for i in range(10):
self.assert_(i in p10)
self.assertFalse(10 in p10)
- # Test overridden behavior for dynamic classes
- class DProxy(object):
- def __init__(self, x):
- self.x = x
- def __bool__(self):
- return not not self.x
- def __hash__(self):
- return hash(self.x)
- def __eq__(self, other):
- return self.x == other
- def __ne__(self, other):
- return self.x != other
- def __cmp__(self, other):
- return cmp(self.x, other.x)
- def __str__(self):
- return "DProxy:%s" % self.x
- def __repr__(self):
- return "DProxy(%r)" % self.x
- def __contains__(self, value):
- return value in self.x
- p0 = DProxy(0)
- p1 = DProxy(1)
- p_1 = DProxy(-1)
- self.assertFalse(p0)
- self.assert_(not not p1)
- self.assertEqual(hash(p0), hash(0))
- self.assertEqual(p0, p0)
- self.assertNotEqual(p0, p1)
- self.assertNotEqual(not p0, p0)
- self.assertEqual(not p0, p1)
- self.assertEqual(cmp(p0, p1), -1)
- self.assertEqual(cmp(p0, p0), 0)
- self.assertEqual(cmp(p0, p_1), 1)
- self.assertEqual(str(p0), "DProxy:0")
- self.assertEqual(repr(p0), "DProxy(0)")
- p10 = DProxy(range(10))
- self.assertFalse(-1 in p10)
- for i in range(10):
- self.assert_(i in p10)
- self.assertFalse(10 in p10)
## # Safety test for __cmp__
## def unsafecmp(a, b):
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
index 56974b8..59e43dc 100644
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -78,7 +78,6 @@ class HashInheritanceTestCase(unittest.TestCase):
]
error_expected = [NoHash(),
OnlyEquality(),
- OnlyCmp(),
]
def test_default_hash(self):
diff --git a/Lib/test/test_long.py b/Lib/test/test_long.py
index dc04bad..a1db26a 100644
--- a/Lib/test/test_long.py
+++ b/Lib/test/test_long.py
@@ -669,10 +669,22 @@ class LongTest(unittest.TestCase):
else:
raise TypeError("can't deal with %r" % val)
- def __cmp__(self, other):
+ def _cmp__(self, other):
if not isinstance(other, Rat):
other = Rat(other)
return cmp(self.n * other.d, self.d * other.n)
+ def __eq__(self, other):
+ return self._cmp__(other) == 0
+ def __ne__(self, other):
+ return self._cmp__(other) != 0
+ def __ge__(self, other):
+ return self._cmp__(other) >= 0
+ def __gt__(self, other):
+ return self._cmp__(other) > 0
+ def __le__(self, other):
+ return self._cmp__(other) <= 0
+ def __lt__(self, other):
+ return self._cmp__(other) < 0
cases = [0, 0.001, 0.99, 1.0, 1.5, 1e20, 1e200]
# 2**48 is an important boundary in the internals. 2**53 is an
diff --git a/Lib/test/test_richcmp.py b/Lib/test/test_richcmp.py
index 435de75..72e636d 100644
--- a/Lib/test/test_richcmp.py
+++ b/Lib/test/test_richcmp.py
@@ -198,13 +198,11 @@ class MiscTest(unittest.TestCase):
def __le__(self, other): raise TestFailed("This shouldn't happen")
def __ge__(self, other): raise TestFailed("This shouldn't happen")
def __ne__(self, other): raise TestFailed("This shouldn't happen")
- def __cmp__(self, other): raise RuntimeError("expected")
a = Misb()
b = Misb()
self.assertEqual(a<b, 0)
self.assertEqual(a==b, 0)
self.assertEqual(a>b, 0)
- self.assertRaises(RuntimeError, cmp, a, b)
def test_not(self):
# Check that exceptions in __bool__ are properly
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py
index 0effd65..614c9c0 100644
--- a/Lib/test/test_set.py
+++ b/Lib/test/test_set.py
@@ -202,9 +202,6 @@ class TestJointOps(unittest.TestCase):
s = self.thetype(t)
self.assertEqual(len(s), 3)
- def test_compare(self):
- self.assertRaises(TypeError, self.s.__cmp__, self.s)
-
def test_sub_and_super(self):
p, q, r = map(self.thetype, ['ab', 'abcde', 'def'])
self.assert_(p < q)