Skip to content

Commit

Permalink
Change test to import the C module
Browse files Browse the repository at this point in the history
Also check that CMake is indeed re-run

Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Aug 20, 2024
1 parent 3a178f9 commit ff924db
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/test_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,20 @@ def test_install_dir(isolated):

settings_overrides = {
"build-dir": "build/{wheel_tag}",
"wheel.install-dir": "sub_pkg",
"wheel.install-dir": "other_pkg",
"editable.rebuild": "true",
}
# Create a dummy _module to satisfy the import
Path("./src/simplest/_module.py").write_text(
# Create a dummy other_pkg package to satisfy the import
other_pkg_src = Path("./src/other_pkg")
other_pkg_src.joinpath("simplest").mkdir(parents=True)
other_pkg_src.joinpath("__init__.py").write_text(
textwrap.dedent(
"""
def square(__x: float, __y: float) -> float:
pass
from .simplest._module import square
"""
)
)
other_pkg_src.joinpath("simplest/__init__.py").touch()

isolated.install(
"-v",
Expand All @@ -140,16 +142,17 @@ def square(__x: float, __y: float) -> float:
)

# Make sure the package is correctly installed in the subdirectory
sub_pkg_path = isolated.platlib / "sub_pkg"
c_module_glob = list(sub_pkg_path.glob("simplest/_module*"))
other_pkg_path = isolated.platlib / "other_pkg"
c_module_glob = list(other_pkg_path.glob("simplest/_module*"))
assert len(c_module_glob) == 1
c_module = c_module_glob[0]
assert c_module.exists()
# If `install-dir` was not taken into account it would install here
failed_c_module = sub_pkg_path / "../simplest" / c_module.name
failed_c_module = other_pkg_path / "../simplest" / c_module.name
assert not failed_c_module.exists()

# Run an import in order to re-trigger the rebuild and check paths again
isolated.execute("import simplest")
out = isolated.execute("import other_pkg.simplest")
assert "Running cmake" in out
assert c_module.exists()
assert not failed_c_module.exists()

0 comments on commit ff924db

Please sign in to comment.