def test__illegal_algorithm_raises_error(): try: natcmp(0, 0, alg="Just random stuff") assert False except ValueError: assert True except Exception: assert False
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__keys_are_being_cached(): natcmp.cached_keys = {} assert len(natcmp.cached_keys) == 0 natcmp(0, 0) assert len(natcmp.cached_keys) == 1 natcmp(0, 0) assert len(natcmp.cached_keys) == 1 natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 2 natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 2 with patch('natsort.compat.locale.dumb_sort', return_value=True): natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 3 with patch('natsort.compat.locale.dumb_sort', return_value=True): natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 3
def __cmp__(self, other): return natcmp(self.value, other.value)
def test_natcmp_works_the_same_for_floats_as_cmp(self, x, y): assert py23_cmp(x, y) == natcmp(x, y)
def test_illegal_algorithm_raises_error(self): with pytest.raises(ValueError): natcmp(0, 0, alg="Just random stuff")
def test_keys_are_being_cached(self, mocker): natcmp.cached_keys = {} assert len(natcmp.cached_keys) == 0 natcmp(0, 0) assert len(natcmp.cached_keys) == 1 natcmp(0, 0) assert len(natcmp.cached_keys) == 1 with mocker.patch("natsort.compat.locale.dumb_sort", return_value=False): natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 2 natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 2 with mocker.patch("natsort.compat.locale.dumb_sort", return_value=True): natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 3 natcmp(0, 0, alg=ns.L) assert len(natcmp.cached_keys) == 3