Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/cran/tests/test_cran.py
Show All 13 Lines | |||||
from swh.loader.package.cran.loader import ( | from swh.loader.package.cran.loader import ( | ||||
extract_intrinsic_metadata, | extract_intrinsic_metadata, | ||||
CRANLoader, | CRANLoader, | ||||
parse_date, | parse_date, | ||||
parse_debian_control, | parse_debian_control, | ||||
) | ) | ||||
from swh.core.tarball import uncompress | from swh.core.tarball import uncompress | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.model import TimestampWithTimezone | from swh.model.model import Snapshot, SnapshotBranch, TargetType, TimestampWithTimezone | ||||
from swh.loader.tests import ( | from swh.loader.tests import ( | ||||
assert_last_visit_matches, | assert_last_visit_matches, | ||||
check_snapshot, | check_snapshot, | ||||
get_stats, | get_stats, | ||||
) | ) | ||||
SNAPSHOT = Snapshot( | |||||
id=hash_to_bytes("920adcccc78aaeedd3cfa4459dd900d8c3431a21"), | |||||
branches={ | |||||
b"HEAD": SnapshotBranch( | |||||
target=b"releases/2.22-6", target_type=TargetType.ALIAS | |||||
), | |||||
b"releases/2.22-6": SnapshotBranch( | |||||
target=hash_to_bytes("42bdb16facd5140424359c8ce89a28ecfa1ce603"), | |||||
target_type=TargetType.REVISION, | |||||
), | |||||
}, | |||||
) | |||||
def test_cran_parse_date(): | def test_cran_parse_date(): | ||||
data = [ | data = [ | ||||
# parsable, some have debatable results though | # parsable, some have debatable results though | ||||
("2001-June-08", datetime(2001, 6, 8, 0, 0, tzinfo=timezone.utc)), | ("2001-June-08", datetime(2001, 6, 8, 0, 0, tzinfo=timezone.utc)), | ||||
( | ( | ||||
"Tue Dec 27 15:06:08 PST 2011", | "Tue Dec 27 15:06:08 PST 2011", | ||||
datetime(2011, 12, 27, 15, 6, 8, tzinfo=timezone.utc), | datetime(2011, 12, 27, 15, 6, 8, tzinfo=timezone.utc), | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | artifact_url = ( | ||||
f"{base_url}/src_contrib_1.4.0_Recommended_KernSmooth_{version}.tar.gz" # noqa | f"{base_url}/src_contrib_1.4.0_Recommended_KernSmooth_{version}.tar.gz" # noqa | ||||
) | ) | ||||
loader = CRANLoader( | loader = CRANLoader( | ||||
origin_url, artifacts=[{"url": artifact_url, "version": version,}] | origin_url, artifacts=[{"url": artifact_url, "version": version,}] | ||||
) | ) | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "920adcccc78aaeedd3cfa4459dd900d8c3431a21" | |||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": SNAPSHOT.id.hex(), | ||||
} | } | ||||
expected_snapshot = { | check_snapshot(SNAPSHOT, loader.storage) | ||||
"id": hash_to_bytes(expected_snapshot_id), | |||||
"branches": { | |||||
b"HEAD": {"target": b"releases/2.22-6", "target_type": "alias"}, | |||||
b"releases/2.22-6": { | |||||
"target": hash_to_bytes("42bdb16facd5140424359c8ce89a28ecfa1ce603"), | |||||
"target_type": "revision", | |||||
}, | |||||
}, | |||||
} | |||||
check_snapshot(expected_snapshot, loader.storage) | |||||
assert_last_visit_matches(loader.storage, origin_url, status="full", type="cran") | assert_last_visit_matches(loader.storage, origin_url, status="full", type="cran") | ||||
visit_stats = get_stats(loader.storage) | visit_stats = get_stats(loader.storage) | ||||
assert { | assert { | ||||
"content": 33, | "content": 33, | ||||
"directory": 7, | "directory": 7, | ||||
"origin": 1, | "origin": 1, | ||||
Show All 27 Lines | def test_cran_2_visits_same_origin(swh_config, requests_mock_datadir): | ||||
) | ) | ||||
# first visit | # first visit | ||||
actual_load_status = loader.load() | actual_load_status = loader.load() | ||||
expected_snapshot_id = "920adcccc78aaeedd3cfa4459dd900d8c3431a21" | expected_snapshot_id = "920adcccc78aaeedd3cfa4459dd900d8c3431a21" | ||||
assert actual_load_status == { | assert actual_load_status == { | ||||
"status": "eventful", | "status": "eventful", | ||||
"snapshot_id": expected_snapshot_id, | "snapshot_id": SNAPSHOT.id.hex(), | ||||
} | } | ||||
expected_snapshot = { | check_snapshot(SNAPSHOT, loader.storage) | ||||
"id": hash_to_bytes(expected_snapshot_id), | |||||
"branches": { | |||||
b"HEAD": {"target": b"releases/2.22-6", "target_type": "alias"}, | |||||
b"releases/2.22-6": { | |||||
"target": hash_to_bytes("42bdb16facd5140424359c8ce89a28ecfa1ce603"), | |||||
"target_type": "revision", | |||||
}, | |||||
}, | |||||
} | |||||
check_snapshot(expected_snapshot, loader.storage) | |||||
assert_last_visit_matches(loader.storage, origin_url, status="full", type="cran") | assert_last_visit_matches(loader.storage, origin_url, status="full", type="cran") | ||||
visit_stats = get_stats(loader.storage) | visit_stats = get_stats(loader.storage) | ||||
assert { | assert { | ||||
"content": 33, | "content": 33, | ||||
"directory": 7, | "directory": 7, | ||||
"origin": 1, | "origin": 1, | ||||
▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines |