Skip to content
Snippets Groups Projects
Commit e590b425 authored by vlorentz's avatar vlorentz
Browse files

test_resolve_revision_from_artifacts: Use the right type for PartialExtID.

We used a string instead of a tuple. It doesn't matter much because they
are only compared with each other, but let's not intentionally use
the wrong types when we don't need to.
parent 2f9b8a8b
No related branches found
No related tags found
1 merge request!197test_resolve_revision_from_artifacts: Use the right type for PartialExtID.
......@@ -5,7 +5,7 @@
import hashlib
import string
from unittest.mock import MagicMock
from unittest.mock import Mock
import attr
import pytest
......@@ -45,18 +45,18 @@ def test_loader_origin_visit_failure(swh_storage):
assert actual_load_status2 == {"status": "failed"}
def test_resolve_revision_from_artifacts():
loader = PackageLoader(None, None)
loader.known_artifact_to_extid = MagicMock(
wraps=lambda known_artifact: known_artifact["key"].encode()
def test_resolve_revision_from_artifacts() -> None:
loader = PackageLoader(None, None) # type: ignore
loader.known_artifact_to_extid = Mock( # type: ignore
wraps=lambda known_artifact: ("extid-type", known_artifact["key"].encode())
)
known_artifacts = {
b"a" * 40: {"key": "extid-of-aaaa"},
b"b" * 40: {"key": "extid-of-bbbb"},
b"a" * 20: {"key": "extid-of-aaaa"},
b"b" * 20: {"key": "extid-of-bbbb"},
}
p_info = MagicMock()
p_info = Mock(wraps=BasePackageInfo(None, None)) # type: ignore
# No known artifact -> it would be useless to compute the extid
assert loader.resolve_revision_from_artifacts({}, p_info) is None
......@@ -74,7 +74,7 @@ def test_resolve_revision_from_artifacts():
p_info.extid.reset_mock()
# Some artifacts, and the PackageInfo is not one of them (ie. cache miss)
p_info.extid.return_value = b"extid-of-cccc"
p_info.extid.return_value = ("extid-type", b"extid-of-cccc")
assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) is None
p_info.extid.assert_called_once()
loader.known_artifact_to_extid.assert_any_call({"key": "extid-of-aaaa"})
......@@ -84,8 +84,8 @@ def test_resolve_revision_from_artifacts():
loader.known_artifact_to_extid.reset_mock()
# Some artifacts, and the PackageInfo is one of them (ie. cache hit)
p_info.extid.return_value = b"extid-of-aaaa"
assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) == b"a" * 40
p_info.extid.return_value = ("extid-type", b"extid-of-aaaa")
assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) == b"a" * 20
p_info.extid.assert_called_once()
loader.known_artifact_to_extid.assert_called_once_with({"key": "extid-of-aaaa"})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment