Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/tests/conftest.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import pytest | import pytest | ||||
import asyncio | import asyncio | ||||
import aiohttp | import aiohttp | ||||
import os | import os | ||||
import shutil | import shutil | ||||
from pathlib import PosixPath | from pathlib import Path | ||||
from aioresponses import aioresponses # type: ignore | from aioresponses import aioresponses # type: ignore | ||||
from swh.model.cli import swhid_of_file, swhid_of_dir | from swh.model.cli import swhid_of_file, swhid_of_dir | ||||
from swh.scanner.model import Tree | from swh.scanner.model import Tree | ||||
from .flask_api import create_app | from .flask_api import create_app | ||||
@pytest.fixture | @pytest.fixture | ||||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Lines | for path, swhid in temp_folder["paths"].items(): | ||||
example_tree.addNode(path, swhid, False) | example_tree.addNode(path, swhid, False) | ||||
return example_tree.getDirectoriesInfo(root) | return example_tree.getDirectoriesInfo(root) | ||||
@pytest.fixture | @pytest.fixture | ||||
def test_sample_folder(datadir, tmp_path): | def test_sample_folder(datadir, tmp_path): | ||||
"""Location of the "data" folder """ | """Location of the "data" folder """ | ||||
archive_path = PosixPath(os.path.join(datadir, "sample-folder.tgz")) | archive_path = Path(os.path.join(datadir, "sample-folder.tgz")) | ||||
assert archive_path.exists() | assert archive_path.exists() | ||||
shutil.unpack_archive(archive_path, extract_dir=tmp_path) | shutil.unpack_archive(archive_path, extract_dir=tmp_path) | ||||
test_sample_folder = PosixPath(os.path.join(tmp_path, "sample-folder")) | test_sample_folder = Path(os.path.join(tmp_path, "sample-folder")) | ||||
assert test_sample_folder.exists() | assert test_sample_folder.exists() | ||||
return test_sample_folder | return test_sample_folder | ||||
@pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||
def app(): | def app(): | ||||
"""Flask backend API (used by live_server).""" | """Flask backend API (used by live_server).""" | ||||
app = create_app() | app = create_app() | ||||
return app | return app |