diff --git a/swh/loader/package/tests/test_loader.py b/swh/loader/package/tests/test_loader.py --- a/swh/loader/package/tests/test_loader.py +++ b/swh/loader/package/tests/test_loader.py @@ -5,12 +5,13 @@ import hashlib import string +from typing import Optional from unittest.mock import Mock import attr import pytest -from swh.loader.package.loader import BasePackageInfo, PackageLoader +from swh.loader.package.loader import BasePackageInfo, PackageLoader, PartialExtID class FakeStorage: @@ -45,22 +46,22 @@ assert actual_load_status2 == {"status": "failed"} -def test_resolve_revision_from_artifacts(): - loader = PackageLoader(None, None) - loader.known_artifact_to_extid = Mock( - 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"}, } class StubPackageInfo(BasePackageInfo): - def extid(self): + def extid(self) -> Optional[PartialExtID]: return return_extid - p_info = Mock(wraps=StubPackageInfo(None, None)) + p_info = Mock(wraps=StubPackageInfo(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 @@ -78,7 +79,7 @@ p_info.extid.reset_mock() # Some artifacts, and the PackageInfo is not one of them (ie. cache miss) - return_extid = b"extid-of-cccc" + return_extid = ("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"}) @@ -88,8 +89,8 @@ loader.known_artifact_to_extid.reset_mock() # Some artifacts, and the PackageInfo is one of them (ie. cache hit) - return_extid = b"extid-of-aaaa" - assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) == b"a" * 40 + return_extid = ("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"})