forked from beeware/briefcase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_create.py
More file actions
235 lines (181 loc) · 8.08 KB
/
test_create.py
File metadata and controls
235 lines (181 loc) · 8.08 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import platform
import sys
from unittest.mock import MagicMock
import pytest
from packaging.version import Version
from briefcase.exceptions import UnsupportedHostError
from briefcase.platforms.windows.app import WindowsAppCreateCommand
@pytest.fixture
def create_command(dummy_console, tmp_path):
return WindowsAppCreateCommand(
console=dummy_console,
base_path=tmp_path / "base_path",
data_path=tmp_path / "briefcase",
)
@pytest.mark.parametrize("host_os", ["Darwin", "Linux", "WeirdOS"])
def test_unsupported_host_os(create_command, host_os):
"""Error raised for an unsupported OS."""
create_command.tools.host_os = host_os
with pytest.raises(
UnsupportedHostError,
match=r"Windows applications can only be built on Windows\.",
):
create_command()
@pytest.mark.parametrize("host_arch", ["i686", "wonky"])
def test_unsupported_arch(create_command, host_arch, first_app_config):
"""Internal apps can only be developed on x86-64 and ARM64."""
create_command.tools.host_os = "Windows"
create_command.tools.host_arch = host_arch
create_command.apps["first"] = first_app_config
with pytest.raises(
UnsupportedHostError,
match=f"Windows applications cannot be built on an {host_arch} machine.",
):
create_command.verify_host()
@pytest.mark.parametrize("host_arch", ["i686", "wonky"])
def test_unsupported_arch_external(create_command, host_arch, first_app_config, capsys):
"""External apps can be built on a different architecture, with a warning."""
create_command.tools.host_os = "Windows"
create_command.tools.host_arch = host_arch
create_command.apps["first"] = first_app_config
first_app_config.external_package_path = "external"
create_command.verify_host()
stdout, stderr = capsys.readouterr()
assert "WARNING: Possible architecture mismatch" in stdout
assert stderr == ""
# The warning is not repeated on cloned commands.
create_command.is_clone = True
create_command.verify_host()
assert capsys.readouterr() == ("", "")
def test_supported_arch(create_command):
"""Windows command are allowed to run on x86-64."""
create_command.tools.host_os = "Windows"
create_command.tools.host_arch = "AMD64"
create_command.verify_host()
def test_unsupported_32bit_python(create_command):
"""Windows commands cannot run with 32bit Python."""
create_command.tools.host_os = "Windows"
create_command.tools.host_arch = "AMD64"
create_command.tools.is_32bit_python = True
with pytest.raises(
UnsupportedHostError,
match="Windows applications cannot be built using a 32bit version of Python",
):
create_command()
def test_verify_windows_cpu_arch(create_command):
"""Running through x86_64 emulation on Windows ARM64 will raise an error."""
# Create a Mock object for the platform module
create_command.tools.platform = MagicMock(spec_set=platform)
# Simulate that Mock platform is running on Windows ARM64 with an x86_64 Python interpreter
create_command.tools.host_os = "Windows"
create_command.tools.host_arch = "ARM64"
create_command.tools.platform.python_compiler = MagicMock(
return_value="MSV v.1950 64 bit (AMD64)"
)
with pytest.raises(
UnsupportedHostError,
match=(
r"The Python interpreter that is being used to run Briefcase has been "
r"compiled for x86_64, and is running in emulation mode on ARM64 "
r"hardware. You must use a Python interpreter that has been "
r"compiled for ARM64."
),
):
create_command.verify_host()
def test_context(create_command, first_app_config):
context = create_command.output_format_template_context(first_app_config)
assert sorted(context.keys()) == [
"binary_path",
"guid",
"install_scope",
"package_path",
"version_triple",
]
@pytest.mark.parametrize(
("version", "version_triple"),
[
("1", "1.0.0"),
("1.2", "1.2.0"),
("1.2.3", "1.2.3"),
("1.2.3.4", "1.2.3"),
("1.2.3a4", "1.2.3"),
("1.2.3b5", "1.2.3"),
("1.2.3rc6", "1.2.3"),
("1.2.3.dev7", "1.2.3"),
("1.2.3.post8", "1.2.3"),
],
)
def test_version_triple(
create_command, first_app_config, tmp_path, version, version_triple
):
first_app_config.version = Version(version)
context = create_command.output_format_template_context(first_app_config)
assert context["version_triple"] == version_triple
def test_explicit_version_triple(create_command, first_app_config, tmp_path):
first_app_config.version = "1.2.3a1"
first_app_config.version_triple = "2.3.4"
context = create_command.output_format_template_context(first_app_config)
# Explicit version triple is used.
assert context["version_triple"] == "2.3.4"
def test_guid(create_command, first_app_config, tmp_path):
"""A predictable GUID will be generated from the bundle."""
context = create_command.output_format_template_context(first_app_config)
assert context["guid"] == "d666a4f1-c7b7-52cc-888a-3a35a7cc97e5"
def test_explicit_guid(create_command, first_app_config, tmp_path):
"""If a GUID is explicitly provided, it is used."""
first_app_config.guid = "e822176f-b755-589f-849c-6c6600f7efb1"
context = create_command.output_format_template_context(first_app_config)
# Explicitly provided GUID is used.
assert context["guid"] == "e822176f-b755-589f-849c-6c6600f7efb1"
@pytest.mark.parametrize(
("revision", "micro"),
[
# Numerical revision
(5, "5"),
# Text revision
("5", "5"),
# Pre-release revision
("0a3", "0"),
("0b2", "0"),
("0rc1", "0"),
],
)
def test_support_package_url(
create_command, revision, micro, first_app_config, tmp_path
):
"""A valid support package URL is created for a support revision."""
expected_link = (
f"https://www.python.org/ftp/python"
f"/{sys.version_info.major}.{sys.version_info.minor}.{micro}"
f"/python-{sys.version_info.major}.{sys.version_info.minor}.{revision}-embed-{create_command.tools.host_arch.lower()}.zip"
)
assert create_command.support_package_url(revision) == expected_link
def test_default_install_scope(create_command, first_app_config, tmp_path):
"""By default, the installer gives a choice between per user and per machine."""
context = create_command.output_format_template_context(first_app_config)
assert context["install_scope"] == "perUserOrMachine"
def test_per_machine_install_scope(create_command, first_app_config, tmp_path):
"""App can be set to have explicit per-machine scope."""
first_app_config.system_installer = True
context = create_command.output_format_template_context(first_app_config)
assert context["install_scope"] == "perMachine"
def test_per_user_install_scope(create_command, first_app_config, tmp_path):
"""App can be set to have explicit per-user scope."""
first_app_config.system_installer = False
context = create_command.output_format_template_context(first_app_config)
assert context["install_scope"] == "perUser"
def test_package_path(create_command, first_app_config, tmp_path):
"""The default package_path is passed as an absolute path."""
context = create_command.output_format_template_context(first_app_config)
assert context["package_path"] == str(
tmp_path / "base_path/build/first-app/windows/app/src"
)
def test_binary_path(create_command, first_app_config, tmp_path):
"""The default binary_path is passed as a path relative to package_path."""
context = create_command.output_format_template_context(first_app_config)
assert context["binary_path"] == "First App.exe"
def test_external(create_command, external_first_app, tmp_path):
"""The package_path and binary_path can be overridden by the user."""
context = create_command.output_format_template_context(external_first_app)
assert context["package_path"] == str(tmp_path / "base_path/external/src")
assert context["binary_path"] == "internal/app.exe"