| 1 |
import sys |
| 2 |
|
| 3 |
import pytest |
| 4 |
from packaging.version import Version |
| 5 |
|
| 6 |
from briefcase.exceptions import UnsupportedHostError |
| 7 |
from briefcase.platforms.windows.app import WindowsAppCreateCommand |
| 8 |
|
| 9 |
|
| 10 |
@pytest.fixture |
| 11 |
def create_command(dummy_console, tmp_path): |
| 12 |
return WindowsAppCreateCommand( |
| 13 |
console=dummy_console, |
| 14 |
base_path=tmp_path / "base_path", |
| 15 |
data_path=tmp_path / "briefcase", |
| 16 |
) |
| 17 |
|
| 18 |
|
| 19 |
@pytest.mark.parametrize("host_os", ["Darwin", "Linux", "WeirdOS"]) |
| 20 |
def test_unsupported_host_os(create_command, host_os): |
| 21 |
"""Error raised for an unsupported OS.""" |
| 22 |
create_command.tools.host_os = host_os |
| 23 |
|
| 24 |
with pytest.raises( |
| 25 |
UnsupportedHostError, |
| 26 |
match=r"Windows applications can only be built on Windows\.", |
| 27 |
): |
| 28 |
create_command() |
| 29 |
|
| 30 |
|
| 31 |
@pytest.mark.parametrize("host_arch", ["i686", "ARM64", "wonky"]) |
| 32 |
def test_unsupported_arch(create_command, host_arch, first_app_config): |
| 33 |
"""Internal apps can only be developed on x86-64.""" |
| 34 |
create_command.tools.host_os = "Windows" |
| 35 |
create_command.tools.host_arch = host_arch |
| 36 |
create_command.apps["first"] = first_app_config |
| 37 |
|
| 38 |
with pytest.raises( |
| 39 |
UnsupportedHostError, |
| 40 |
match=f"Windows applications cannot be built on an {host_arch} machine.", |
| 41 |
): |
| 42 |
create_command.verify_host() |
| 43 |
|
| 44 |
|
| 45 |
@pytest.mark.parametrize("host_arch", ["i686", "ARM64", "wonky"]) |
| 46 |
def test_unsupported_arch_external(create_command, host_arch, first_app_config, capsys): |
| 47 |
"""External apps can be built on a different architecture, with a warning.""" |
| 48 |
create_command.tools.host_os = "Windows" |
| 49 |
create_command.tools.host_arch = host_arch |
| 50 |
create_command.apps["first"] = first_app_config |
| 51 |
first_app_config.external_package_path = "external" |
| 52 |
|
| 53 |
create_command.verify_host() |
| 54 |
stdout, stderr = capsys.readouterr() |
| 55 |
assert "WARNING: Possible architecture mismatch" in stdout |
| 56 |
assert stderr == "" |
| 57 |
|
| 58 |
# The warning is not repeated on cloned commands. |
| 59 |
create_command.is_clone = True |
| 60 |
create_command.verify_host() |
| 61 |
assert capsys.readouterr() == ("", "") |
| 62 |
|
| 63 |
|
| 64 |
def test_supported_arch(create_command): |
| 65 |
"""Windows command are allowed to run on x86-64.""" |
| 66 |
create_command.tools.host_os = "Windows" |
| 67 |
create_command.tools.host_arch = "AMD64" |
| 68 |
|
| 69 |
create_command.verify_host() |
| 70 |
|
| 71 |
|
| 72 |
def test_unsupported_32bit_python(create_command): |
| 73 |
"""Windows commands cannot run with 32bit Python.""" |
| 74 |
create_command.tools.host_os = "Windows" |
| 75 |
create_command.tools.host_arch = "AMD64" |
| 76 |
create_command.tools.is_32bit_python = True |
| 77 |
|
| 78 |
with pytest.raises( |
| 79 |
UnsupportedHostError, |
| 80 |
match="Windows applications cannot be built using a 32bit version of Python", |
| 81 |
): |
| 82 |
create_command() |
| 83 |
|
| 84 |
|
| 85 |
def test_context(create_command, first_app_config): |
| 86 |
context = create_command.output_format_template_context(first_app_config) |
| 87 |
assert sorted(context.keys()) == [ |
| 88 |
"binary_path", |
| 89 |
"guid", |
| 90 |
"install_scope", |
| 91 |
"package_path", |
| 92 |
"version_triple", |
| 93 |
] |
| 94 |
|
| 95 |
|
| 96 |
@pytest.mark.parametrize( |
| 97 |
("version", "version_triple"), |
| 98 |
[ |
| 99 |
("1", "1.0.0"), |
| 100 |
("1.2", "1.2.0"), |
| 101 |
("1.2.3", "1.2.3"), |
| 102 |
("1.2.3.4", "1.2.3"), |
| 103 |
("1.2.3a4", "1.2.3"), |
| 104 |
("1.2.3b5", "1.2.3"), |
| 105 |
("1.2.3rc6", "1.2.3"), |
| 106 |
("1.2.3.dev7", "1.2.3"), |
| 107 |
("1.2.3.post8", "1.2.3"), |
| 108 |
], |
| 109 |
) |
| 110 |
def test_version_triple( |
| 111 |
create_command, first_app_config, tmp_path, version, version_triple |
| 112 |
): |
| 113 |
first_app_config.version = Version(version) |
| 114 |
context = create_command.output_format_template_context(first_app_config) |
| 115 |
|
| 116 |
assert context["version_triple"] == version_triple |
| 117 |
|
| 118 |
|
| 119 |
def test_explicit_version_triple(create_command, first_app_config, tmp_path): |
| 120 |
first_app_config.version = "1.2.3a1" |
| 121 |
first_app_config.version_triple = "2.3.4" |
| 122 |
|
| 123 |
context = create_command.output_format_template_context(first_app_config) |
| 124 |
|
| 125 |
# Explicit version triple is used. |
| 126 |
assert context["version_triple"] == "2.3.4" |
| 127 |
|
| 128 |
|
| 129 |
def test_guid(create_command, first_app_config, tmp_path): |
| 130 |
"""A predictable GUID will be generated from the bundle.""" |
| 131 |
context = create_command.output_format_template_context(first_app_config) |
| 132 |
|
| 133 |
assert context["guid"] == "d666a4f1-c7b7-52cc-888a-3a35a7cc97e5" |
| 134 |
|
| 135 |
|
| 136 |
def test_explicit_guid(create_command, first_app_config, tmp_path): |
| 137 |
"""If a GUID is explicitly provided, it is used.""" |
| 138 |
first_app_config.guid = "e822176f-b755-589f-849c-6c6600f7efb1" |
| 139 |
context = create_command.output_format_template_context(first_app_config) |
| 140 |
|
| 141 |
# Explicitly provided GUID is used. |
| 142 |
assert context["guid"] == "e822176f-b755-589f-849c-6c6600f7efb1" |
| 143 |
|
| 144 |
|
| 145 |
@pytest.mark.parametrize( |
| 146 |
("revision", "micro"), |
| 147 |
[ |
| 148 |
# Numerical revision |
| 149 |
(5, "5"), |
| 150 |
# Text revision |
| 151 |
("5", "5"), |
| 152 |
# Pre-release revision |
| 153 |
("0a3", "0"), |
| 154 |
("0b2", "0"), |
| 155 |
("0rc1", "0"), |
| 156 |
], |
| 157 |
) |
| 158 |
def test_support_package_url( |
| 159 |
create_command, revision, micro, first_app_config, tmp_path |
| 160 |
): |
| 161 |
"""A valid support package URL is created for a support revision.""" |
| 162 |
expected_link = ( |
| 163 |
f"https://www.python.org/ftp/python" |
| 164 |
f"/{sys.version_info.major}.{sys.version_info.minor}.{micro}" |
| 165 |
f"/python-{sys.version_info.major}.{sys.version_info.minor}.{revision}-embed-amd64.zip" |
| 166 |
) |
| 167 |
assert create_command.support_package_url(revision) == expected_link |
| 168 |
|
| 169 |
|
| 170 |
def test_default_install_scope(create_command, first_app_config, tmp_path): |
| 171 |
"""By default, the installer gives a choice between per user and per machine.""" |
| 172 |
context = create_command.output_format_template_context(first_app_config) |
| 173 |
assert context["install_scope"] == "perUserOrMachine" |
| 174 |
|
| 175 |
|
| 176 |
def test_per_machine_install_scope(create_command, first_app_config, tmp_path): |
| 177 |
"""App can be set to have explicit per-machine scope.""" |
| 178 |
first_app_config.system_installer = True |
| 179 |
context = create_command.output_format_template_context(first_app_config) |
| 180 |
assert context["install_scope"] == "perMachine" |
| 181 |
|
| 182 |
|
| 183 |
def test_per_user_install_scope(create_command, first_app_config, tmp_path): |
| 184 |
"""App can be set to have explicit per-user scope.""" |
| 185 |
first_app_config.system_installer = False |
| 186 |
context = create_command.output_format_template_context(first_app_config) |
| 187 |
assert context["install_scope"] == "perUser" |
| 188 |
|
| 189 |
|
| 190 |
def test_package_path(create_command, first_app_config, tmp_path): |
| 191 |
"""The default package_path is passed as an absolute path.""" |
| 192 |
context = create_command.output_format_template_context(first_app_config) |
| 193 |
assert context["package_path"] == str( |
| 194 |
tmp_path / "base_path/build/first-app/windows/app/src" |
| 195 |
) |
| 196 |
|
| 197 |
|
| 198 |
def test_binary_path(create_command, first_app_config, tmp_path): |
| 199 |
"""The default binary_path is passed as a path relative to package_path.""" |
| 200 |
context = create_command.output_format_template_context(first_app_config) |
| 201 |
assert context["binary_path"] == "First App.exe" |
| 202 |
|
| 203 |
|
| 204 |
def test_external(create_command, external_first_app, tmp_path): |
| 205 |
"""The package_path and binary_path can be overridden by the user.""" |
| 206 |
context = create_command.output_format_template_context(external_first_app) |
| 207 |
assert context["package_path"] == str(tmp_path / "base_path/external/src") |
| 208 |
assert context["binary_path"] == "internal/app.exe" |