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": "5cbc765bd910a62315f340988f329768", | |||||
"sha256": "44f91fa4fd77aea15dcba382b3f20e13a6ae1d48eedb9ae6b3c3a0709bbdb76e", # noqa: B950 | |||||
}, | |||||
}, | |||||
{ | |||||
"url": "https://conda.anaconda.org/conda-forge/linux-64/lifetimes-0.11.1-py36hc560c46_1.tar.bz2", # noqa: B950 | |||||
"date": "", # Empty date | |||||
"version": "linux-64/0.11.1-py36hc560c46_1", | |||||
"filename": "lifetimes-0.11.1-py36hc560c46_1.tar.bz2", | |||||
"checksums": { | |||||
"md5": "14d2908d3b625ffd3f8d1fc0f20eaa07", | |||||
"sha256": "46f5c5ab12338ec7b546d930a75c39633762fb2dac5f486fefebabbc4705c6c1", # 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 = "9c20bedf9af54ef7b3937fe4675f9f17b9331b7b" | |||||
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("9848f61b501801799025d632221833a0f988dca2"), | |||||
target_type=TargetType.RELEASE, | |||||
), | |||||
b"releases/linux-64/0.11.1-py36hc560c46_1": SnapshotBranch( | |||||
target=hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27"), | |||||
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("9848f61b501801799025d632221833a0f988dca2")] | |||||
)[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", | |||||
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("9848f61b501801799025d632221833a0f988dca2"), | |||||
) | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
url=ORIGINS[0]["url"], | |||||
status="full", | |||||
type="conda", | |||||
snapshot=hash_to_bytes(load_status["snapshot_id"]), | |||||
) | |||||
# This one have empty author and date | |||||
assert swh_storage.release_get( | |||||
[hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27")] | |||||
)[0] == Release( | |||||
name=b"linux-64/0.11.1-py36hc560c46_1", | |||||
message=b"Synthetic release for Conda source package lifetimes version" | |||||
b" linux-64/0.11.1-py36hc560c46_1\n", | |||||
target=hash_to_bytes("45ca406aeb31f51836a8593b619ab216403ce489"), | |||||
target_type=ObjectType.DIRECTORY, | |||||
synthetic=True, | |||||
author=Person(fullname=b"", name=None, email=None), | |||||
date=None, | |||||
id=hash_to_bytes("fad38f867db9311504a4c340f2b32dcdffa46e27"), | |||||
) | |||||
assert_last_visit_matches( | |||||
swh_storage, | |||||
url=ORIGINS[0]["url"], | |||||
status="full", | |||||
type="conda", | |||||
snapshot=hash_to_bytes(load_status["snapshot_id"]), | |||||
) |