-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathtest_tagopt.py
221 lines (183 loc) · 6.81 KB
/
test_tagopt.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
"""
Tests for the bdist_wheel tag options (--python-tag, --universal, and
--plat-name)
"""
from __future__ import annotations
import subprocess
import sys
import pytest
SETUP_PY = """\
from setuptools import setup, Extension
setup(
name="Test",
version="1.0",
author_email="[email protected]",
py_modules=["test"],
{ext_modules}
)
"""
EXT_MODULES = "ext_modules=[Extension('_test', sources=['test.c'])],"
@pytest.fixture
def temp_pkg(request, tmp_path):
tmp_path.joinpath("test.py").write_text('print("Hello, world")', encoding="utf-8")
ext = getattr(request, "param", [False, ""])
if ext[0]:
# if ext[1] is not '', it will write a bad header and fail to compile
tmp_path.joinpath("test.c").write_text(
f"#include <std{ext[1]}io.h>", encoding="utf-8"
)
setup_py = SETUP_PY.format(ext_modules=EXT_MODULES)
else:
setup_py = SETUP_PY.format(ext_modules="")
tmp_path.joinpath("setup.py").write_text(setup_py, encoding="utf-8")
if ext[0]:
try:
subprocess.check_call(
[sys.executable, "setup.py", "build_ext"], cwd=str(tmp_path)
)
except subprocess.CalledProcessError:
pytest.skip("Cannot compile C extensions")
return tmp_path
@pytest.mark.parametrize("temp_pkg", [[True, "xxx"]], indirect=["temp_pkg"])
def test_nocompile_skips(temp_pkg):
assert False # noqa: B011 - should have skipped with a "Cannot compile" message
def test_default_tag(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name == f"Test-1.0-py{sys.version_info[0]}-none-any.whl"
assert wheels[0].suffix == ".whl"
def test_build_number(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--build-number=1"],
cwd=str(temp_pkg),
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name == f"Test-1.0-1-py{sys.version_info[0]}-none-any.whl"
assert wheels[0].suffix == ".whl"
def test_explicit_tag(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--python-tag=py32"],
cwd=str(temp_pkg),
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py32-")
assert wheels[0].suffix == ".whl"
def test_universal_tag(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--universal"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py2.py3-")
assert wheels[0].suffix == ".whl"
def test_universal_beats_explicit_tag(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--universal", "--python-tag=py32"],
cwd=str(temp_pkg),
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py2.py3-")
assert wheels[0].suffix == ".whl"
def test_universal_in_setup_cfg(temp_pkg):
temp_pkg.joinpath("setup.cfg").write_text(
"[bdist_wheel]\nuniversal=1", encoding="utf-8"
)
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py2.py3-")
assert wheels[0].suffix == ".whl"
def test_pythontag_in_setup_cfg(temp_pkg):
temp_pkg.joinpath("setup.cfg").write_text(
"[bdist_wheel]\npython_tag=py32", encoding="utf-8"
)
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py32-")
assert wheels[0].suffix == ".whl"
def test_legacy_wheel_section_in_setup_cfg(temp_pkg):
temp_pkg.joinpath("setup.cfg").write_text("[wheel]\nuniversal=1", encoding="utf-8")
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.startswith("Test-1.0-py2.py3-")
assert wheels[0].suffix == ".whl"
def test_plat_name_purepy(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--plat-name=testplat.pure"],
cwd=str(temp_pkg),
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.endswith("-testplat_pure.whl")
assert wheels[0].suffix == ".whl"
@pytest.mark.parametrize("temp_pkg", [[True, ""]], indirect=["temp_pkg"])
def test_plat_name_ext(temp_pkg):
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel", "--plat-name=testplat.arch"],
cwd=str(temp_pkg),
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.endswith("-testplat_arch.whl")
assert wheels[0].suffix == ".whl"
def test_plat_name_purepy_in_setupcfg(temp_pkg):
temp_pkg.joinpath("setup.cfg").write_text(
"[bdist_wheel]\nplat_name=testplat.pure", encoding="utf-8"
)
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.endswith("-testplat_pure.whl")
assert wheels[0].suffix == ".whl"
@pytest.mark.parametrize("temp_pkg", [[True, ""]], indirect=["temp_pkg"])
def test_plat_name_ext_in_setupcfg(temp_pkg):
temp_pkg.joinpath("setup.cfg").write_text(
"[bdist_wheel]\nplat_name=testplat.arch", encoding="utf-8"
)
subprocess.check_call(
[sys.executable, "setup.py", "bdist_wheel"], cwd=str(temp_pkg)
)
dist_dir = temp_pkg.joinpath("dist")
assert dist_dir.is_dir()
wheels = list(dist_dir.iterdir())
assert len(wheels) == 1
assert wheels[0].name.endswith("-testplat_arch.whl")
assert wheels[0].suffix == ".whl"