summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2010-04-04 21:45:01 +0000
committerRaymond Hettinger <python@rcn.com>2010-04-04 21:45:01 +0000
commitbb006cf26cc41aefcddc8f06722c524826aacefa (patch)
tree5d0e82402052f188ea868cf94497eba52a7b38fd /Lib/test
parent4f185228b084ee45ef822198762154457dc343db (diff)
downloadcpython-git-bb006cf26cc41aefcddc8f06722c524826aacefa.tar.gz
Add tests for cmp_to_key.
Adopt PEP 8 compliant function name. Factor-out existing uses cmp_to_key. Update documentation to use internal pointers instead of external resource.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_functools.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 2549e05c14..44992b8c5b 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -338,7 +338,12 @@ class TestReduce(unittest.TestCase):
self.assertEqual(reduce(42, "", "1"), "1") # func is never called with one item
self.assertRaises(TypeError, reduce, 42, (42, 42))
-
+class TestCmpToKey(unittest.TestCase):
+ def test_cmp_to_key(self):
+ def mycmp(x, y):
+ return y - x
+ self.assertEqual(sorted(range(5), key=functools.cmp_to_key(mycmp)),
+ [4, 3, 2, 1, 0])
def test_main(verbose=None):