diff options
author | Raymond Hettinger <python@rcn.com> | 2008-01-30 02:55:10 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-01-30 02:55:10 (GMT) |
commit | d4cb56d4e88c7e001bbaba2c80953db47632f199 (patch) | |
tree | 73c95e0223ed8a98fac797fc99ab1bffae9c5457 /Lib/unittest.py | |
parent | fd66e51c4c1ff9293b0f332d6ebc8093b2ef12bb (diff) | |
download | cpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.zip cpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.tar.gz cpython-d4cb56d4e88c7e001bbaba2c80953db47632f199.tar.bz2 |
Convert some custom sort comparison functions to equivalent key functions.
Diffstat (limited to 'Lib/unittest.py')
-rw-r--r-- | Lib/unittest.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/unittest.py b/Lib/unittest.py index adbbe8a..742871b 100644 --- a/Lib/unittest.py +++ b/Lib/unittest.py @@ -504,6 +504,15 @@ class FunctionTestCase(TestCase): # Locating and loading tests ############################################################################## +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 + class TestLoader: """This class is responsible for loading tests according to various criteria and returning them wrapped in a TestSuite @@ -598,7 +607,7 @@ class TestLoader: and hasattr(getattr(testCaseClass, attrname), '__call__') testFnNames = list(filter(isTestMethod, dir(testCaseClass))) if self.sortTestMethodsUsing: - testFnNames.sort(self.sortTestMethodsUsing) + testFnNames.sort(key=CmpToKey(self.sortTestMethodsUsing)) return testFnNames |