Skip to content

Commit 08a874a

Browse files
committed
tests: add tests for output
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 098e77b commit 08a874a

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
@@ -327,6 +327,8 @@ if(PYBIND11_INSTALL)
327327
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
328328
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
329329

330+
# When building a wheel, include __init__.py's for modules
331+
# (see https://github.com/pybind/pybind11/pull/5552)
330332
if(DEFINED SKBUILD_PROJECT_NAME AND SKBUILD_PROJECT_NAME STREQUAL "pybind11")
331333
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/empty")
332334
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
@@ -230,11 +230,24 @@ def tests_build_wheel(monkeypatch, tmpdir):
230230

231231
with zipfile.ZipFile(str(wheel)) as z:
232232
names = z.namelist()
233+
share = zipfile.Path(z, "pybind11/share")
234+
pkgconfig = (share / "pkgconfig/pybind11.pc").read_text(encoding="utf-8")
235+
cmakeconfig = (share / "cmake/pybind11/pybind11Config.cmake").read_text(
236+
encoding="utf-8"
237+
)
233238

234239
trimmed = {n for n in names if "dist-info" not in n}
235240
trimmed |= {f"dist-info/{n.split('/', 1)[-1]}" for n in names if "dist-info" in n}
241+
236242
assert files == trimmed
237243

244+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmakeconfig
245+
246+
version = wheel.basename.split("-")[1]
247+
simple_version = ".".join(version.split(".")[:3])
248+
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version)
249+
assert pkgconfig_expected == pkgconfig
250+
238251

239252
def tests_build_global_wheel(monkeypatch, tmpdir):
240253
monkeypatch.chdir(MAIN_DIR)
@@ -258,8 +271,21 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
258271

259272
with zipfile.ZipFile(str(wheel)) as z:
260273
names = z.namelist()
274+
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
275+
276+
share = zipfile.Path(z, f"{beginning}.data/data/share")
277+
pkgconfig = (share / "pkgconfig/pybind11.pc").read_text(encoding="utf-8")
278+
cmakeconfig = (share / "cmake/pybind11/pybind11Config.cmake").read_text(
279+
encoding="utf-8"
280+
)
261281

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

265284
assert files == trimmed
285+
286+
assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in cmakeconfig
287+
288+
version = wheel.basename.split("-")[1]
289+
simple_version = ".".join(version.split(".")[:3])
290+
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version)
291+
assert pkgconfig_expected == pkgconfig

0 commit comments

Comments
 (0)