Skip to content

Commit 855e26b

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

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: 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")

Diff for: 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:

Diff for: tests/extra_python_package/test_files.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,24 @@ 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)
@@ -274,8 +287,21 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
274287

275288
with zipfile.ZipFile(str(wheel)) as z:
276289
names = z.namelist()
290+
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
291+
292+
share = zipfile.Path(z, f"{beginning}.data/data/share")
293+
pkgconfig = (share / "pkgconfig/pybind11.pc").read_text(encoding="utf-8")
294+
cmakeconfig = (share / "cmake/pybind11/pybind11Config.cmake").read_text(
295+
encoding="utf-8"
296+
)
277297

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

281300
assert files == trimmed
301+
302+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmakeconfig
303+
304+
version = wheel.basename.split("-")[1]
305+
simple_version = ".".join(version.split(".")[:3])
306+
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version)
307+
assert pkgconfig_expected == pkgconfig

0 commit comments

Comments
 (0)