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.
This commit is contained in:
Raymond Hettinger 2010-04-04 21:45:01 +00:00
parent 4f185228b0
commit bb006cf26c
8 changed files with 17 additions and 31 deletions

View file

@ -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):