diff --git a/swh/loader/package/archive/tests/test_archive.py b/swh/loader/package/archive/tests/test_archive.py --- a/swh/loader/package/archive/tests/test_archive.py +++ b/swh/loader/package/archive/tests/test_archive.py @@ -82,7 +82,7 @@ # hash is different then before as we changed the snapshot # gnu used to use `release/` (singular) instead of plural -_expected_new_snapshot_first_visit_id = ( +_expected_new_snapshot_first_visit_id = hash_to_bytes( "c419397fd912039825ebdbea378bc6283f006bf5" # noqa ) @@ -164,7 +164,8 @@ actual_load_status = loader.load() assert actual_load_status["status"] == "eventful" assert ( - actual_load_status["snapshot_id"] == _expected_new_snapshot_first_visit_id + hash_to_bytes(actual_load_status["snapshot_id"]) + == _expected_new_snapshot_first_visit_id ) # noqa assert_last_visit_matches(loader.storage, URL, status="full", type="tar") diff --git a/swh/loader/package/cran/tests/test_cran.py b/swh/loader/package/cran/tests/test_cran.py --- a/swh/loader/package/cran/tests/test_cran.py +++ b/swh/loader/package/cran/tests/test_cran.py @@ -176,7 +176,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"HEAD": {"target": b"releases/2.22-6", "target_type": "alias"}, b"releases/2.22-6": { @@ -233,7 +233,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"HEAD": {"target": b"releases/2.22-6", "target_type": "alias"}, b"releases/2.22-6": { diff --git a/swh/loader/package/debian/tests/test_debian.py b/swh/loader/package/debian/tests/test_debian.py --- a/swh/loader/package/debian/tests/test_debian.py +++ b/swh/loader/package/debian/tests/test_debian.py @@ -134,7 +134,7 @@ } == stats expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"releases/stretch/contrib/0.7.2-3": { "target_type": "revision", @@ -179,7 +179,7 @@ } == stats expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"releases/stretch/contrib/0.7.2-3": { "target_type": "revision", @@ -381,7 +381,7 @@ assert_last_visit_matches(loader.storage, url, status="full", type="deb") expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"releases/stretch/contrib/0.7.2-3": { "target_type": "revision", diff --git a/swh/loader/package/deposit/tests/test_deposit.py b/swh/loader/package/deposit/tests/test_deposit.py --- a/swh/loader/package/deposit/tests/test_deposit.py +++ b/swh/loader/package/deposit/tests/test_deposit.py @@ -174,7 +174,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } check_snapshot(expected_snapshot, storage=loader.storage) @@ -249,7 +249,7 @@ b"HEAD": {"target": hash_to_bytes(revision_id), "target_type": "revision"} } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } 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 @@ -198,7 +198,7 @@ }, } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } snapshot = check_snapshot(expected_snapshot, storage=loader.storage) @@ -245,7 +245,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } snapshot = check_snapshot(expected_snapshot, storage=loader.storage) @@ -292,7 +292,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } snapshot = check_snapshot(expected_snapshot, storage=loader.storage) @@ -347,7 +347,7 @@ } expected_snapshot = { - "id": "0c5881c74283793ebe9a09a105a9381e41380383", + "id": hash_to_bytes("0c5881c74283793ebe9a09a105a9381e41380383"), "branches": expected_branches, } @@ -374,7 +374,7 @@ }, } expected_snapshot = { - "id": "4257fa2350168c6bfec726a06452ea27a2c0cb33", + "id": hash_to_bytes("4257fa2350168c6bfec726a06452ea27a2c0cb33"), "branches": expected_branches, } @@ -426,7 +426,7 @@ }, } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } diff --git a/swh/loader/package/npm/tests/test_npm.py b/swh/loader/package/npm/tests/test_npm.py --- a/swh/loader/package/npm/tests/test_npm.py +++ b/swh/loader/package/npm/tests/test_npm.py @@ -323,7 +323,7 @@ ) expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": { b"HEAD": {"target": b"releases/0.0.4", "target_type": "alias"}, b"releases/0.0.2": { @@ -424,7 +424,7 @@ } == stats expected_snapshot = { - "id": "b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92", + "id": hash_to_bytes("b11ebac8c9d0c9e5063a2df693a18e3aba4b2f92"), "branches": { b"HEAD": {"target_type": "alias", "target": b"releases/0.1.0"}, b"releases/0.1.0": { @@ -514,7 +514,7 @@ # no branch as one artifact without any intrinsic metadata expected_snapshot = { - "id": "1a8893e6a86f444e8be8e7bda6cb34fb1735a00e", + "id": hash_to_bytes("1a8893e6a86f444e8be8e7bda6cb34fb1735a00e"), "branches": {}, } check_snapshot(expected_snapshot, loader.storage) @@ -535,7 +535,7 @@ # no branch as one artifact without any intrinsic metadata expected_snapshot = { - "id": "1a8893e6a86f444e8be8e7bda6cb34fb1735a00e", + "id": hash_to_bytes("1a8893e6a86f444e8be8e7bda6cb34fb1735a00e"), "branches": {}, } check_snapshot(expected_snapshot, loader.storage) @@ -556,7 +556,7 @@ # artifact is used expected_snapshot = { - "id": "d6e08e19159f77983242877c373c75222d5ae9dd", + "id": hash_to_bytes("d6e08e19159f77983242877c373c75222d5ae9dd"), "branches": { b"HEAD": {"target_type": "alias", "target": b"releases/0.0.1"}, b"releases/0.0.1": { diff --git a/swh/loader/package/pypi/tests/test_pypi.py b/swh/loader/package/pypi/tests/test_pypi.py --- a/swh/loader/package/pypi/tests/test_pypi.py +++ b/swh/loader/package/pypi/tests/test_pypi.py @@ -381,7 +381,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } check_snapshot(expected_snapshot, storage=loader.storage) @@ -466,7 +466,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } check_snapshot(expected_snapshot, loader.storage) @@ -516,7 +516,7 @@ } expected_snapshot = { - "id": snapshot_id, + "id": hash_to_bytes(snapshot_id), "branches": expected_branches, } check_snapshot(expected_snapshot, loader.storage) @@ -657,7 +657,7 @@ b"HEAD": {"target": b"releases/1.3.0", "target_type": "alias",}, } expected_snapshot = { - "id": expected_snapshot_id2, + "id": hash_to_bytes(expected_snapshot_id2), "branches": expected_branches, } @@ -711,7 +711,7 @@ } expected_snapshot = { - "id": expected_snapshot_id, + "id": hash_to_bytes(expected_snapshot_id), "branches": expected_branches, } check_snapshot(expected_snapshot, loader.storage) @@ -825,7 +825,7 @@ } # no branch as one artifact without any intrinsic metadata - expected_snapshot = {"id": expected_snapshot_id, "branches": {}} + expected_snapshot = {"id": hash_to_bytes(expected_snapshot_id), "branches": {}} check_snapshot(expected_snapshot, loader.storage) assert_last_visit_matches(loader.storage, url, status="full", type="pypi") diff --git a/swh/loader/tests/__init__.py b/swh/loader/tests/__init__.py --- a/swh/loader/tests/__init__.py +++ b/swh/loader/tests/__init__.py @@ -135,30 +135,20 @@ needed. """ - if isinstance(snapshot, Snapshot): - expected_snapshot = snapshot - elif isinstance(snapshot, dict): - # dict must be snapshot compliant - snapshot_dict = {"id": hash_to_bytes(snapshot["id"])} - branches = {} - for branch, target in snapshot["branches"].items(): - if isinstance(branch, str): - branch = branch.encode("utf-8") - branches[branch] = encode_target(target) - snapshot_dict["branches"] = branches - expected_snapshot = Snapshot.from_dict(snapshot_dict) - else: + if isinstance(snapshot, dict): + snapshot = Snapshot.from_dict(snapshot) + if not isinstance(snapshot, Snapshot): raise AssertionError(f"variable 'snapshot' must be a snapshot: {snapshot!r}") - snapshot_dict = storage.snapshot_get(expected_snapshot.id) + snapshot_dict = storage.snapshot_get(snapshot.id) if snapshot_dict is None: - raise AssertionError(f"Snapshot {expected_snapshot.id.hex()} is not found") + raise AssertionError(f"Snapshot {snapshot.id.hex()} is not found") snapshot_dict.pop("next_branch") actual_snaphot = Snapshot.from_dict(snapshot_dict) assert isinstance(actual_snaphot, Snapshot) - assert expected_snapshot == actual_snaphot + assert snapshot == actual_snaphot branches_by_target_type = defaultdict(list) object_to_branch = {} diff --git a/swh/loader/tests/test_init.py b/swh/loader/tests/test_init.py --- a/swh/loader/tests/test_init.py +++ b/swh/loader/tests/test_init.py @@ -384,7 +384,8 @@ } unexpected_snapshot = { - "id": "2498dbf535f882bc7f9a18fb16c9ad27fda7bab7", # id is correct + # id is correct + "id": hash_to_bytes(snap_id_hex), "branches": { b"master": { "target": hash_to_bytes(hash_hex), # wrong branch @@ -398,17 +399,15 @@ check_snapshot(ORIGIN_VISIT, swh_storage) # 1. snapshot id is correct but branches mismatched - for snap_id in [snap_id_hex, snapshot.id]: - with pytest.raises(AssertionError, match="Differing attributes"): - unexpected_snapshot["id"] = snap_id - check_snapshot(unexpected_snapshot, swh_storage) + with pytest.raises(AssertionError, match="Differing attributes"): + unexpected_snapshot["id"] = snapshot.id + check_snapshot(unexpected_snapshot, swh_storage) # 2. snapshot id is not correct, it's not found in the storage - wrong_snap_id_hex = "999666f535f882bc7f9a18fb16c9ad27fda7bab7" - for snap_id in [wrong_snap_id_hex, hash_to_bytes(wrong_snap_id_hex)]: - unexpected_snapshot["id"] = wrong_snap_id_hex - with pytest.raises(AssertionError, match="is not found"): - check_snapshot(unexpected_snapshot, swh_storage) + wrong_snap_id = hash_to_bytes("999666f535f882bc7f9a18fb16c9ad27fda7bab7") + unexpected_snapshot["id"] = wrong_snap_id + with pytest.raises(AssertionError, match="is not found"): + check_snapshot(unexpected_snapshot, swh_storage) # 3. snapshot references an inexistent alias snapshot0 = Snapshot(