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 | |||||
from pathlib import PosixPath | from pathlib import PosixPath | ||||
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 | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | for path, swhid in temp_folder["paths"].items(): | ||||
example_tree.addNode(path, swhid, True) | example_tree.addNode(path, swhid, True) | ||||
else: | else: | ||||
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_folder(): | def test_sample_folder(datadir, tmp_path): | ||||
"""Location of the "data" folder """ | """Location of the "data" folder """ | ||||
tests_path = PosixPath(os.path.abspath(__file__)).parent | archive_path = PosixPath(os.path.join(datadir, "sample-folder.tgz")) | ||||
tests_data_folder = tests_path.joinpath("data") | assert archive_path.exists() | ||||
assert tests_data_folder.exists() | shutil.unpack_archive(archive_path, extract_dir=tmp_path) | ||||
return tests_data_folder | test_sample_folder = PosixPath(os.path.join(tmp_path, "sample-folder")) | ||||
assert test_sample_folder.exists() | |||||
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 |