diff --git a/swh/lister/tests/test_utils.py b/swh/lister/tests/test_utils.py --- a/swh/lister/tests/test_utils.py +++ b/swh/lister/tests/test_utils.py @@ -11,7 +11,12 @@ @pytest.mark.parametrize( "total_pages,nb_pages,expected_ranges", - [(14, 5, [(0, 5), (5, 10), (10, 14)]), (19, 10, [(0, 10), (10, 19)])], + [ + (14, 5, [(0, 4), (5, 9), (10, 14)]), + (19, 10, [(0, 9), (10, 19)]), + (20, 3, [(0, 2), (3, 5), (6, 8), (9, 11), (12, 14), (15, 17), (18, 20)]), + (21, 3, [(0, 2), (3, 5), (6, 8), (9, 11), (12, 14), (15, 17), (18, 21),],), + ], ) def test_split_range(total_pages, nb_pages, expected_ranges): actual_ranges = list(utils.split_range(total_pages, nb_pages)) diff --git a/swh/lister/utils.py b/swh/lister/utils.py --- a/swh/lister/utils.py +++ b/swh/lister/utils.py @@ -1,13 +1,15 @@ -# Copyright (C) 2018 the Software Heritage developers +# Copyright (C) 2018-2020 the Software Heritage developers # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from typing import Iterator, Tuple -def split_range(total_pages, nb_pages): + +def split_range(total_pages: int, nb_pages: int) -> Iterator[Tuple[int, int]]: prev_index = None for index in range(0, total_pages, nb_pages): if index is not None and prev_index is not None: - yield prev_index, index + yield prev_index, index - 1 prev_index = index if index != total_pages: