Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_converters.py
# Copyright (C) 2015-2018 The Software Heritage developers | # Copyright (C) 2015-2018 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 | import os | ||||
import shutil | import shutil | ||||
import subprocess | import subprocess | ||||
import tempfile | import tempfile | ||||
import dulwich.objects | |||||
import dulwich.repo | import dulwich.repo | ||||
import pytest | import pytest | ||||
import swh.loader.git.converters as converters | import swh.loader.git.converters as converters | ||||
from swh.model.hashutil import bytehex_to_hash, hash_to_bytehex, hash_to_bytes | from swh.model.hashutil import bytehex_to_hash, hash_to_bytehex, hash_to_bytes | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
Content, | Content, | ||||
Directory, | |||||
DirectoryEntry, | |||||
ObjectType, | ObjectType, | ||||
Person, | Person, | ||||
Release, | Release, | ||||
Revision, | Revision, | ||||
RevisionType, | RevisionType, | ||||
Timestamp, | Timestamp, | ||||
TimestampWithTimezone, | TimestampWithTimezone, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | def test_corrupt_tree(self): | ||||
tree = copy.deepcopy(self.repo[sha1]) | tree = copy.deepcopy(self.repo[sha1]) | ||||
converters.dulwich_tree_to_directory(tree) | converters.dulwich_tree_to_directory(tree) | ||||
del tree._entries[next(iter(tree._entries))] | del tree._entries[next(iter(tree._entries))] | ||||
with pytest.raises(converters.HashMismatch): | with pytest.raises(converters.HashMismatch): | ||||
converters.dulwich_tree_to_directory(tree) | converters.dulwich_tree_to_directory(tree) | ||||
def test_tree_perms(self): | |||||
entries = [ | |||||
(b"blob_100644", 0o100644, "file"), | |||||
(b"blob_100664", 0o100664, "file"), | |||||
(b"blob_100666", 0o100666, "file"), | |||||
(b"blob_120000", 0o120000, "file"), | |||||
(b"commit_160644", 0o160644, "rev"), | |||||
(b"commit_160664", 0o160664, "rev"), | |||||
(b"commit_160666", 0o160666, "rev"), | |||||
(b"commit_normal", 0o160000, "rev"), | |||||
(b"tree_040644", 0o040644, "dir"), | |||||
(b"tree_040664", 0o040664, "dir"), | |||||
(b"tree_040666", 0o040666, "dir"), | |||||
(b"tree_normal", 0o040000, "dir"), | |||||
] | |||||
tree = dulwich.objects.Tree() | |||||
for (name, mode, _) in entries: | |||||
tree.add(name, mode, b"00" * 20) | |||||
assert converters.dulwich_tree_to_directory(tree) == Directory( | |||||
entries=tuple( | |||||
DirectoryEntry(type=type, perms=perms, name=name, target=b"\x00" * 20) | |||||
for (name, perms, type) in entries | |||||
) | |||||
) | |||||
def test_commit_to_revision(self): | def test_commit_to_revision(self): | ||||
sha1 = b"9768d0b576dbaaecd80abedad6dfd0d72f1476da" | sha1 = b"9768d0b576dbaaecd80abedad6dfd0d72f1476da" | ||||
revision = converters.dulwich_commit_to_revision(self.repo[sha1]) | revision = converters.dulwich_commit_to_revision(self.repo[sha1]) | ||||
expected_revision = Revision( | expected_revision = Revision( | ||||
id=hash_to_bytes("9768d0b576dbaaecd80abedad6dfd0d72f1476da"), | id=hash_to_bytes("9768d0b576dbaaecd80abedad6dfd0d72f1476da"), | ||||
directory=b"\xf0i\\./\xa7\xce\x9dW@#\xc3A7a\xa4s\xe5\x00\xca", | directory=b"\xf0i\\./\xa7\xce\x9dW@#\xc3A7a\xa4s\xe5\x00\xca", | ||||
type=RevisionType.GIT, | type=RevisionType.GIT, | ||||
▲ Show 20 Lines • Show All 382 Lines • Show Last 20 Lines |