diff options
| author | Éric Araujo <merwok@netwok.org> | 2011-07-26 16:25:14 (GMT) |
|---|---|---|
| committer | Éric Araujo <merwok@netwok.org> | 2011-07-26 16:25:14 (GMT) |
| commit | 9e1af03fbb2a9fc1472ac866add02c99b0c88b16 (patch) | |
| tree | 25efce5bd9633ba8cb685c9c64464a49da941853 /Lib/test/list_tests.py | |
| parent | 76748b7033cdd52a95d78d85f2ec15244e5d0fd8 (diff) | |
| parent | a0e92a802815d55dafd303b39843ddd2b9784bdb (diff) | |
| download | cpython-9e1af03fbb2a9fc1472ac866add02c99b0c88b16.zip cpython-9e1af03fbb2a9fc1472ac866add02c99b0c88b16.tar.gz cpython-9e1af03fbb2a9fc1472ac866add02c99b0c88b16.tar.bz2 | |
Branch merge.
I moved the NEWS entry for the reindent fix to the right release section.
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 e3a7845..be054ea 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): @@ -443,7 +436,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: @@ -456,7 +449,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) @@ -468,7 +461,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) |
