def __new__(cls, x, y, alg=ns.DEFAULT): try: ns.DEFAULT | alg except TypeError: msg = "natsort_keygen: 'alg' argument must be from the enum 'ns'" raise ValueError(msg + ", got {}".format(py23_str(alg))) # Add the _DUMB option if the locale library is broken. if alg & ns.LOCALEALPHA and natsort.compat.locale.dumb_sort(): alg |= NS_DUMB if alg not in cls.cached_keys: cls.cached_keys[alg] = natsort_keygen(alg=alg) return py23_cmp(cls.cached_keys[alg](x), cls.cached_keys[alg](y))
def __new__(cls, x, y, alg=0, *args, **kwargs): try: alg = _args_to_enum(**kwargs) | alg except TypeError: msg = ("natsort_keygen: 'alg' argument must be " "from the enum 'ns'") raise ValueError(msg + ', got {0}'.format(py23_str(alg))) # Add the _DUMB option if the locale library is broken. if alg & ns.LOCALEALPHA and natsort.compat.locale.dumb_sort(): alg |= ns._DUMB if alg not in cls.cached_keys: cls.cached_keys[alg] = natsort_keygen(alg=alg) return py23_cmp(cls.cached_keys[alg](x), cls.cached_keys[alg](y))
def test_py23_cmp(x): assert py23_cmp(x, x) == 0 assert py23_cmp(x, x + 1) < 0 assert py23_cmp(x, x - 1) > 0
def test__natcmp_works_the_same_for_floats_as_cmp(x, y): assert py23_cmp(x, y) == natcmp(x, y)
def test__natcmp_works_the_same_for_integers_as_cmp(x, y): assert py23_cmp(x, y) == natcmp(x, y)
def test_natcmp_works_the_same_for_floats_as_cmp(self, x, y): assert py23_cmp(x, y) == natcmp(x, y)