Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/cpan/tests/test_cpan.py
# Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 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 | ||||
# flake8: noqa: B950 | # flake8: noqa: B950 | ||||
import json | import json | ||||
from pathlib import Path | from pathlib import Path | ||||
import pytest | import pytest | ||||
from swh.loader.package import __version__ | from swh.loader.package import __version__ | ||||
from swh.loader.package.cpan.loader import CpanLoader | from swh.loader.package.cpan.loader import CpanLoader, CpanPackageInfo | ||||
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 ( | ||||
Person, | Person, | ||||
RawExtrinsicMetadata, | RawExtrinsicMetadata, | ||||
Release, | Release, | ||||
Snapshot, | Snapshot, | ||||
SnapshotBranch, | SnapshotBranch, | ||||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Lines | ): | ||||
] | ] | ||||
assert ( | assert ( | ||||
cpan_loader.storage.raw_extrinsic_metadata_get( | cpan_loader.storage.raw_extrinsic_metadata_get( | ||||
directory_swhid, | directory_swhid, | ||||
cpan_loader.get_metadata_authority(), | cpan_loader.get_metadata_authority(), | ||||
).results | ).results | ||||
== expected_metadata | == expected_metadata | ||||
) | ) | ||||
package_extids = [ | |||||
package_info.extid() | |||||
for version in cpan_loader.get_versions() | |||||
for _, package_info in cpan_loader.get_package_info(version) | |||||
] | |||||
extids = storage.extid_get_from_extid( | |||||
id_type=CpanPackageInfo.EXTID_TYPE, | |||||
ids=[extid for (_, _, extid) in package_extids], | |||||
version=CpanPackageInfo.EXTID_VERSION, | |||||
) | |||||
release_swhids = { | |||||
CoreSWHID(object_type=ObjectType.RELEASE, object_id=branch.target) | |||||
for branch in expected_snapshot.branches.values() | |||||
if branch.target_type == TargetType.RELEASE | |||||
} | |||||
assert {extid.target for extid in extids} == release_swhids |