tests: Separate lister instantiations

Prior to this commit, all listers were instantiated at the same time even if
only one was needed. This commit separates those instantiations.

The only drawback to this is the db model initialization which now happens at
each lister instantiation. This can be dealt with if needed at another time
though.
This commit is contained in:
Antoine R. Dumont (@ardumont) 2020-09-02 09:47:12 +02:00
parent 92422dcf75
commit 5a5b7ef70b
No known key found for this signature in database
GPG key ID: 52E2E9840D10C3B8
14 changed files with 127 additions and 87 deletions

View file

@ -1,13 +1,19 @@
# Copyright (C) 2019 the Software Heritage developers
# Copyright (C) 2019-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 pytest
from swh.lister import __version__
def test_lister_no_page(requests_mock_datadir, swh_listers):
lister = swh_listers["cgit"]
@pytest.fixture
def lister_under_test():
return "cgit"
def test_lister_no_page(requests_mock_datadir, swh_lister):
lister = swh_lister
assert lister.url == "https://git.savannah.gnu.org/cgit/"
@ -21,8 +27,8 @@ def test_lister_no_page(requests_mock_datadir, swh_listers):
assert repos[-2] == "http://example.org/cgit/xstarcastle.git/"
def test_lister_model(requests_mock_datadir, swh_listers):
lister = swh_listers["cgit"]
def test_lister_model(requests_mock_datadir, swh_lister):
lister = swh_lister
repo = next(lister.get_repos())
@ -36,8 +42,8 @@ def test_lister_model(requests_mock_datadir, swh_listers):
}
def test_lister_with_pages(requests_mock_datadir, swh_listers):
lister = swh_listers["cgit"]
def test_lister_with_pages(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
repos = list(lister.get_repos())
@ -45,8 +51,8 @@ def test_lister_with_pages(requests_mock_datadir, swh_listers):
assert len(repos) == 16
def test_lister_run(requests_mock_datadir, swh_listers):
lister = swh_listers["cgit"]
def test_lister_run(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
lister.run()
@ -69,8 +75,8 @@ def test_lister_run(requests_mock_datadir, swh_listers):
assert row["priority"] is None
def test_lister_requests(requests_mock_datadir, swh_listers):
lister = swh_listers["cgit"]
def test_lister_requests(requests_mock_datadir, swh_lister):
lister = swh_lister
lister.url = "https://git.tizen/cgit/"
lister.run()