diff options
| author | Éric Araujo <merwok@netwok.org> | 2011-07-29 01:11:09 (GMT) |
|---|---|---|
| committer | Éric Araujo <merwok@netwok.org> | 2011-07-29 01:11:09 (GMT) |
| commit | 2527796a22404d5b8cb0e498a965c6b4a743caac (patch) | |
| tree | 5bc07b91dde0085cc09c3336ed740f6817f11fc3 /Lib/test/list_tests.py | |
| parent | 1e3a68d36b08cd9d59084a37c8cb6c2d911868ce (diff) | |
| parent | cf534817adc49b2562d175fabd3e3992d25063fe (diff) | |
| download | cpython-2527796a22404d5b8cb0e498a965c6b4a743caac.zip cpython-2527796a22404d5b8cb0e498a965c6b4a743caac.tar.gz cpython-2527796a22404d5b8cb0e498a965c6b4a743caac.tar.bz2 | |
Merge from 3.2 (#10318, #12255, #12043, #12417 and other fixes)
Diffstat (limited to 'Lib/test/list_tests.py')
| -rw-r--r-- | Lib/test/list_tests.py | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py index 0c656fd..42e118b 100644 --- a/Lib/test/list_tests.py +++ b/Lib/test/list_tests.py @@ -4,17 +4,10 @@ Tests common to list and UserList.UserList import sys import os +from functools import cmp_to_key from test import support, seq_tests -def CmpToKey(mycmp): - 'Convert a cmp= function into a key= function' - class K(object): - def __init__(self, obj): - self.obj = obj - def __lt__(self, other): - return mycmp(self.obj, other.obj) == -1 - return K class CommonTest(seq_tests.CommonTest): @@ -484,7 +477,7 @@ class CommonTest(seq_tests.CommonTest): return 1 else: # a > b return -1 - u.sort(key=CmpToKey(revcmp)) + u.sort(key=cmp_to_key(revcmp)) self.assertEqual(u, self.type2test([2,1,0,-1,-2])) # The following dumps core in unpatched Python 1.5: @@ -497,7 +490,7 @@ class CommonTest(seq_tests.CommonTest): else: # xmod > ymod return 1 z = self.type2test(range(12)) - z.sort(key=CmpToKey(myComparison)) + z.sort(key=cmp_to_key(myComparison)) self.assertRaises(TypeError, z.sort, 2) @@ -509,7 +502,8 @@ class CommonTest(seq_tests.CommonTest): return -1 else: # x > y return 1 - self.assertRaises(ValueError, z.sort, key=CmpToKey(selfmodifyingComparison)) + self.assertRaises(ValueError, z.sort, + key=cmp_to_key(selfmodifyingComparison)) self.assertRaises(TypeError, z.sort, 42, 42, 42, 42) |
