def test_keys_to_cmp_two_keys_neg_a_neg_b(): cmp_this = keys_to_cmp(['~a', '~b']) assert cmp_this(da1b2, da1b1) < 0 assert cmp_this(da1b1, da1b2) > 0 assert cmp_this(da1b1, da1b1) == 0 assert cmp_this(da1b2, da2b1) > 0 assert cmp_this(da1b1, da1b1) == 0 assert cmp_this(da2b1, da1b1) < 0
def test_keys_to_cmp_two_keys_a_b(): cmp_this = keys_to_cmp(['a', 'b']) assert cmp_this(da1b2, da1b1) > 0 assert cmp_this(da1b1, da1b2) < 0 assert cmp_this(da1b1, da1b1) == 0 assert cmp_this(da1b2, da2b1) < 0 assert cmp_this(da1b1, da1b1) == 0 assert cmp_this(da2b1, da1b1) > 0
def __init__(self, ns): super(Sort, self).__init__(ns) if not self.ns.sort_key: raise ParameterError("sort: no key(s) given") self.mods = {} for m in self.ns.module: self.mods[m] = __import__(m) self.cmp_keys = keys_to_cmp(self.ns.sort_key)
def make_key(key_tuple): return cmp_to_key(keys_to_cmp(key_tuple))
def test_keys_to_cmp_one_key_a(): cmp_this = keys_to_cmp(['a']) assert cmp_this(da1b2, da2b1) < 0 assert cmp_this(da1b1, da1b1) == 0 assert cmp_this(da2b1, da1b1) > 0