Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/git/tests/test_converters.py
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | def test_convertion_wrong_input(self): | ||||
"tag": converters.dulwich_tag_to_release, | "tag": converters.dulwich_tag_to_release, | ||||
} | } | ||||
for _callable in m.values(): | for _callable in m.values(): | ||||
with pytest.raises(ValueError): | with pytest.raises(ValueError): | ||||
_callable(Something()) | _callable(Something()) | ||||
def test_corrupt_tree(self): | def test_corrupt_tree(self): | ||||
# has a signature | sha1 = b"a9b41fc6347d778f16c4380b598d8083e9b4c1fb" | ||||
sha1 = b"f0695c2e2fa7ce9d574023c3413761a473e500ca" | target = b"641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce" | ||||
tree = copy.deepcopy(self.repo[sha1]) | tree = dulwich.objects.Tree() | ||||
tree.add(b"file1", 0o644, target) | |||||
assert tree.sha().hexdigest() == sha1.decode() | |||||
converters.dulwich_tree_to_directory(tree) | converters.dulwich_tree_to_directory(tree) | ||||
del tree._entries[next(iter(tree._entries))] | original_sha = tree.sha() | ||||
tree.add(b"file2", 0o644, target) | |||||
tree.sha() # reset tree._needs_serialization | |||||
tree._sha = original_sha # force the wrong hash | |||||
assert tree.sha().hexdigest() == sha1.decode() | |||||
with pytest.raises(converters.HashMismatch): | with pytest.raises(converters.HashMismatch): | ||||
converters.dulwich_tree_to_directory(tree) | converters.dulwich_tree_to_directory(tree) | ||||
def test_weird_tree(self): | |||||
"""Tests a tree with entries the wrong order""" | |||||
raw_manifest = ( | |||||
b"0644 file2\x00" | |||||
b"d\x1f\xb6\xe0\x8d\xdb.O\xd0\x96\xdc\xf1\x8e\x80\xb8\x94\xbf~%\xce" | |||||
b"0644 file1\x00" | |||||
b"d\x1f\xb6\xe0\x8d\xdb.O\xd0\x96\xdc\xf1\x8e\x80\xb8\x94\xbf~%\xce" | |||||
) | |||||
tree = dulwich.objects.Tree.from_raw_string(b"tree", raw_manifest) | |||||
assert converters.dulwich_tree_to_directory(tree) == Directory( | |||||
entries=( | |||||
# in alphabetical order, as it should be | |||||
DirectoryEntry( | |||||
name=b"file1", | |||||
type="file", | |||||
target=hash_to_bytes("641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce"), | |||||
perms=0o644, | |||||
), | |||||
DirectoryEntry( | |||||
name=b"file2", | |||||
type="file", | |||||
target=hash_to_bytes("641fb6e08ddb2e4fd096dcf18e80b894bf7e25ce"), | |||||
perms=0o644, | |||||
), | |||||
), | |||||
raw_manifest=b"tree 62\x00" + raw_manifest, | |||||
) | |||||
def test_tree_perms(self): | def test_tree_perms(self): | ||||
entries = [ | entries = [ | ||||
(b"blob_100644", 0o100644, "file"), | (b"blob_100644", 0o100644, "file"), | ||||
(b"blob_100664", 0o100664, "file"), | (b"blob_100664", 0o100664, "file"), | ||||
(b"blob_100666", 0o100666, "file"), | (b"blob_100666", 0o100666, "file"), | ||||
(b"blob_120000", 0o120000, "file"), | (b"blob_120000", 0o120000, "file"), | ||||
(b"commit_160644", 0o160644, "rev"), | (b"commit_160644", 0o160644, "rev"), | ||||
(b"commit_160664", 0o160664, "rev"), | (b"commit_160664", 0o160664, "rev"), | ||||
▲ Show 20 Lines • Show All 555 Lines • Show Last 20 Lines |