Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/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 | ||||
from swh.loader.git.loader import GitLoader | import os | ||||
from swh.loader.git.tests.test_from_disk import DirGitLoaderTest | |||||
from . import TEST_LOADER_CONFIG | import pytest | ||||
import dulwich.repo | |||||
from unittest import TestCase | |||||
class GitLoaderTest(GitLoader): | from swh.loader.git.loader import GitLoader | ||||
def parse_config_file(self, *args, **kwargs): | from swh.loader.git.tests.test_from_disk import FullGitLoaderTests | ||||
return {**super().parse_config_file(*args, **kwargs), **TEST_LOADER_CONFIG} | |||||
from swh.loader.git.tests import prepare_repository_from_archive | |||||
class TestGitLoader(DirGitLoaderTest): | |||||
"""Same tests as for the GitLoaderFromDisk, but running on GitLoader.""" | |||||
def setUp(self): | class GitLoaderTest(TestCase, FullGitLoaderTests): | ||||
super().setUp() | """Prepare a git directory repository to be loaded through a GitLoader. | ||||
self.loader = GitLoaderTest(self.repo_url) | This tests all git loader scenario. | ||||
self.storage = self.loader.storage | |||||
def load(self): | """ | ||||
return self.loader.load() | |||||
@pytest.fixture(autouse=True) | |||||
def init(self, swh_config, datadir, tmp_path): | |||||
super().setUp() | |||||
archive_name = "testrepo" | |||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | |||||
tmp_path = str(tmp_path) | |||||
self.repo_url = prepare_repository_from_archive( | |||||
archive_path, archive_name, tmp_path=tmp_path | |||||
) | |||||
self.destination_path = os.path.join(tmp_path, archive_name) | |||||
self.loader = GitLoader(self.repo_url) | |||||
self.repo = dulwich.repo.Repo(self.destination_path) |