Page MenuHomeSoftware Heritage

D3539.id12490.diff
No OneTemporary

D3539.id12490.diff

diff --git a/swh/loader/package/nixguix/tests/test_nixguix.py b/swh/loader/package/nixguix/tests/test_nixguix.py
--- a/swh/loader/package/nixguix/tests/test_nixguix.py
+++ b/swh/loader/package/nixguix/tests/test_nixguix.py
@@ -15,7 +15,7 @@
from unittest.mock import patch
-from swh.model.model import Snapshot, TargetType
+from swh.model.model import Snapshot, SnapshotBranch, TargetType
from swh.loader.package.archive.loader import ArchiveLoader
from swh.loader.package.nixguix.loader import (
NixGuixLoader,
@@ -37,6 +37,21 @@
sources_url = "https://nix-community.github.io/nixpkgs-swh/sources.json"
+SNAPSHOT1 = Snapshot(
+ id=hash_to_bytes("0c5881c74283793ebe9a09a105a9381e41380383"),
+ branches={
+ b"evaluation": SnapshotBranch(
+ target=hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
+ target_type=TargetType.REVISION,
+ ),
+ b"https://github.com/owner-1/repository-1/revision-1.tgz": SnapshotBranch(
+ target=hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
+ target_type=TargetType.REVISION,
+ ),
+ },
+)
+
+
def check_snapshot(
snapshot: Union[Dict[str, Any], Snapshot],
storage: StorageInterface,
@@ -104,16 +119,16 @@
assert len(clean["sources"]) == 1
-def check_snapshot_revisions_ok(snapshot, storage):
+def check_snapshot_revisions_ok(snapshot: Snapshot, storage: StorageInterface):
"""Ensure the snapshot revisions are structurally as expected
"""
revision_ids = []
- for name, branch in snapshot["branches"].items():
+ for name, branch in snapshot.branches.items():
if name == b"evaluation":
continue # skipping that particular branch
- if branch["target_type"] == "revision":
- revision_ids.append(branch["target"])
+ if branch.target_type == TargetType.REVISION:
+ revision_ids.append(branch.target)
revisions = storage.revision_get(revision_ids)
for rev in revisions:
@@ -180,29 +195,18 @@
load_status = loader.load()
loader.load()
- expected_snapshot_id = "0c5881c74283793ebe9a09a105a9381e41380383"
- assert load_status == {"status": "eventful", "snapshot_id": expected_snapshot_id}
+ assert load_status == {"status": "eventful", "snapshot_id": SNAPSHOT1.id.hex()}
assert_last_visit_matches(
- loader.storage, sources_url, status="partial", type="nixguix"
+ loader.storage,
+ sources_url,
+ status="partial",
+ type="nixguix",
+ snapshot=SNAPSHOT1.id,
)
- expected_branches = {
- b"evaluation": {
- "target": hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
- "target_type": "revision",
- },
- b"https://github.com/owner-1/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
- "target_type": "revision",
- },
- }
- expected_snapshot = {
- "id": hash_to_bytes(expected_snapshot_id),
- "branches": expected_branches,
- }
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ check_snapshot(SNAPSHOT1, storage=loader.storage)
+ check_snapshot_revisions_ok(SNAPSHOT1, loader.storage)
urls = [
m.url
@@ -226,30 +230,18 @@
"""
loader = NixGuixLoader(sources_url)
load_status = loader.load()
- expected_snapshot_id = "0c5881c74283793ebe9a09a105a9381e41380383"
- assert load_status == {"status": "eventful", "snapshot_id": expected_snapshot_id}
+ assert load_status == {"status": "eventful", "snapshot_id": SNAPSHOT1.id.hex()}
assert_last_visit_matches(
- loader.storage, sources_url, status="partial", type="nixguix"
+ loader.storage,
+ sources_url,
+ status="partial",
+ type="nixguix",
+ snapshot=SNAPSHOT1.id,
)
- expected_branches = {
- b"evaluation": {
- "target": hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
- "target_type": "revision",
- },
- b"https://github.com/owner-1/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
- "target_type": "revision",
- },
- }
-
- expected_snapshot = {
- "id": hash_to_bytes(expected_snapshot_id),
- "branches": expected_branches,
- }
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ check_snapshot(SNAPSHOT1, storage=loader.storage)
+ check_snapshot_revisions_ok(SNAPSHOT1, loader.storage)
stats = get_stats(loader.storage)
assert {
@@ -266,37 +258,43 @@
loader = NixGuixLoader(sources_url)
load_status = loader.load()
- expected_snapshot_id = "b0bfa75cbd0cc90aac3b9e95fb0f59c731176d97"
- assert load_status == {"status": "eventful", "snapshot_id": expected_snapshot_id}
+ expected_snapshot_id_hex = "b0bfa75cbd0cc90aac3b9e95fb0f59c731176d97"
+ expected_snapshot_id = hash_to_bytes(expected_snapshot_id_hex)
+ assert load_status == {
+ "status": "eventful",
+ "snapshot_id": expected_snapshot_id_hex,
+ }
assert_last_visit_matches(
- loader.storage, sources_url, status="partial", type="nixguix"
+ loader.storage,
+ sources_url,
+ status="partial",
+ type="nixguix",
+ snapshot=expected_snapshot_id,
)
# This ensures visits are incremental. Indeed, if we request a
# second time an url, because of the requests_mock_datadir_visits
# fixture, the file has to end with `_visit1`.
- expected_branches = {
- b"evaluation": {
- "target": hash_to_bytes("602140776b2ce6c9159bcf52ada73a297c063d5e"),
- "target_type": "revision",
- },
- b"https://github.com/owner-1/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
- "target_type": "revision",
- },
- b"https://github.com/owner-2/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("85e0bad74e33e390aaeb74f139853ae3863ee544"),
- "target_type": "revision",
+ expected_snapshot = Snapshot(
+ id=expected_snapshot_id,
+ branches={
+ b"evaluation": SnapshotBranch(
+ target=hash_to_bytes("602140776b2ce6c9159bcf52ada73a297c063d5e"),
+ target_type=TargetType.REVISION,
+ ),
+ b"https://github.com/owner-1/repository-1/revision-1.tgz": SnapshotBranch(
+ target=hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
+ target_type=TargetType.REVISION,
+ ),
+ b"https://github.com/owner-2/repository-1/revision-1.tgz": SnapshotBranch(
+ target=hash_to_bytes("85e0bad74e33e390aaeb74f139853ae3863ee544"),
+ target_type=TargetType.REVISION,
+ ),
},
- }
-
- expected_snapshot = {
- "id": hash_to_bytes(expected_snapshot_id),
- "branches": expected_branches,
- }
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ )
+ check_snapshot(expected_snapshot, storage=loader.storage)
+ check_snapshot_revisions_ok(expected_snapshot, loader.storage)
stats = get_stats(loader.storage)
assert {
@@ -332,27 +330,15 @@
assert res["status"] == "eventful"
assert_last_visit_matches(
- loader.storage, sources_url, status="partial", type="nixguix"
+ loader.storage,
+ sources_url,
+ status="partial",
+ type="nixguix",
+ snapshot=SNAPSHOT1.id,
)
- expected_branches = {
- b"https://github.com/owner-1/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
- "target_type": "revision",
- },
- b"evaluation": {
- "target": hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
- "target_type": "revision",
- },
- }
-
- expected_snapshot = {
- "id": hash_to_bytes("0c5881c74283793ebe9a09a105a9381e41380383"),
- "branches": expected_branches,
- }
-
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ check_snapshot(SNAPSHOT1, storage=loader.storage)
+ check_snapshot_revisions_ok(SNAPSHOT1, loader.storage)
def test_eoferror(swh_config, requests_mock_datadir):
@@ -367,19 +353,18 @@
loader = NixGuixLoader(sources)
loader.load()
- expected_branches = {
- b"evaluation": {
- "target": hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
- "target_type": "revision",
+ expected_snapshot = Snapshot(
+ id=hash_to_bytes("4257fa2350168c6bfec726a06452ea27a2c0cb33"),
+ branches={
+ b"evaluation": SnapshotBranch(
+ target=hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
+ target_type=TargetType.REVISION,
+ ),
},
- }
- expected_snapshot = {
- "id": hash_to_bytes("4257fa2350168c6bfec726a06452ea27a2c0cb33"),
- "branches": expected_branches,
- }
+ )
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ check_snapshot(expected_snapshot, storage=loader.storage)
+ check_snapshot_revisions_ok(expected_snapshot, loader.storage)
def fake_download(
@@ -409,29 +394,13 @@
loader = NixGuixLoader(sources_url)
res = loader.load()
- expected_snapshot_id = "0c5881c74283793ebe9a09a105a9381e41380383"
assert res == {
"status": "eventful",
- "snapshot_id": expected_snapshot_id,
- }
-
- expected_branches = {
- b"https://github.com/owner-1/repository-1/revision-1.tgz": {
- "target": hash_to_bytes("488ad4e7b8e2511258725063cf43a2b897c503b4"),
- "target_type": "revision",
- },
- b"evaluation": {
- "target": hash_to_bytes("cc4e04c26672dd74e5fd0fecb78b435fb55368f7"),
- "target_type": "revision",
- },
- }
- expected_snapshot = {
- "id": hash_to_bytes(expected_snapshot_id),
- "branches": expected_branches,
+ "snapshot_id": SNAPSHOT1.id.hex(),
}
- snapshot = check_snapshot(expected_snapshot, storage=loader.storage)
- check_snapshot_revisions_ok(snapshot, loader.storage)
+ check_snapshot(SNAPSHOT1, storage=loader.storage)
+ check_snapshot_revisions_ok(SNAPSHOT1, loader.storage)
assert len(mock_download.mock_calls) == 2

File Metadata

Mime Type
text/plain
Expires
Dec 20 2024, 7:25 AM (11 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3221802

Event Timeline