Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_loader.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 | ||||
from functools import partial | from functools import partial | ||||
from http.server import HTTPServer, SimpleHTTPRequestHandler | from http.server import HTTPServer, SimpleHTTPRequestHandler | ||||
import os | import os | ||||
import subprocess | import subprocess | ||||
from threading import Thread | from threading import Thread | ||||
from dulwich.errors import GitProtocolError, NotGitRepository, ObjectFormatException | from dulwich.errors import GitProtocolError, NotGitRepository, ObjectFormatException | ||||
from dulwich.porcelain import push | from dulwich.porcelain import push | ||||
import dulwich.repo | import dulwich.repo | ||||
import pytest | import pytest | ||||
from swh.loader.git import dumb | |||||
from swh.loader.git.loader import GitLoader | from swh.loader.git.loader import GitLoader | ||||
from swh.loader.git.tests.test_from_disk import FullGitLoaderTests | from swh.loader.git.tests.test_from_disk import FullGitLoaderTests | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
get_stats, | get_stats, | ||||
prepare_repository_from_archive, | prepare_repository_from_archive, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | def test_load_despite_dulwich_exception(self, mocker, failure_exception): | ||||
"origin": 1, | "origin": 1, | ||||
"origin_visit": 1, | "origin_visit": 1, | ||||
"release": 0, | "release": 0, | ||||
"revision": 7, | "revision": 7, | ||||
"skipped_content": 0, | "skipped_content": 0, | ||||
"snapshot": 1, | "snapshot": 1, | ||||
} | } | ||||
def test_load_empty_repository(self, mocker): | |||||
class GitObjectsFetcherNoRefs(dumb.GitObjectsFetcher): | |||||
def _get_refs(self): | |||||
return {} | |||||
mocker.patch.object(dumb, "GitObjectsFetcher", GitObjectsFetcherNoRefs) | |||||
res = self.loader.load() | |||||
assert res == {"status": "uneventful"} | |||||
stats = get_stats(self.loader.storage) | |||||
assert stats == { | |||||
"content": 0, | |||||
"directory": 0, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 0, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} | |||||
class TestDumbGitLoaderWithPack(DumbGitLoaderTestBase): | class TestDumbGitLoaderWithPack(DumbGitLoaderTestBase): | ||||
@classmethod | @classmethod | ||||
def setup_class(cls): | def setup_class(cls): | ||||
cls.with_pack_files = True | cls.with_pack_files = True | ||||
class TestDumbGitLoaderWithoutPack(DumbGitLoaderTestBase): | class TestDumbGitLoaderWithoutPack(DumbGitLoaderTestBase): | ||||
@classmethod | @classmethod | ||||
def setup_class(cls): | def setup_class(cls): | ||||
cls.with_pack_files = False | cls.with_pack_files = False |