Example #1
0
def test__illegal_algorithm_raises_error():
    try:
        natcmp(0, 0, alg="Just random stuff")
        assert False

    except ValueError:
        assert True

    except Exception:
        assert False
Example #2
0
def test__natcmp_works_the_same_for_floats_as_cmp(x, y):
    assert py23_cmp(x, y) == natcmp(x, y)
Example #3
0
def test__natcmp_works_the_same_for_integers_as_cmp(x, y):
    assert py23_cmp(x, y) == natcmp(x, y)
Example #4
0
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
Example #5
0
 def __cmp__(self, other):
     return natcmp(self.value, other.value)
Example #6
0
 def test_natcmp_works_the_same_for_floats_as_cmp(self, x, y):
     assert py23_cmp(x, y) == natcmp(x, y)
Example #7
0
 def test_illegal_algorithm_raises_error(self):
     with pytest.raises(ValueError):
         natcmp(0, 0, alg="Just random stuff")
Example #8
0
    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
Example #9
0
 def __cmp__(self, other):
     return natcmp(self.value, other.value)