Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/tests/test_loader.py
# Copyright (C) 2016-2020 The Software Heritage developers | # Copyright (C) 2016-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 os | import os | ||||
import subprocess | |||||
from typing import Optional | |||||
from swh.loader.tests.common import assert_last_visit_matches | from swh.loader.tests import ( | ||||
from swh.loader.package.tests.common import check_snapshot, get_stats | assert_last_visit_matches, | ||||
check_snapshot, | |||||
prepare_repository_from_archive, | |||||
get_stats, | |||||
) | |||||
from swh.loader.svn.loader import ( | from swh.loader.svn.loader import ( | ||||
DEFAULT_BRANCH, | DEFAULT_BRANCH, | ||||
SvnLoader, | SvnLoader, | ||||
SvnLoaderFromRemoteDump, | SvnLoaderFromRemoteDump, | ||||
build_swh_snapshot, | build_swh_snapshot, | ||||
) | ) | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
Show All 30 Lines | GOURMET_WRONG_LINKS_SNAPSHOT = hashutil.hash_to_bytes( | ||||
"b17f38acabb90f066dedd30c29f01a02af88a5c4" | "b17f38acabb90f066dedd30c29f01a02af88a5c4" | ||||
) | ) | ||||
MEDIAWIKI_SNAPSHOT = hashutil.hash_to_bytes("d6d6e9703f157c5702d9a4a5dec878926ed4ab76") | MEDIAWIKI_SNAPSHOT = hashutil.hash_to_bytes("d6d6e9703f157c5702d9a4a5dec878926ed4ab76") | ||||
PYANG_SNAPSHOT = hashutil.hash_to_bytes("6d9590de11b00a5801de0ff3297c5b44bbbf7d24") | PYANG_SNAPSHOT = hashutil.hash_to_bytes("6d9590de11b00a5801de0ff3297c5b44bbbf7d24") | ||||
def prepare_repository_from_archive( | |||||
archive_path: str, filename: Optional[str] = None, tmp_path: str = "/tmp" | |||||
) -> str: | |||||
# uncompress folder/repositories/dump for the loader to ingest | |||||
subprocess.check_output(["tar", "xf", archive_path, "-C", tmp_path]) | |||||
# build the origin url (or some derivative form) | |||||
_fname = filename if filename else os.path.basename(archive_path) | |||||
repo_url = f"file://{tmp_path}/{_fname}" | |||||
return repo_url | |||||
def test_loader_svn_new_visit(swh_config, datadir, tmp_path): | def test_loader_svn_new_visit(swh_config, datadir, tmp_path): | ||||
"""Eventful visit should yield 1 snapshot""" | """Eventful visit should yield 1 snapshot""" | ||||
archive_name = "pkg-gourmet" | archive_name = "pkg-gourmet" | ||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | ||||
loader = SvnLoader(repo_url, destination_path=tmp_path) | loader = SvnLoader(repo_url, destination_path=tmp_path) | ||||
▲ Show 20 Lines • Show All 602 Lines • Show Last 20 Lines |