forked from scientific-python/spin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_build_cmds.py
More file actions
197 lines (156 loc) · 5.38 KB
/
test_build_cmds.py
File metadata and controls
197 lines (156 loc) · 5.38 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
import os
import subprocess
import sys
import tempfile
from pathlib import Path
import pytest
from spin.cmds.util import run
from .testutil import (
skip_on_windows,
skip_py_lt_311,
skip_unless_linux,
skip_unless_macos,
spin,
stdout,
)
def test_basic_build(example_pkg):
"""Does the package build?"""
spin("build")
assert Path("build").exists(), "`build` folder not created after `spin build`"
assert Path(
"build-install"
).exists(), "`build-install` folder not created after `spin build`"
def test_debug_builds(example_pkg):
"""Does spin generate gcov debug output files?"""
spin("build", "--gcov")
debug_files = Path(".").rglob("*.gcno")
assert len(list(debug_files)) != 0, "debug files not generated for gcov build"
def test_build_jobs_auto(example_pkg):
"""Does `spin build -j auto` work?"""
p = spin("build", "-j", "auto")
assert b"Building with" in p.stdout
assert b"parallel jobs" in p.stdout
def test_build_jobs_invalid(example_pkg):
"""Does `spin build -j nan` fail with a clear error?"""
p = spin("build", "-j", "nan", sys_exit=False)
assert p.returncode != 0
assert b"Expected an integer or 'auto'" in p.stderr
def test_prefix_builds(example_pkg):
"""does spin build --prefix create a build-install directory with the correct structure?"""
spin("build", "--prefix=/foobar/")
assert (Path("build-install") / Path("foobar")).exists()
def test_coverage_builds(example_pkg):
"""Does gcov test generate coverage files?"""
spin("test", "--gcov")
coverage_files = Path(".").rglob("*.gcda")
assert len(list(coverage_files)) != 0, "coverage files not generated for gcov build"
@pytest.mark.parametrize(
"report_type,output_file",
[
("html", Path("coveragereport/index.html")),
("xml", Path("coverage.xml")),
("text", Path("coverage.txt")),
("sonarqube", Path("sonarqube.xml")),
],
)
def test_coverage_reports(example_pkg, report_type, output_file):
"""Does gcov test generate coverage reports?"""
spin("test", "--gcov", f"--gcov-format={report_type}")
coverage_report = Path("./build/meson-logs", output_file)
assert (
coverage_report.exists()
), f"coverage report not generated for gcov build ({report_type})"
def test_expand_pythonpath(example_pkg):
"""Does an $ENV_VAR get expanded in `spin run`?"""
output = spin("run", "echo $PYTHONPATH")
assert any(
p in stdout(output) for p in ("site-packages", "dist-packages")
), f"Expected value of $PYTHONPATH, got {stdout(output)} instead"
def test_run_stdout(example_pkg):
"""Ensure `spin run` only includes command output on stdout."""
p = spin(
"run",
sys.executable,
"-c",
"import sys; del sys.path[0]; import example_pkg; print(example_pkg.__version__)",
)
assert (
stdout(p) == "0.0.0dev0"
), f"`spin run` stdout did not yield version, but {stdout(p)}"
# Detecting whether a file is executable is not that easy on Windows,
# as it seems to take into consideration whether that file is associated as an executable.
@skip_on_windows
def test_recommend_run_python(example_pkg):
"""If `spin run file.py` is called, is `spin run python file.py` recommended?"""
with tempfile.NamedTemporaryFile(suffix=".py") as f:
p = spin("run", f.name, sys_exit=False)
assert "Did you mean to call" in stdout(
p
), "Failed to recommend `python run python file.py`"
def test_sdist(example_pkg):
spin("sdist")
def test_example(example_pkg):
spin("example")
def test_docs(example_pkg):
run(["pip", "install", "--quiet", "sphinx"])
spin("docs")
def test_spin_install(example_pkg):
cwd = os.getcwd()
spin("install")
with tempfile.TemporaryDirectory() as d:
try:
os.chdir(d)
p = run(
[
sys.executable,
"-c",
"import example_pkg; print(example_pkg.__version__)",
],
stdout=subprocess.PIPE,
)
assert stdout(p) == "0.0.0dev0"
finally:
os.chdir(cwd)
run(["pip", "uninstall", "-y", "--quiet", "example_pkg"])
@skip_unless_linux
def test_gdb(example_pkg):
p = spin(
"gdb",
"-c",
'import example_pkg; example_pkg.echo("hi")',
"--",
"--eval",
"run",
"--batch",
)
assert "hi" in stdout(p)
@skip_unless_macos
def test_lldb(example_pkg):
p = spin(
"lldb",
"-c",
'import example_pkg; example_pkg.echo("hi")',
"--",
"-o",
"run",
"--batch",
)
assert "hi" in stdout(p)
@skip_py_lt_311 # python command does not run on older pythons
def test_parallel_builds(example_pkg):
spin("build")
spin("build", "-C", "parallel/build")
p = spin("python", "--", "-c", "import example_pkg; print(example_pkg.__file__)")
example_pkg_path = stdout(p).split("\n")[-1]
p = spin(
"python",
"-C",
"parallel/build",
"--",
"-c",
"import example_pkg; print(example_pkg.__file__)",
)
example_pkg_parallel_path = stdout(p).split("\n")[-1]
assert "build-install" in example_pkg_path
assert "parallel/build-install" in example_pkg_parallel_path
assert "parallel/build-install" not in example_pkg_path