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,7 +5,7 @@ import hashlib import string -from unittest.mock import MagicMock +from unittest.mock import Mock import attr import pytest @@ -47,7 +47,7 @@ def test_resolve_revision_from_artifacts(): loader = PackageLoader(None, None) - loader.known_artifact_to_extid = MagicMock( + loader.known_artifact_to_extid = Mock( wraps=lambda known_artifact: known_artifact["key"].encode() ) @@ -56,7 +56,11 @@ b"b" * 40: {"key": "extid-of-bbbb"}, } - p_info = MagicMock() + class StubPackageInfo(BasePackageInfo): + def extid(self): + return return_extid + + p_info = Mock(wraps=StubPackageInfo(None, None)) # No known artifact -> it would be useless to compute the extid assert loader.resolve_revision_from_artifacts({}, p_info) is None @@ -66,7 +70,7 @@ p_info.extid.reset_mock() # Some artifacts, but the PackageInfo does not support extids - p_info.extid.return_value = None + return_extid = None assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) is None p_info.extid.assert_called_once() loader.known_artifact_to_extid.assert_not_called() @@ -74,7 +78,7 @@ 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" + return_extid = 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,7 +88,7 @@ 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" + return_extid = b"extid-of-aaaa" assert loader.resolve_revision_from_artifacts(known_artifacts, p_info) == b"a" * 40 p_info.extid.assert_called_once() loader.known_artifact_to_extid.assert_called_once_with({"key": "extid-of-aaaa"})