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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
from unittest.mock import MagicMock
import briefcase.platforms.linux.system
from briefcase.integrations.docker import Docker, DockerAppContext
from briefcase.integrations.subprocess import Subprocess
def test_linux_no_docker(create_command, first_app_config, monkeypatch):
"""If Docker is disabled on Linux, the app_context is Subprocess."""
create_command.tools.host_os = "Linux"
create_command.target_image = None
# Force a dummy vendor:codename for test purposes.
first_app_config.target_vendor = "somevendor"
first_app_config.target_codename = "surprising"
first_app_config.target_vendor_base = "basevendor"
# Mock the existence of a valid non-docker system Python
create_command.verify_system_python = MagicMock()
# Verify the tools
create_command.verify_tools()
create_command.verify_app_tools(app=first_app_config)
# No error and Subprocess is used.
assert isinstance(create_command.tools[first_app_config].app_context, Subprocess)
# Docker is not verified.
assert not hasattr(create_command.tools, "docker")
# System python is verified
create_command.verify_system_python.assert_called_once_with()
# Reset the mock, then invoke verify_app_tools a second time.
create_command.verify_system_python.reset_mock()
create_command.verify_app_tools(app=first_app_config)
# Python will *not* be verified a second time.
create_command.verify_system_python.assert_not_called()
def test_linux_docker(create_command, first_app_config, tmp_path, monkeypatch):
"""If Docker is enabled on Linux, the Docker alias is set."""
create_command.tools.host_os = "Linux"
create_command.target_image = "somevendor:surprising"
create_command.extra_docker_build_args = ["--option-one", "--option-two"]
# Force a dummy vendor:codename for test purposes.
first_app_config.target_vendor = "somevendor"
first_app_config.target_codename = "surprising"
first_app_config.target_vendor_base = "basevendor"
first_app_config.python_version_tag = "3"
# Mock Docker tool verification
mock__version_compat = MagicMock(spec=Docker._version_compat)
mock__user_access = MagicMock(spec=Docker._user_access)
mock__buildx_installed = MagicMock(spec=Docker._buildx_installed)
mock__is_user_mapping_enabled = MagicMock(spec=Docker._is_user_mapping_enabled)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_version_compat",
mock__version_compat,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_user_access",
mock__user_access,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_buildx_installed",
mock__buildx_installed,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_is_user_mapping_enabled",
mock__is_user_mapping_enabled,
)
mock_docker_app_context_verify = MagicMock(spec=DockerAppContext.verify)
monkeypatch.setattr(
briefcase.platforms.linux.system.DockerAppContext,
"verify",
mock_docker_app_context_verify,
)
create_command.verify_docker_python = MagicMock()
# Verify the tools
create_command.verify_tools()
create_command.verify_app_tools(app=first_app_config)
# Docker and Docker app context are verified
mock__version_compat.assert_called_with(tools=create_command.tools)
mock__user_access.assert_called_with(tools=create_command.tools)
mock__buildx_installed.assert_called_with(tools=create_command.tools)
mock__is_user_mapping_enabled.assert_called_with("somevendor:surprising")
assert isinstance(create_command.tools.docker, Docker)
mock_docker_app_context_verify.assert_called_with(
tools=create_command.tools,
app=first_app_config,
image_tag="briefcase/com.example.first-app:somevendor-surprising",
dockerfile_path=tmp_path
/ "base_path/build/first-app/somevendor/surprising/Dockerfile",
app_base_path=tmp_path / "base_path",
host_bundle_path=tmp_path / "base_path/build/first-app/somevendor/surprising",
host_data_path=tmp_path / "briefcase",
python_version="3",
extra_build_args=["--option-one", "--option-two"],
)
# Python was also verified
create_command.verify_docker_python.assert_called_once_with(first_app_config)
# Reset the mock, then invoke verify_app_tools a second time.
create_command.verify_docker_python.reset_mock()
create_command.verify_app_tools(app=first_app_config)
# Python will *not* be verified a second time.
create_command.verify_docker_python.assert_not_called()
def test_non_linux_docker(create_command, first_app_config, tmp_path, monkeypatch):
"""If Docker is enabled on non-Linux, the Docker alias is set."""
create_command.tools.host_os = "Darwin"
create_command.target_image = "somevendor:surprising"
create_command.extra_docker_build_args = ["--option-one", "--option-two"]
# Force a dummy vendor:codename for test purposes.
first_app_config.target_vendor = "somevendor"
first_app_config.target_codename = "surprising"
first_app_config.target_vendor_base = "basevendor"
first_app_config.python_version_tag = "3"
# Mock Docker tool verification
mock__version_compat = MagicMock(spec=Docker._version_compat)
mock__user_access = MagicMock(spec=Docker._user_access)
mock__buildx_installed = MagicMock(spec=Docker._buildx_installed)
mock__is_user_mapping_enabled = MagicMock(spec=Docker._is_user_mapping_enabled)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_version_compat",
mock__version_compat,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_user_access",
mock__user_access,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_buildx_installed",
mock__buildx_installed,
)
monkeypatch.setattr(
briefcase.platforms.linux.system.Docker,
"_is_user_mapping_enabled",
mock__is_user_mapping_enabled,
)
mock_docker_app_context_verify = MagicMock(spec=DockerAppContext.verify)
monkeypatch.setattr(
briefcase.platforms.linux.system.DockerAppContext,
"verify",
mock_docker_app_context_verify,
)
create_command.verify_docker_python = MagicMock()
# Verify the tools
create_command.verify_tools()
create_command.verify_app_tools(app=first_app_config)
# Docker and Docker app context are verified
mock__version_compat.assert_called_with(tools=create_command.tools)
mock__user_access.assert_called_with(tools=create_command.tools)
mock__buildx_installed.assert_called_with(tools=create_command.tools)
mock__is_user_mapping_enabled.assert_called_with("somevendor:surprising")
assert isinstance(create_command.tools.docker, Docker)
mock_docker_app_context_verify.assert_called_with(
tools=create_command.tools,
app=first_app_config,
image_tag="briefcase/com.example.first-app:somevendor-surprising",
dockerfile_path=tmp_path
/ "base_path/build/first-app/somevendor/surprising/Dockerfile",
app_base_path=tmp_path / "base_path",
host_bundle_path=tmp_path / "base_path/build/first-app/somevendor/surprising",
host_data_path=tmp_path / "briefcase",
python_version="3",
extra_build_args=["--option-one", "--option-two"],
)
# Python was also verified
create_command.verify_docker_python.assert_called_once_with(first_app_config)
# Reset the mock, then invoke verify_app_tools a second time.
create_command.verify_docker_python.reset_mock()
create_command.verify_app_tools(app=first_app_config)
# Python will *not* be verified a second time.
create_command.verify_docker_python.assert_not_called()
|