Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/tests/__init__.py
Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | Returns: | ||||
the snapshot stored in the storage for further test assertion if any is | the snapshot stored in the storage for further test assertion if any is | ||||
needed. | needed. | ||||
""" | """ | ||||
expected_snapshot_id = expected_snapshot["id"] | expected_snapshot_id = expected_snapshot["id"] | ||||
expected_branches = expected_snapshot["branches"] | expected_branches = expected_snapshot["branches"] | ||||
snap = storage.snapshot_get(hash_to_bytes(expected_snapshot_id)) | snap = storage.snapshot_get(hash_to_bytes(expected_snapshot_id)) | ||||
if snap is None: | if snap is None: | ||||
# display known snapshots instead if possible | raise AssertionError(f"Snapshot {expected_snapshot_id} is not found") | ||||
if hasattr(storage, "_snapshots"): # in-mem storage | |||||
from pprint import pprint | |||||
for snap_id, (_snap, _) in storage._snapshots.items(): | |||||
snapd = _snap.to_dict() | |||||
snapd["id"] = hash_to_hex(snapd["id"]) | |||||
branches = { | |||||
branch.decode("utf-8"): decode_target(target) | |||||
for branch, target in snapd["branches"].items() | |||||
} | |||||
snapd["branches"] = branches | |||||
pprint(snapd) | |||||
raise AssertionError("Snapshot is not found") | |||||
branches = { | branches = { | ||||
branch.decode("utf-8"): decode_target(target) | branch.decode("utf-8"): decode_target(target) | ||||
for branch, target in snap["branches"].items() | for branch, target in snap["branches"].items() | ||||
} | } | ||||
assert expected_branches == branches | assert expected_branches == branches | ||||
return snap | return snap | ||||
Show All 21 Lines |