summaryrefslogtreecommitdiffstats
path: root/Lib/test/list_tests.py
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2009-01-27 18:17:45 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2009-01-27 18:17:45 (GMT)
commita56c467ac39ab1a6a2e9dc2fa41a9f573f989839 (patch)
treef65fc7d2a4359328f10c1dd9122a692e78e71e8a /Lib/test/list_tests.py
parent191e850053128f726d6562e1d8306dfe5e4aa8aa (diff)
downloadcpython-a56c467ac39ab1a6a2e9dc2fa41a9f573f989839.zip
cpython-a56c467ac39ab1a6a2e9dc2fa41a9f573f989839.tar.gz
cpython-a56c467ac39ab1a6a2e9dc2fa41a9f573f989839.tar.bz2
Issue #1717: Remove cmp. Stage 1: remove all uses of cmp and __cmp__ from
the standard library and tests.
Diffstat (limited to 'Lib/test/list_tests.py')
-rw-r--r--Lib/test/list_tests.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index 5b1aa75..67492f3 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -439,13 +439,24 @@ class CommonTest(seq_tests.CommonTest):
self.assertRaises(TypeError, u.sort, 42, 42)
def revcmp(a, b):
- return cmp(b, a)
+ if a == b:
+ return 0
+ elif a < b:
+ return 1
+ else: # a > b
+ return -1
u.sort(key=CmpToKey(revcmp))
self.assertEqual(u, self.type2test([2,1,0,-1,-2]))
# The following dumps core in unpatched Python 1.5:
def myComparison(x,y):
- return cmp(x%3, y%7)
+ xmod, ymod = x%3, y%7
+ if xmod == ymod:
+ return 0
+ elif xmod < ymod:
+ return -1
+ else: # xmod > ymod
+ return 1
z = self.type2test(range(12))
z.sort(key=CmpToKey(myComparison))
@@ -453,7 +464,12 @@ class CommonTest(seq_tests.CommonTest):
def selfmodifyingComparison(x,y):
z.append(1)
- return cmp(x, y)
+ if x == y:
+ return 0
+ elif x < y:
+ return -1
+ else: # x > y
+ return 1
self.assertRaises(ValueError, z.sort, key=CmpToKey(selfmodifyingComparison))
self.assertRaises(TypeError, z.sort, 42, 42, 42, 42)