Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/opam/tests/test_opam.py
# Copyright (C) 2019-2021 The Software Heritage developers | # Copyright (C) 2019-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 swh.loader.package import __version__ | from swh.loader.package import __version__ | ||||
from swh.loader.package.loader import RawExtrinsicMetadataCore | from swh.loader.package.loader import RawExtrinsicMetadataCore | ||||
from swh.loader.package.opam.loader import OpamLoader, OpamPackageInfo | from swh.loader.package.opam.loader import OpamLoader, OpamPackageInfo | ||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import ( | from swh.model.model import ( | ||||
MetadataAuthority, | |||||
MetadataAuthorityType, | |||||
MetadataFetcher, | |||||
Person, | Person, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | |||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
TargetType, | TargetType, | ||||
) | ) | ||||
from swh.model.model import MetadataAuthority, MetadataAuthorityType, MetadataFetcher | |||||
from swh.model.model import ObjectType as ModelObjectType | |||||
from swh.model.swhids import CoreSWHID, ExtendedObjectType, ExtendedSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ExtendedObjectType, ExtendedSWHID, ObjectType | ||||
from swh.storage.interface import PagedResult | from swh.storage.interface import PagedResult | ||||
OCB_METADATA = b"""\ | OCB_METADATA = b"""\ | ||||
opam-version: "2.0" | opam-version: "2.0" | ||||
name: "ocb" | name: "ocb" | ||||
version: "0.1" | version: "0.1" | ||||
synopsis: "SVG badge generator" | synopsis: "SVG badge generator" | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | loader = OpamLoader( | ||||
opam_instance, | opam_instance, | ||||
opam_url, | opam_url, | ||||
opam_package, | opam_package, | ||||
initialize_opam_root=True, | initialize_opam_root=True, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = hash_to_bytes("50b5961c27dd4f8b138acce8bac4f90d1e33081f") | expected_snapshot_id = hash_to_bytes("e480958fa7851268be2bcc8d01145c0c9624b34b") | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id.hex(), | "snapshot_id": expected_snapshot_id.hex(), | ||||
} | } | ||||
release_id = hash_to_bytes("03db7f0d572509f1c7ce18c847db83070e26fd5e") | |||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=expected_snapshot_id, | id=expected_snapshot_id, | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch(target=b"agrid.0.1", target_type=TargetType.ALIAS,), | b"HEAD": SnapshotBranch(target=b"agrid.0.1", target_type=TargetType.ALIAS,), | ||||
b"agrid.0.1": SnapshotBranch( | b"agrid.0.1": SnapshotBranch( | ||||
target=hash_to_bytes("efcb9ef9d0f2a85312463251732b42f9e45a5c12"), | target=release_id, target_type=TargetType.RELEASE, | ||||
target_type=TargetType.RELEASE, | |||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
assert swh_storage.release_get([release_id])[0] == Release( | |||||
name=b"0.1", | |||||
message=b"Synthetic release for OPAM source package agrid version 0.1", | |||||
target=hash_to_bytes("00412ee5bc601deb462e55addd1004715116785e"), | |||||
target_type=ModelObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
author=Person( | |||||
fullname=b"OCamlPro <contact@ocamlpro.com>", name=None, email=None | |||||
), | |||||
date=None, | |||||
id=release_id, | |||||
) | |||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | ||||
) | ) | ||||
check_snapshot(expected_snapshot, swh_storage) | check_snapshot(expected_snapshot, swh_storage) | ||||
stats = get_stats(swh_storage) | stats = get_stats(swh_storage) | ||||
Show All 24 Lines | loader = OpamLoader( | ||||
opam_instance, | opam_instance, | ||||
opam_url, | opam_url, | ||||
opam_package, | opam_package, | ||||
initialize_opam_root=True, | initialize_opam_root=True, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = hash_to_bytes("f0a974e47999e74d323f1fb9604fde72527bda28") | expected_snapshot_id = hash_to_bytes("1a70631bee44c86dded71e0a091b1c91c110f812") | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id.hex(), | "snapshot_id": expected_snapshot_id.hex(), | ||||
} | } | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=expected_snapshot_id, | id=expected_snapshot_id, | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch( | b"HEAD": SnapshotBranch( | ||||
target=b"directories.0.3", target_type=TargetType.ALIAS, | target=b"directories.0.3", target_type=TargetType.ALIAS, | ||||
), | ), | ||||
b"directories.0.1": SnapshotBranch( | b"directories.0.1": SnapshotBranch( | ||||
target=hash_to_bytes("1f839cb1f4720d6b33fdd856e3ff1119497979d9"), | target=hash_to_bytes("013d53d7e1aedbe03aaa3d5c0e6d1d780ef2634d"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"directories.0.2": SnapshotBranch( | b"directories.0.2": SnapshotBranch( | ||||
target=hash_to_bytes("4133834d966381804347efbc41e35dd2bdd48962"), | target=hash_to_bytes("4fdcc3606c0af33cb4d733b70074e79f03e928a1"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
b"directories.0.3": SnapshotBranch( | b"directories.0.3": SnapshotBranch( | ||||
target=hash_to_bytes("2f20cabfbacfe447b80dc2a4eb14d461775100c8"), | target=hash_to_bytes("5de72a60f81649157d267773c30e897b7005dcdb"), | ||||
target_type=TargetType.RELEASE, | target_type=TargetType.RELEASE, | ||||
), | ), | ||||
}, | }, | ||||
) | ) | ||||
assert_last_visit_matches( | assert_last_visit_matches( | ||||
swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | swh_storage, url, status="full", type="opam", snapshot=expected_snapshot_id | ||||
) | ) | ||||
Show All 17 Lines | loader = OpamLoader( | ||||
opam_instance, | opam_instance, | ||||
opam_url, | opam_url, | ||||
opam_package, | opam_package, | ||||
initialize_opam_root=True, | initialize_opam_root=True, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = hash_to_bytes("987425c6fe94d3972c4c4e97ee27a6a7c8b68e82") | expected_snapshot_id = hash_to_bytes("96246035587354a71f429d5b9b8dcc98afad3708") | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id.hex(), | "snapshot_id": expected_snapshot_id.hex(), | ||||
} | } | ||||
info_iter = loader.get_package_info("0.1") | info_iter = loader.get_package_info("0.1") | ||||
branch_name, package_info = next(info_iter) | branch_name, package_info = next(info_iter) | ||||
expected_branch_name = "ocb.0.1" | expected_branch_name = "ocb.0.1" | ||||
Show All 12 Lines | expected_package_info = OpamPackageInfo( | ||||
metadata=OCB_METADATA, format="opam-package-definition", | metadata=OCB_METADATA, format="opam-package-definition", | ||||
) | ) | ||||
], | ], | ||||
) | ) | ||||
assert branch_name == expected_branch_name | assert branch_name == expected_branch_name | ||||
assert package_info == expected_package_info | assert package_info == expected_package_info | ||||
release_id = hash_to_bytes("8d0612cdf172e5dff3d876ca2bbc0f6003cc36cc") | release_id = hash_to_bytes("4904ad9d0f3b3f84cec2b899d0d05c682b0efdcb") | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(actual_load_status["snapshot_id"]), | id=hash_to_bytes(actual_load_status["snapshot_id"]), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch(target=b"ocb.0.1", target_type=TargetType.ALIAS,), | b"HEAD": SnapshotBranch(target=b"ocb.0.1", target_type=TargetType.ALIAS,), | ||||
b"ocb.0.1": SnapshotBranch( | b"ocb.0.1": SnapshotBranch( | ||||
target=release_id, target_type=TargetType.RELEASE, | target=release_id, target_type=TargetType.RELEASE, | ||||
), | ), | ||||
Show All 30 Lines | loader = OpamLoader( | ||||
opam_package, | opam_package, | ||||
initialize_opam_root=True, | initialize_opam_root=True, | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
assert actual_load_status["status"] == "eventful" | assert actual_load_status["status"] == "eventful" | ||||
expected_release_id = hash_to_bytes("8d0612cdf172e5dff3d876ca2bbc0f6003cc36cc") | expected_release_id = hash_to_bytes("4904ad9d0f3b3f84cec2b899d0d05c682b0efdcb") | ||||
expected_snapshot = Snapshot( | expected_snapshot = Snapshot( | ||||
id=hash_to_bytes(actual_load_status["snapshot_id"]), | id=hash_to_bytes(actual_load_status["snapshot_id"]), | ||||
branches={ | branches={ | ||||
b"HEAD": SnapshotBranch(target=b"ocb.0.1", target_type=TargetType.ALIAS,), | b"HEAD": SnapshotBranch(target=b"ocb.0.1", target_type=TargetType.ALIAS,), | ||||
b"ocb.0.1": SnapshotBranch( | b"ocb.0.1": SnapshotBranch( | ||||
target=expected_release_id, target_type=TargetType.RELEASE, | target=expected_release_id, target_type=TargetType.RELEASE, | ||||
), | ), | ||||
Show All 38 Lines |