Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_from_disk.py
# Copyright (C) 2018-2021 The Software Heritage developers | # Copyright (C) 2018-2021 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 datetime | import datetime | ||||
import os.path | import os.path | ||||
from unittest import TestCase | |||||
import dulwich.objects | import dulwich.objects | ||||
import dulwich.porcelain | import dulwich.porcelain | ||||
import dulwich.repo | import dulwich.repo | ||||
import pytest | import pytest | ||||
from swh.loader.git.from_disk import GitLoaderFromArchive, GitLoaderFromDisk | from swh.loader.git.from_disk import GitLoaderFromArchive, GitLoaderFromDisk | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
▲ Show 20 Lines • Show All 477 Lines • ▼ Show 20 Lines | def test_load_tag_minimal(self): | ||||
name=b"v1.0.0", | name=b"v1.0.0", | ||||
message=b"First release!\n", | message=b"First release!\n", | ||||
target_type=ObjectType.REVISION, | target_type=ObjectType.REVISION, | ||||
target=bytehex_to_hash(new_revision), | target=bytehex_to_hash(new_revision), | ||||
synthetic=False, | synthetic=False, | ||||
) | ) | ||||
class GitLoaderFromDiskTest(TestCase, FullGitLoaderTests): | class TestGitLoaderFromDisk(FullGitLoaderTests): | ||||
"""Prepare a git directory repository to be loaded through a GitLoaderFromDisk. | """Prepare a git directory repository to be loaded through a GitLoaderFromDisk. | ||||
This tests all git loader scenario. | This tests all git loader scenario. | ||||
""" | """ | ||||
@pytest.fixture(autouse=True) | @pytest.fixture(autouse=True) | ||||
def init(self, swh_storage, datadir, tmp_path): | def init(self, swh_storage, datadir, tmp_path): | ||||
archive_name = "testrepo" | archive_name = "testrepo" | ||||
Show All 9 Lines | def init(self, swh_storage, datadir, tmp_path): | ||||
visit_date=datetime.datetime( | visit_date=datetime.datetime( | ||||
2016, 5, 3, 15, 16, 32, tzinfo=datetime.timezone.utc | 2016, 5, 3, 15, 16, 32, tzinfo=datetime.timezone.utc | ||||
), | ), | ||||
directory=self.destination_path, | directory=self.destination_path, | ||||
) | ) | ||||
self.repo = dulwich.repo.Repo(self.destination_path) | self.repo = dulwich.repo.Repo(self.destination_path) | ||||
class GitLoaderFromArchiveTest(TestCase, CommonGitLoaderTests): | class TestGitLoaderFromArchive(CommonGitLoaderTests): | ||||
"""Tests for GitLoaderFromArchive. Only tests common scenario.""" | """Tests for GitLoaderFromArchive. Only tests common scenario.""" | ||||
@pytest.fixture(autouse=True) | @pytest.fixture(autouse=True) | ||||
def init(self, swh_storage, datadir, tmp_path): | def init(self, swh_storage, datadir, tmp_path): | ||||
archive_name = "testrepo" | archive_name = "testrepo" | ||||
archive_path = os.path.join(datadir, f"{archive_name}.tgz") | archive_path = os.path.join(datadir, f"{archive_name}.tgz") | ||||
self.repo_url = archive_path | self.repo_url = archive_path | ||||
self.loader = GitLoaderFromArchive( | self.loader = GitLoaderFromArchive( | ||||
swh_storage, | swh_storage, | ||||
url=self.repo_url, | url=self.repo_url, | ||||
archive_path=archive_path, | archive_path=archive_path, | ||||
visit_date=datetime.datetime( | visit_date=datetime.datetime( | ||||
2016, 5, 3, 15, 16, 32, tzinfo=datetime.timezone.utc | 2016, 5, 3, 15, 16, 32, tzinfo=datetime.timezone.utc | ||||
), | ), | ||||
) | ) |