diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..ee586ef --- /dev/null +++ b/conftest.py @@ -0,0 +1,15 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +import pytest + +pytest_plugins = ["swh.scheduler.pytest_plugin", "swh.storage.pytest_plugin"] + + +@pytest.fixture(scope="session") +def swh_scheduler_celery_includes(swh_scheduler_celery_includes): + return swh_scheduler_celery_includes + [ + "swh.loader.git.tasks", + ] diff --git a/pytest.ini b/pytest.ini index afa4cf3..e085539 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,5 @@ [pytest] +# Drop this when these fixtures aren't imported automatically +addopts = -p no:pytest_swh_scheduler -p no:pytest_swh_storage + norecursedirs = docs diff --git a/requirements-test.txt b/requirements-test.txt index a037972..9a7ca3d 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,4 +1,4 @@ pytest pytest-mock -swh.scheduler[testing] +swh.scheduler[testing] >= 0.5.0 swh.storage[testing] diff --git a/swh/loader/git/tests/conftest.py b/swh/loader/git/tests/conftest.py index 78f3b50..a290fb0 100644 --- a/swh/loader/git/tests/conftest.py +++ b/swh/loader/git/tests/conftest.py @@ -1,57 +1,47 @@ # Copyright (C) 2018-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information import os import yaml import pytest from typing import Any, Dict -from swh.scheduler.tests.conftest import * # noqa -from swh.storage.tests.conftest import * # noqa - @pytest.fixture def swh_loader_config(swh_storage_backend_config) -> Dict[str, Any]: swh_storage_backend_config["journal_writer"] = {} return { "storage": { "cls": "pipeline", "steps": [ {"cls": "filter"}, { "cls": "buffer", "min_batch_size": { "content": 10, "content_bytes": 100 * 1024 * 1024, "directory": 10, "revision": 10, "release": 10, }, }, swh_storage_backend_config, ], }, "max_content_size": 100 * 1024 * 1024, "pack_size_bytes": 4 * 1024 * 1024 * 1024, "save_data": False, } @pytest.fixture def swh_config(swh_loader_config, monkeypatch, tmp_path): conffile = os.path.join(str(tmp_path), "loader.yml") with open(conffile, "w") as f: f.write(yaml.dump(swh_loader_config)) monkeypatch.setenv("SWH_CONFIG_FILENAME", conffile) return conffile - - -@pytest.fixture(scope="session") # type: ignore # expected redefinition -def celery_includes(): - return [ - "swh.loader.git.tasks", - ] diff --git a/swh/loader/git/tests/test_tasks.py b/swh/loader/git/tests/test_tasks.py index a1b4ffe..0649b13 100644 --- a/swh/loader/git/tests/test_tasks.py +++ b/swh/loader/git/tests/test_tasks.py @@ -1,60 +1,64 @@ # Copyright (C) 2018-2019 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -def test_git_loader(mocker, swh_app, celery_session_worker): +def test_git_loader(mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker): mock_loader = mocker.patch("swh.loader.git.loader.GitLoader.load") mock_loader.return_value = {"status": "eventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.git.tasks.UpdateGitRepository", kwargs={"url": "origin_url",} ) assert res res.wait() assert res.successful() assert res.result == {"status": "eventful"} mock_loader.assert_called_once_with() -def test_git_loader_from_disk(mocker, swh_app, celery_session_worker): +def test_git_loader_from_disk( + mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker +): mock_loader = mocker.patch("swh.loader.git.from_disk.GitLoaderFromDisk.load") mock_loader.return_value = {"status": "uneventful"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.git.tasks.LoadDiskGitRepository", kwargs={ "url": "origin_url2", "directory": "/some/repo", "date": "2018-12-10 00:00", }, ) assert res res.wait() assert res.successful() assert res.result == {"status": "uneventful"} mock_loader.assert_called_once_with() -def test_git_loader_from_archive(mocker, swh_app, celery_session_worker): +def test_git_loader_from_archive( + mocker, swh_scheduler_celery_app, swh_scheduler_celery_worker +): mock_loader = mocker.patch("swh.loader.git.from_disk.GitLoaderFromArchive.load") mock_loader.return_value = {"status": "failed"} - res = swh_app.send_task( + res = swh_scheduler_celery_app.send_task( "swh.loader.git.tasks.UncompressAndLoadDiskGitRepository", kwargs={ "url": "origin_url3", "archive_path": "/some/repo", "date": "2017-01-10 00:00", }, ) assert res res.wait() assert res.successful() assert res.result == {"status": "failed"} mock_loader.assert_called_once_with() diff --git a/tox.ini b/tox.ini index d6cf85e..fcbf344 100644 --- a/tox.ini +++ b/tox.ini @@ -1,39 +1,40 @@ [tox] envlist=black,flake8,mypy,py3 [testenv] extras = testing deps = # the dependency below is needed for now as a workaround for # https://github.com/pypa/pip/issues/6239 # TODO: remove when this issue is fixed swh.core[http] >= 0.0.61 swh.storage[testing] + swh.scheduler[testing] >= 0.5.0 pytest-cov commands = pytest --cov={envsitepackagesdir}/swh/loader/git \ {envsitepackagesdir}/swh/loader/git \ --cov-branch {posargs} [testenv:black] skip_install = true deps = black commands = {envpython} -m black --check swh [testenv:flake8] skip_install = true deps = flake8 commands = {envpython} -m flake8 [testenv:mypy] extras = testing deps = mypy commands = mypy swh