1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
from unittest.mock import MagicMock
import pytest
import briefcase.commands.upgrade
from briefcase.commands import UpgradeCommand
from briefcase.exceptions import MissingToolError
from briefcase.integrations.base import ManagedTool, Tool
from ...utils import DummyConsole
@pytest.fixture
def upgrade_command(tmp_path):
command = DummyUpgradeCommand(base_path=tmp_path)
command.tools.host_os = "wonky"
return command
class DummyUpgradeCommand(UpgradeCommand):
"""A dummy upgrade command that doesn't actually do anything.
It only serves to track which actions would be performed.
"""
# Platform and format contain upper case to test case normalization
platform = "Tester"
output_format = "Dummy"
description = "Dummy update command"
def __init__(self, *args, **kwargs):
kwargs.setdefault("console", DummyConsole())
super().__init__(*args, **kwargs)
def bundle_path(self, app):
return self.platform_path / f"{app.app_name}.dummy"
def binary_path(self, app):
return self.bundle_path(app) / f"{app.app_name}.bin"
@pytest.fixture
def mock_tool_registry(monkeypatch):
"""Tool registry with all dummy tools."""
tool_list = [
DummyTool,
DummyManagedTool1,
DummyManagedTool2,
DummyManagedTool3,
DummyUnManagedManagedTool,
DummyNotInstalledManagedTool,
]
tool_registry = dict()
for tool in tool_list:
monkeypatch.setattr(tool, "verify", MagicMock(wraps=tool.verify))
tool_registry[tool.name] = tool
monkeypatch.setattr(briefcase.commands.upgrade, "tool_registry", tool_registry)
@pytest.fixture
def mock_no_managed_tool_registry(monkeypatch):
"""Tool registry without any installed managed tools."""
tool_list = [
DummyTool,
DummyUnManagedManagedTool,
DummyNotInstalledManagedTool,
]
tool_registry = dict()
for tool in tool_list:
monkeypatch.setattr(tool, "verify", MagicMock(wraps=tool.verify))
tool_registry[tool.name] = tool
monkeypatch.setattr(briefcase.commands.upgrade, "tool_registry", tool_registry)
class DummyToolBase(Tool):
name = "dummy_tool_base"
supported_host_os = {"wonky"}
@classmethod
def verify_install(cls, tools, **kwargs):
return cls(tools=tools)
class DummyManagedToolBase(ManagedTool):
name = "dummy_managed_tool_base"
supported_host_os = {"wonky"}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.actions = []
@classmethod
def verify_install(cls, tools, **kwargs):
# add to ToolCache so accessible after upgrade
setattr(tools, cls.name, cls(tools=tools))
return getattr(tools, cls.name)
def exists(self) -> bool:
self.actions.append("exists")
return True
def install(self):
self.actions.append("install")
def uninstall(self):
self.actions.append("uninstall")
class DummyTool(DummyToolBase):
"""Unmanaged Tool testing class."""
name = "unmanaged"
full_name = "Unmanaged Dummy Tool"
class DummyUnManagedManagedTool(DummyManagedToolBase):
"""Managed Tool without a managed install testing class."""
name = "unmanaged_managed"
full_name = "Unmanaged Managed Dummy Tool"
@property
def managed_install(self) -> bool:
return False
class DummyNotInstalledManagedTool(DummyManagedToolBase):
"""Managed Tool without a managed install testing class."""
name = "not_installed"
full_name = "Not Installed Managed Dummy Tool"
@classmethod
def verify_install(cls, tools, **kwargs):
raise MissingToolError(cls.full_name)
class DummyManagedTool1(DummyManagedToolBase):
"""Managed Tool testing class."""
name = "managed_1"
full_name = "Managed Dummy Tool 1"
class DummyManagedTool2(DummyManagedToolBase):
"""Managed Tool testing class."""
name = "managed_2"
full_name = "Managed Dummy Tool 2"
class DummyManagedTool3(DummyManagedToolBase):
"""Managed Tool testing class."""
name = "managed_3"
full_name = "Managed Dummy Tool 3"
|