Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/conda/tests/test_conda.py
- This file was added.
# Copyright (C) 2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from swh.loader.package.conda.loader import CondaLoader | |||||
from swh.loader.tests import assert_last_visit_matches, check_snapshot, get_stats | |||||
from swh.model.hashutil import hash_to_bytes | |||||
from swh.model.model import ( | |||||
ObjectType, | |||||
Person, | |||||
Release, | |||||
Snapshot, | |||||
SnapshotBranch, | |||||
TargetType, | |||||
TimestampWithTimezone, | |||||
) | |||||
ORIGINS = [ | |||||
{ | |||||
"url": "https://anaconda.org/conda-forge/lifetimes", | |||||
"artifacts": [ | |||||
{ | |||||
"url": "https://conda.anaconda.org/conda-forge/linux-64/lifetimes-0.11.1-py36h9f0ad1d_1.tar.bz2", # noqa: B950 | |||||
"date": "2020-07-06T12:19:36.425000+00:00", | |||||
"version": "linux-64/0.11.1-py36h9f0ad1d_1", | |||||
"filename": "lifetimes-0.11.1-py36h9f0ad1d_1.tar.bz2", | |||||
"checksums": { | |||||
"md5": "faa398f7ba0d60ce44aa6eeded490cee", | |||||
"sha256": "f82a352dfae8abceeeaa538b220fd9c5e4aa4e59092a6a6cea70b9ec0581ea03", # noqa: B950 | |||||
}, | |||||
}, | |||||
{ | |||||
"url": "https://conda.anaconda.org/conda-forge/linux-64/lifetimes-0.11.1-py36hc560c46_1.tar.bz2", # noqa: B950 | |||||
"date": "2020-07-06T12:19:37.032000+00:00", | |||||
"version": "linux-64/0.11.1-py36hc560c46_1", | |||||
"filename": "lifetimes-0.11.1-py36hc560c46_1.tar.bz2", | |||||
"checksums": { | |||||
"md5": "c53a689a4c5948e84211bdfc23e3fe68", | |||||
"sha256": "76146c2ebd6e3b65928bde53a2585287759d77beba785c0eeb889ee565c0035d", # noqa: B950 | |||||
}, | |||||
}, | |||||
], | |||||
}, | |||||
] | |||||
def test_get_versions(requests_mock_datadir, swh_storage): | |||||
loader = CondaLoader( | |||||
swh_storage, url=ORIGINS[0]["url"], artifacts=ORIGINS[0]["artifacts"] | |||||
) | |||||
assert loader.get_versions() == [ | |||||
"linux-64/0.11.1-py36h9f0ad1d_1", | |||||
"linux-64/0.11.1-py36hc560c46_1", | |||||
] | |||||
def test_get_default_version(requests_mock_datadir, swh_storage): | |||||
loader = CondaLoader( | |||||
swh_storage, url=ORIGINS[0]["url"], artifacts=ORIGINS[0]["artifacts"] | |||||
) | |||||
assert loader.get_default_version() == "linux-64/0.11.1-py36hc560c46_1" | |||||
def test_conda_loader_load_multiple_version( | |||||
datadir, requests_mock_datadir, swh_storage | |||||
): | |||||
loader = CondaLoader( | |||||
swh_storage, url=ORIGINS[0]["url"], artifacts=ORIGINS[0]["artifacts"] | |||||
) | |||||
load_status = loader.load() | |||||
assert load_status["status"] == "eventful" | |||||
assert load_status["snapshot_id"] is not None | |||||
expected_snapshot_id = "d28cb3227e977fe137a1a65aaf0ba1d24349e02e" | |||||
assert expected_snapshot_id == load_status["snapshot_id"] | |||||
expected_snapshot = Snapshot( | |||||
id=hash_to_bytes(load_status["snapshot_id"]), | |||||
branches={ | |||||
b"releases/linux-64/0.11.1-py36h9f0ad1d_1": SnapshotBranch( | |||||
target=hash_to_bytes("23ee1d2e82afe5abf3877b67e776686c5bfb60fa"), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"releases/linux-64/0.11.1-py36hc560c46_1": SnapshotBranch( | |||||
target=hash_to_bytes("7d29fc06dbd67cf3dc17747200589981fc4302bc"), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"HEAD": SnapshotBranch( | |||||
target=b"releases/linux-64/0.11.1-py36hc560c46_1", | |||||
target_type=TargetType.ALIAS, | |||||
), | |||||
}, | |||||
) | |||||
check_snapshot(expected_snapshot, swh_storage) | |||||
stats = get_stats(swh_storage) | |||||
assert { | |||||
"content": 1 + 1, | |||||
"directory": 2 + 3, | |||||
"origin": 1, | |||||
"origin_visit": 1, | |||||
"release": 1 + 1, | |||||
"revision": 0, | |||||
"skipped_content": 0, | |||||
"snapshot": 1, | |||||
} == stats | |||||
assert swh_storage.release_get( | |||||
[hash_to_bytes("23ee1d2e82afe5abf3877b67e776686c5bfb60fa")] | |||||
)[0] == Release( | |||||
name=b"linux-64/0.11.1-py36h9f0ad1d_1", | |||||
message=b"Synthetic release for Conda source package lifetimes version" | |||||
b" linux-64/0.11.1-py36h9f0ad1d_1\n\nMeasure customer lifetime value in Python\n", | |||||
target=hash_to_bytes("0c63e5f909e481d8e5832bac8abbd089bca42993"), | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
author=Person( | |||||
fullname=b"CamDavidsonPilon", name=b"CamDavidsonPilon", email=None | |||||
), | |||||
date=TimestampWithTimezone.from_iso8601("2020-07-06T12:19:36.425000+00:00"), | |||||
id=hash_to_bytes("23ee1d2e82afe5abf3877b67e776686c5bfb60fa"), | |||||
) | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
url=ORIGINS[0]["url"], | |||||
status="full", | |||||
type="conda", | |||||
snapshot=hash_to_bytes(load_status["snapshot_id"]), | |||||
) |