def test_empty_results(self): paginator = SequencePaginator([]) result = paginator.get_result(5) assert list(result) == [] assert result.prev == Cursor(0, 0, True, False) assert result.next == Cursor(0, 0, False, False) paginator = SequencePaginator([], reverse=True) result = paginator.get_result(5) assert list(result) == [] assert result.prev == Cursor(0, 0, True, False) assert result.next == Cursor(0, 0, False, False)
def test_descending_repeated_scores(self): paginator = SequencePaginator([(1, i) for i in range(10)], reverse=True) result = paginator.get_result(5) assert list(result) == [9, 8, 7, 6, 5] assert result.prev == Cursor(1, 0, True, False) assert result.next == Cursor(1, 5, False, True) result = paginator.get_result(5, result.next) assert list(result) == [4, 3, 2, 1, 0] assert result.prev == Cursor(1, 5, True, True) assert result.next == Cursor(1, 10, False, False) result = paginator.get_result(5, result.prev) assert list(result) == [9, 8, 7, 6, 5] assert result.prev == Cursor(1, 0, True, False) assert result.next == Cursor(1, 5, False, True) result = paginator.get_result(5, Cursor(-10, 0, False)) assert list(result) == [] assert result.prev == Cursor(1, 10, True, True) assert result.next == Cursor(1, 10, False, False)
def test_descending_simple(self): paginator = SequencePaginator([(i, i) for i in range(10)], reverse=True) result = paginator.get_result(5) assert list(result) == [9, 8, 7, 6, 5] assert result.prev == Cursor(9, 0, True, False) assert result.next == Cursor(4, 0, False, True) result = paginator.get_result(5, result.next) assert list(result) == [4, 3, 2, 1, 0] assert result.prev == Cursor(4, 0, True, True) assert result.next == Cursor(0, 1, False, False) result = paginator.get_result(5, result.prev) assert list(result) == [9, 8, 7, 6, 5] assert result.prev == Cursor(9, 0, True, False) assert result.next == Cursor(4, 0, False, True) result = paginator.get_result(5, Cursor(-10, 0, False)) assert list(result) == [] assert result.prev == Cursor(0, 1, True, True) assert result.next == Cursor(0, 1, False, False)
def test_ascending_simple(self): paginator = SequencePaginator([(i, i) for i in range(10)], reverse=False) result = paginator.get_result(5) assert list(result) == [0, 1, 2, 3, 4] assert result.prev == Cursor(0, 0, True, False) assert result.next == Cursor(5, 0, False, True) result = paginator.get_result(5, result.next) assert list(result) == [5, 6, 7, 8, 9] assert result.prev == Cursor(5, 0, True, True) assert result.next == Cursor(9, 1, False, False) result = paginator.get_result(5, result.prev) assert list(result) == [0, 1, 2, 3, 4] assert result.prev == Cursor(0, 0, True, False) assert result.next == Cursor(5, 0, False, True) result = paginator.get_result(5, Cursor(100, 0, False)) assert list(result) == [] assert result.prev == Cursor(9, 1, True, True) assert result.next == Cursor(9, 1, False, False)
def test_hits(self): n = 10 paginator = SequencePaginator([(i, i) for i in range(n)]) assert paginator.get_result(5, count_hits=True).hits == n