test_utils: Migrate to pytest

This commit is contained in:
Antoine R. Dumont (@ardumont) 2020-09-09 18:48:07 +02:00
parent 66a61f3dd2
commit 725c1fe4ad
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8

View file

@ -1,28 +1,28 @@
# Copyright (C) 2018-2019 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
import unittest
import pytest
from testing.postgresql import Postgresql
from swh.lister import utils
class UtilsTest(unittest.TestCase):
def test_split_range(self):
actual_ranges = list(utils.split_range(14, 5))
self.assertEqual(actual_ranges, [(0, 5), (5, 10), (10, 14)])
@pytest.mark.parametrize(
"total_pages,nb_pages,expected_ranges",
[(14, 5, [(0, 5), (5, 10), (10, 14)]), (19, 10, [(0, 10), (10, 19)])],
)
def test_split_range(total_pages, nb_pages, expected_ranges):
actual_ranges = list(utils.split_range(total_pages, nb_pages))
assert actual_ranges == expected_ranges
actual_ranges = list(utils.split_range(19, 10))
self.assertEqual(actual_ranges, [(0, 10), (10, 19)])
def test_split_range_errors(self):
with self.assertRaises(TypeError):
list(utils.split_range(None, 1))
with self.assertRaises(TypeError):
list(utils.split_range(100, None))
@pytest.mark.parametrize("total_pages,nb_pages", [(None, 1), (100, None)])
def test_split_range_errors(total_pages, nb_pages):
for total_pages, nb_pages in [(None, 1), (100, None)]:
with pytest.raises(TypeError):
next(utils.split_range(total_pages, nb_pages))
def init_db():