diff options
Diffstat (limited to 'Lib/test/list_tests.py')
-rw-r--r-- | Lib/test/list_tests.py | 22 |
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) |