Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_loader.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-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 copy | import copy | |||||||||
import logging | import logging | |||||||||
import os | import os | |||||||||
import time | import time | |||||||||
import hglib | import hglib | |||||||||
from hglib.error import CommandError | ||||||||||
import pytest | import pytest | |||||||||
from swh.loader.tests import ( | from swh.loader.tests import ( | |||||||||
assert_last_visit_matches, | assert_last_visit_matches, | |||||||||
check_snapshot, | check_snapshot, | |||||||||
get_stats, | get_stats, | |||||||||
prepare_repository_from_archive, | prepare_repository_from_archive, | |||||||||
) | ) | |||||||||
▲ Show 20 Lines • Show All 206 Lines • ▼ Show 20 Lines | assert_last_visit_matches( | |||||||||
loader.storage, | loader.storage, | |||||||||
repo_url, | repo_url, | |||||||||
status="partial", | status="partial", | |||||||||
type="hg", | type="hg", | |||||||||
snapshot=hash_to_bytes("3b8fe58e467deb7597b12a5fd3b2c096b8c02028"), | snapshot=hash_to_bytes("3b8fe58e467deb7597b12a5fd3b2c096b8c02028"), | |||||||||
) | ) | |||||||||
@pytest.mark.parametrize( | ||||||||||
"error_msg", | ||||||||||
[ | ||||||||||
b"does not appear to be an hg repository", | ||||||||||
b"404: Not Found", | ||||||||||
b" Name or service not known", | ||||||||||
], | ||||||||||
) | ||||||||||
def test_visit_error_with_status_not_found( | ||||||||||
swh_config, datadir, tmp_path, mocker, error_msg | ||||||||||
): | ||||||||||
"""Not reaching the repo leads to a 'not_found' ingestion status""" | ||||||||||
mock = mocker.patch("hglib.clone") | ||||||||||
mock.side_effect = CommandError((), 255, b"", error_msg) | ||||||||||
archive_name = "the-sandbox" | ||||||||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||||||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | ||||||||||
loader = HgBundle20Loader(repo_url) | ||||||||||
assert loader.load() == {"status": "uneventful"} | ||||||||||
assert_last_visit_matches( | ||||||||||
loader.storage, repo_url, status="not_found", type="hg", snapshot=None, | ||||||||||
) | ||||||||||
def test_visit_error_with_clone_error(swh_config, datadir, tmp_path, mocker): | ||||||||||
vlorentzUnsubmitted Not Done Inline Actions
vlorentz: | ||||||||||
"""Testing failures other than 'not_found'""" | ||||||||||
mock = mocker.patch("hglib.clone") | ||||||||||
mock.side_effect = CommandError((), 255, b"", b"out of disk space") | ||||||||||
archive_name = "the-sandbox" | ||||||||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||||||||
repo_url = prepare_repository_from_archive(archive_path, archive_name, tmp_path) | ||||||||||
loader = HgBundle20Loader(repo_url) | ||||||||||
assert loader.load() == {"status": "failed"} | ||||||||||
assert_last_visit_matches( | ||||||||||
loader.storage, repo_url, status="failed", type="hg", snapshot=None, | ||||||||||
Not Done Inline Actionsgood test, thanks :) vlorentz: good test, thanks :) | ||||||||||
) | ||||||||||
def test_visit_repository_with_transplant_operations(swh_config, datadir, tmp_path): | def test_visit_repository_with_transplant_operations(swh_config, datadir, tmp_path): | |||||||||
"""Visit a mercurial repository visit transplant operations within should yield a | """Visit a mercurial repository visit transplant operations within should yield a | |||||||||
snapshot as well. | snapshot as well. | |||||||||
""" | """ | |||||||||
archive_name = "transplant" | archive_name = "transplant" | |||||||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | |||||||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |