diff options
author | Marc Abramowitz <marc@marc-abramowitz.com> | 2012-07-10 09:29:18 -0700 |
---|---|---|
committer | Marc Abramowitz <marc@marc-abramowitz.com> | 2012-07-10 09:29:18 -0700 |
commit | 65db1ac3c0e90bbe541caa1902314aa097f1997a (patch) | |
tree | 1cad45506f2a160f6b198144d9b9b481240f1670 | |
parent | c35e781466eb6c630e1321489927a4390401bb9c (diff) | |
download | factory-boy-65db1ac3c0e90bbe541caa1902314aa097f1997a.tar factory-boy-65db1ac3c0e90bbe541caa1902314aa097f1997a.tar.gz |
Switch `sorted` argument from `cmp` to `key`.
-rw-r--r-- | factory/utils.py | 12 | ||||
-rw-r--r-- | tests/test_utils.py | 18 |
2 files changed, 1 insertions, 29 deletions
diff --git a/factory/utils.py b/factory/utils.py index 2fcd7ff..ce72a9a 100644 --- a/factory/utils.py +++ b/factory/utils.py @@ -57,16 +57,6 @@ def extract_dict(prefix, kwargs, pop=True, exclude=()): return extracted -def declength_compare(a, b): - """Compare objects, choosing longest first.""" - if len(a) > len(b): - return -1 - elif len(a) < len(b): - return 1 - else: - return cmp(a, b) - - def multi_extract_dict(prefixes, kwargs, pop=True, exclude=()): """Extracts all values from a given list of prefixes. @@ -78,7 +68,7 @@ def multi_extract_dict(prefixes, kwargs, pop=True, exclude=()): """ results = {} exclude = list(exclude) - for prefix in sorted(prefixes, cmp=declength_compare): + for prefix in sorted(prefixes, key=lambda x: -len(x)): extracted = extract_dict(prefix, kwargs, pop=pop, exclude=exclude) results[prefix] = extracted exclude.extend( diff --git a/tests/test_utils.py b/tests/test_utils.py index 6fd6ee2..f30c0e3 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -25,24 +25,6 @@ from factory import utils from .compat import unittest -class DecLengthCompareTestCase(unittest.TestCase): - def test_reciprocity(self): - self.assertEqual(1, utils.declength_compare('a', 'bb')) - self.assertEqual(-1, utils.declength_compare('aa', 'b')) - - def test_not_lexical(self): - self.assertEqual(1, utils.declength_compare('abc', 'aaaa')) - self.assertEqual(-1, utils.declength_compare('aaaa', 'abc')) - - def test_same_length(self): - self.assertEqual(-1, utils.declength_compare('abc', 'abd')) - self.assertEqual(1, utils.declength_compare('abe', 'abd')) - - def test_equality(self): - self.assertEqual(0, utils.declength_compare('abc', 'abc')) - self.assertEqual(0, utils.declength_compare([1, 2, 3], [1, 2, 3])) - - class ExtractDictTestCase(unittest.TestCase): def test_empty_dict(self): self.assertEqual({}, utils.extract_dict('foo', {})) |