/
main_platform_test.py
265 lines (193 loc) 路 8.16 KB
/
main_platform_test.py
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
from __future__ import annotations
import sys
import pytest
from cibuildwheel.__main__ import main
from cibuildwheel.architecture import Architecture
from ..conftest import MOCK_PACKAGE_DIR
def test_unknown_platform_non_ci(monkeypatch, capsys):
monkeypatch.delenv("CI", raising=False)
monkeypatch.delenv("BITRISE_BUILD_NUMBER", raising=False)
monkeypatch.delenv("AZURE_HTTP_USER_AGENT", raising=False)
monkeypatch.delenv("TRAVIS", raising=False)
monkeypatch.delenv("APPVEYOR", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("GITLAB_CI", raising=False)
monkeypatch.delenv("CIRCLECI", raising=False)
monkeypatch.delenv("CIRRUS_CI", raising=False)
monkeypatch.delenv("CIBW_PLATFORM", raising=False)
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.code == 2
_, err = capsys.readouterr()
assert "cibuildwheel: Unable to detect platform." in err
assert "cibuildwheel should run on your CI server" in err
def test_unknown_platform_on_ci(monkeypatch, capsys):
monkeypatch.setenv("CI", "true")
monkeypatch.setattr(sys, "platform", "nonexistent")
monkeypatch.delenv("CIBW_PLATFORM", raising=False)
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.code == 2
_, err = capsys.readouterr()
assert 'cibuildwheel: Unable to detect platform from "sys.platform"' in err
def test_unknown_platform(monkeypatch, capsys):
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
with pytest.raises(SystemExit) as exit:
main()
_, err = capsys.readouterr()
assert exit.value.code == 2
assert "cibuildwheel: Unsupported platform: nonexistent" in err
def test_platform_argument(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_PLATFORM", "nonexistent")
monkeypatch.setattr(sys, "argv", sys.argv + ["--platform", platform])
main()
options = intercepted_build_args.args[0]
assert options.globals.package_dir == MOCK_PACKAGE_DIR.resolve()
def test_platform_environment(platform, intercepted_build_args, monkeypatch):
main()
options = intercepted_build_args.args[0]
assert options.globals.package_dir == MOCK_PACKAGE_DIR.resolve()
def test_archs_default(platform, intercepted_build_args, monkeypatch):
main()
options = intercepted_build_args.args[0]
if platform == "linux":
assert options.globals.architectures == {Architecture.x86_64, Architecture.i686}
elif platform == "windows":
assert options.globals.architectures == {Architecture.AMD64, Architecture.x86}
else:
assert options.globals.architectures == {Architecture.x86_64}
@pytest.mark.parametrize("use_env_var", [False, True])
def test_archs_argument(platform, intercepted_build_args, monkeypatch, use_env_var):
if use_env_var:
monkeypatch.setenv("CIBW_ARCHS", "ppc64le")
else:
monkeypatch.setenv("CIBW_ARCHS", "unused")
monkeypatch.setattr(sys, "argv", sys.argv + ["--archs", "ppc64le"])
if platform in {"macos", "windows"}:
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.args == (4,)
else:
main()
options = intercepted_build_args.args[0]
assert options.globals.architectures == {Architecture.ppc64le}
def test_archs_platform_specific(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_ARCHS", "unused")
monkeypatch.setenv("CIBW_ARCHS_LINUX", "ppc64le")
monkeypatch.setenv("CIBW_ARCHS_WINDOWS", "x86")
monkeypatch.setenv("CIBW_ARCHS_MACOS", "x86_64")
main()
options = intercepted_build_args.args[0]
if platform == "linux":
assert options.globals.architectures == {Architecture.ppc64le}
elif platform == "windows":
assert options.globals.architectures == {Architecture.x86}
elif platform == "macos":
assert options.globals.architectures == {Architecture.x86_64}
def test_archs_platform_native(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_ARCHS", "native")
main()
options = intercepted_build_args.args[0]
if platform in {"linux", "macos"}:
assert options.globals.architectures == {Architecture.x86_64}
elif platform == "windows":
assert options.globals.architectures == {Architecture.AMD64}
def test_archs_platform_auto64(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_ARCHS", "auto64")
main()
options = intercepted_build_args.args[0]
if platform in {"linux", "macos"}:
assert options.globals.architectures == {Architecture.x86_64}
elif platform == "windows":
assert options.globals.architectures == {Architecture.AMD64}
def test_archs_platform_auto32(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_ARCHS", "auto32")
if platform == "macos":
with pytest.raises(SystemExit) as exit:
main()
assert exit.value.args == (4,)
else:
main()
options = intercepted_build_args.args[0]
if platform == "linux":
assert options.globals.architectures == {Architecture.i686}
elif platform == "windows":
assert options.globals.architectures == {Architecture.x86}
def test_archs_platform_all(platform, intercepted_build_args, monkeypatch):
monkeypatch.setenv("CIBW_ARCHS", "all")
main()
options = intercepted_build_args.args[0]
if platform == "linux":
assert options.globals.architectures == {
Architecture.x86_64,
Architecture.i686,
Architecture.aarch64,
Architecture.ppc64le,
Architecture.s390x,
}
elif platform == "windows":
assert options.globals.architectures == {
Architecture.x86,
Architecture.AMD64,
Architecture.ARM64,
}
elif platform == "macos":
assert options.globals.architectures == {
Architecture.x86_64,
Architecture.arm64,
Architecture.universal2,
}
@pytest.mark.parametrize(
"only,plat",
(
("cp311-manylinux_x86_64", "linux"),
("cp310-win_amd64", "windows"),
("cp310-win32", "windows"),
("cp311-macosx_x86_64", "macos"),
),
)
def test_only_argument(intercepted_build_args, monkeypatch, only, plat):
monkeypatch.setenv("CIBW_BUILD", "unused")
monkeypatch.setenv("CIBW_SKIP", "unused")
monkeypatch.setattr(sys, "argv", sys.argv + ["--only", only])
main()
options = intercepted_build_args.args[0]
assert options.globals.build_selector.build_config == only
assert options.globals.build_selector.skip_config == ""
assert options.platform == plat
assert options.globals.architectures == Architecture.all_archs(plat)
@pytest.mark.parametrize("only", ("cp311-manylxinux_x86_64", "some_linux_thing"))
def test_only_failed(monkeypatch, only):
monkeypatch.setattr(sys, "argv", sys.argv + ["--only", only])
with pytest.raises(SystemExit):
main()
def test_only_no_platform(monkeypatch):
monkeypatch.setattr(
sys, "argv", sys.argv + ["--only", "cp311-manylinux_x86_64", "--platform", "macos"]
)
with pytest.raises(SystemExit):
main()
def test_only_no_archs(monkeypatch):
monkeypatch.setattr(
sys, "argv", sys.argv + ["--only", "cp311-manylinux_x86_64", "--archs", "x86_64"]
)
with pytest.raises(SystemExit):
main()
@pytest.mark.parametrize(
"envvar_name,envvar_value",
(
("CIBW_BUILD", "cp310-*"),
("CIBW_SKIP", "cp311-*"),
("CIBW_ARCHS", "auto32"),
("CIBW_PLATFORM", "macos"),
),
)
def test_only_overrides_env_vars(monkeypatch, intercepted_build_args, envvar_name, envvar_value):
monkeypatch.setattr(sys, "argv", sys.argv + ["--only", "cp311-manylinux_x86_64"])
monkeypatch.setenv(envvar_name, envvar_value)
main()
options = intercepted_build_args.args[0]
assert options.globals.build_selector.build_config == "cp311-manylinux_x86_64"
assert options.globals.build_selector.skip_config == ""
assert options.platform == "linux"
assert options.globals.architectures == Architecture.all_archs("linux")