summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-05 18:56:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2010-04-05 18:56:31 (GMT)
commitc50846aaef3e38d466ac9a0a87f72f09238e2061 (patch)
treef6ae48bcfbabb5107c971c240f3b06a549084f98 /Lib/unittest
parent5daab45158094e577b9791cda7d8a0f4e34f45cb (diff)
downloadcpython-c50846aaef3e38d466ac9a0a87f72f09238e2061.zip
cpython-c50846aaef3e38d466ac9a0a87f72f09238e2061.tar.gz
cpython-c50846aaef3e38d466ac9a0a87f72f09238e2061.tar.bz2
Forward port total_ordering() and cmp_to_key().
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/loader.py3
-rw-r--r--Lib/unittest/util.py9
2 files changed, 2 insertions, 10 deletions
diff --git a/Lib/unittest/loader.py b/Lib/unittest/loader.py
index 5d11b6e..f00f38d 100644
--- a/Lib/unittest/loader.py
+++ b/Lib/unittest/loader.py
@@ -5,6 +5,7 @@ import re
import sys
import traceback
import types
+import functools
from fnmatch import fnmatch
@@ -141,7 +142,7 @@ class TestLoader(object):
testFnNames = testFnNames = list(filter(isTestMethod,
dir(testCaseClass)))
if self.sortTestMethodsUsing:
- testFnNames.sort(key=util.CmpToKey(self.sortTestMethodsUsing))
+ testFnNames.sort(key=functools.cmp_to_key(self.sortTestMethodsUsing))
return testFnNames
def discover(self, start_dir, pattern='test*.py', top_level_dir=None):
diff --git a/Lib/unittest/util.py b/Lib/unittest/util.py
index 736c202..ea8a68d 100644
--- a/Lib/unittest/util.py
+++ b/Lib/unittest/util.py
@@ -70,15 +70,6 @@ def unorderable_list_difference(expected, actual):
# anything left in actual is unexpected
return missing, actual
-def CmpToKey(mycmp):
- 'Convert a cmp= function into a key= function'
- class K(object):
- def __init__(self, obj, *args):
- self.obj = obj
- def __lt__(self, other):
- return mycmp(self.obj, other.obj) == -1
- return K
-
def three_way_cmp(x, y):
"""Return -1 if x < y, 0 if x == y and 1 if x > y"""
return (x > y) - (x < y)