Skip to content

Commit

Permalink
tests: Add tests for building a PEP660 wheel in editable mode with ex…
Browse files Browse the repository at this point in the history
…tension modules
  • Loading branch information
robbotorigami committed Aug 30, 2023
1 parent 88101f2 commit b406de0
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/masonry/builders/test_wheel.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import distutils.ccompiler
import os
import re
import shutil
Expand Down Expand Up @@ -28,13 +29,18 @@
WHEEL_TAG_REGEX = "[cp]p[23]_?\\d+-(?:cp[23]_?\\d+m?u?|pypy[23]_?\\d+_pp\\d+)-.+"


shared_lib_extension = distutils.ccompiler.new_compiler().shared_lib_extension


@pytest.fixture(autouse=True)
def setup() -> Iterator[None]:
clear_samples_dist()
clear_samples_build()

yield

clear_samples_dist()
clear_samples_build()


def clear_samples_dist() -> None:
Expand All @@ -43,6 +49,14 @@ def clear_samples_dist() -> None:
shutil.rmtree(str(dist))


def clear_samples_build() -> None:
for build in fixtures_dir.glob("**/build"):
if build.is_dir():
shutil.rmtree(str(build))
for so in fixtures_dir.glob(f"**/*{shared_lib_extension}"):
so.unlink()


def test_wheel_module() -> None:
module_path = fixtures_dir / "module1"
WheelBuilder.make(Factory().create_poetry(module_path))
Expand Down Expand Up @@ -373,3 +387,30 @@ def test_tag(in_venv_build: bool, mocker: MockerFixture) -> None:
get_sys_tags_spy.assert_not_called()
else:
get_sys_tags_spy.assert_called()


def test_extended_editable_wheel_build() -> None:
"""Tests that an editable wheel made from a project with extensions includes
the .pth, but does not include the built package itself.
"""
root = fixtures_dir / "extended"
WheelBuilder.make_in(Factory().create_poetry(root), editable=True)

whl = next((root / "dist").glob("extended-0.1-*.whl"))

assert whl.exists()
with zipfile.ZipFile(str(whl)) as z:
assert "extended.pth" in z.namelist()
# Ensure the directory "extended/" does not exist in the whl
assert all(not n.startswith("extended/") for n in z.namelist())


def test_extended_editable_build_inplace() -> None:
"""Tests that a project with extensions builds the extension modules in-place
when ran for an editable install.
"""
root = fixtures_dir / "extended"
WheelBuilder.make_in(Factory().create_poetry(root), editable=True)

so = next((root / "extended").glob(f"extended.*{shared_lib_extension}"))
assert so.exists()

0 comments on commit b406de0

Please sign in to comment.