Skip to content

Commit d9d3774

Browse files
committed
tests: add tests for output
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 433715a commit d9d3774

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ if(PYBIND11_INSTALL)
324324
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
325325
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
326326

327+
# When building a wheel, include __init__.py's for modules
328+
# (see https://github.com/pybind/pybind11/pull/5552)
327329
if(DEFINED SKBUILD_PROJECT_NAME AND SKBUILD_PROJECT_NAME STREQUAL "pybind11")
328330
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/empty")
329331
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py")

noxfile.py

+3
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def build(session: nox.Session) -> None:
116116

117117
@contextlib.contextmanager
118118
def preserve_file(filename: Path) -> Generator[str, None, None]:
119+
"""
120+
Causes a file to be stored and preserved when the context manager exits.
121+
"""
119122
old_stat = filename.stat()
120123
old_file = filename.read_text(encoding="utf-8")
121124
try:

tests/extra_python_package/test_files.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,38 @@ def tests_build_wheel(monkeypatch, tmpdir):
246246

247247
with zipfile.ZipFile(str(wheel)) as z:
248248
names = z.namelist()
249+
share = zipfile.Path(z, "pybind11/share")
250+
pkgconfig = (share / "pkgconfig/pybind11.pc").read_text(encoding="utf-8")
251+
cmakeconfig = (share / "cmake/pybind11/pybind11Config.cmake").read_text(
252+
encoding="utf-8"
253+
)
249254

250255
trimmed = {n for n in names if "dist-info" not in n}
251256
trimmed |= {f"dist-info/{n.split('/', 1)[-1]}" for n in names if "dist-info" in n}
257+
252258
assert files == trimmed
253259

260+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmakeconfig
261+
262+
version = wheel.basename.split("-")[1]
263+
simple_version = ".".join(version.split(".")[:3])
264+
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version)
265+
assert pkgconfig_expected == pkgconfig
266+
254267

255268
def tests_build_global_wheel(monkeypatch, tmpdir):
256269
monkeypatch.chdir(MAIN_DIR)
257270
with build_global():
258271
subprocess.run(
259-
[sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir), *UV_ARGS],
272+
[
273+
sys.executable,
274+
"-m",
275+
"build",
276+
"--wheel",
277+
"--outdir",
278+
str(tmpdir),
279+
*UV_ARGS,
280+
],
260281
check=True,
261282
)
262283

@@ -274,8 +295,21 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
274295

275296
with zipfile.ZipFile(str(wheel)) as z:
276297
names = z.namelist()
298+
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
299+
300+
share = zipfile.Path(z, f"{beginning}.data/data/share")
301+
pkgconfig = (share / "pkgconfig/pybind11.pc").read_text(encoding="utf-8")
302+
cmakeconfig = (share / "cmake/pybind11/pybind11Config.cmake").read_text(
303+
encoding="utf-8"
304+
)
277305

278-
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
279306
trimmed = {n[len(beginning) + 1 :] for n in names}
280307

281308
assert files == trimmed
309+
310+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmakeconfig
311+
312+
version = wheel.basename.split("-")[1]
313+
simple_version = ".".join(version.split(".")[:3])
314+
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version)
315+
assert pkgconfig_expected == pkgconfig

0 commit comments

Comments
 (0)