forked from tox-dev/tox
/
test_package_builder_isolated.py
204 lines (173 loc) · 5.59 KB
/
test_package_builder_isolated.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
import os
import subprocess
import py
import pytest
import tox.helper
from tox.package.builder.isolated import get_build_info
from tox.reporter import _INSTANCE
def test_verbose_isolated_build(initproj, mock_venv, cmd):
initproj(
"example123-0.5",
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
"pyproject.toml": """
[build-system]
requires = ["setuptools >= 35.0.2"]
build-backend = 'setuptools.build_meta'
""",
},
)
result = cmd("--sdistonly", "-v", "-v", "-v", "-e", "py")
assert "running sdist" in result.out, result.out
assert "running egg_info" in result.out, result.out
assert "Writing example123-0.5{}setup.cfg".format(os.sep) in result.out, result.out
def test_dist_exists_version_change(mock_venv, initproj, cmd):
base = initproj(
"package_toml-{}".format("0.1"),
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
"pyproject.toml": """
[build-system]
requires = ["setuptools >= 35.0.2"]
build-backend = 'setuptools.build_meta'
""",
},
)
result = cmd("-e", "py")
result.assert_success()
new_code = base.join("setup.py").read_text("utf-8").replace("0.1", "0.2")
base.join("setup.py").write_text(new_code, "utf-8")
result = cmd("-e", "py")
result.assert_success()
def test_package_isolated_no_pyproject_toml(initproj, cmd):
initproj(
"package_no_toml-0.1",
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
},
)
result = cmd("--sdistonly", "-e", "py")
result.assert_fail()
assert result.outlines == ["ERROR: missing {}".format(py.path.local().join("pyproject.toml"))]
def toml_file_check(initproj, version, message, toml):
initproj(
"package_toml-{}".format(version),
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
"pyproject.toml": toml,
},
)
with pytest.raises(SystemExit, match="1"):
get_build_info(py.path.local())
toml_file = py.path.local().join("pyproject.toml")
msg = "ERROR: {} inside {}".format(message, toml_file)
assert _INSTANCE.messages == [msg]
def test_package_isolated_toml_no_build_system(initproj):
toml_file_check(initproj, 1, "build-system section missing", "")
def test_package_isolated_toml_no_requires(initproj):
toml_file_check(
initproj,
2,
"missing requires key at build-system section",
"""
[build-system]
""",
)
def test_package_isolated_toml_no_backend(initproj):
toml_file_check(
initproj,
3,
"missing build-backend key at build-system section",
"""
[build-system]
requires = []
""",
)
def test_package_isolated_toml_bad_requires(initproj):
toml_file_check(
initproj,
4,
"requires key at build-system section must be a list of string",
"""
[build-system]
requires = ""
build-backend = ""
""",
)
def test_package_isolated_toml_bad_backend(initproj):
toml_file_check(
initproj,
5,
"build-backend key at build-system section must be a string",
"""
[build-system]
requires = []
build-backend = []
""",
)
def test_package_isolated_toml_bad_backend_path(initproj):
"""Verify that a non-list 'backend-path' is forbidden."""
toml_file_check(
initproj,
6,
"backend-path key at build-system section must be a list, if specified",
"""
[build-system]
requires = []
build-backend = 'setuptools.build_meta'
backend-path = 42
""",
)
def test_package_isolated_toml_backend_path_outside_root(initproj):
"""Verify that a 'backend-path' outside the project root is forbidden."""
toml_file_check(
initproj,
6,
"backend-path must exist in the project root",
"""
[build-system]
requires = []
build-backend = 'setuptools.build_meta'
backend-path = ['..']
""",
)
def test_verbose_isolated_build_in_tree(initproj, mock_venv, cmd):
initproj(
"example123-0.5",
filedefs={
"tox.ini": """
[tox]
isolated_build = true
""",
"build.py": """
from setuptools.build_meta import *
""",
"pyproject.toml": """
[build-system]
requires = ["setuptools >= 35.0.2"]
build-backend = 'build'
backend-path = ['.']
""",
},
)
result = cmd("--sdistonly", "-v", "-v", "-v", "-e", "py")
assert "running sdist" in result.out, result.out
assert "running egg_info" in result.out, result.out
assert "Writing example123-0.5{}setup.cfg".format(os.sep) in result.out, result.out
def test_isolated_build_script_args(tmp_path):
"""Verify that build_isolated.py can be called with only 2 argurments."""
# cannot import build_isolated because of its side effects
script_path = os.path.join(os.path.dirname(tox.helper.__file__), "build_isolated.py")
subprocess.check_call(("python", script_path, str(tmp_path), "setuptools.build_meta"))