Skip to content

Commit bbd1934

Browse files
committed
Consolidate isolate and editable_mode fixture usages
Signed-off-by: Cristian Le <git@lecris.dev>
1 parent 8948319 commit bbd1934

File tree

2 files changed

+44
-135
lines changed

2 files changed

+44
-135
lines changed

tests/test_editable.py

Lines changed: 33 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
from pathlib import Path
77

88
import pytest
9-
from conftest import PackageInfo, VEnv, process_package
9+
from conftest import PackageInfo, process_package
1010

1111

1212
@pytest.mark.compile
1313
@pytest.mark.configure
1414
@pytest.mark.integration
15-
@pytest.mark.parametrize("isolate", [True, False], ids=["isolated", "notisolated"])
1615
@pytest.mark.parametrize(
1716
"py_pkg",
1817
[
@@ -30,17 +29,12 @@
3029
sys.version_info[:2] == (3, 9), reason="Python 3.9 not supported yet"
3130
)
3231
def test_navigate_editable(isolated, isolate, py_pkg):
33-
isolate_args = ["--no-build-isolation"] if not isolate else []
34-
isolated.install("pip>=23")
35-
if not isolate:
36-
isolated.install("scikit-build-core")
37-
3832
if py_pkg:
3933
init_py = Path("python/shared_pkg/data/__init__.py")
4034
init_py.touch()
4135

4236
isolated.install(
43-
"-v", "--config-settings=build-dir=build/{wheel_tag}", *isolate_args, "-e", "."
37+
"-v", "--config-settings=build-dir=build/{wheel_tag}", *isolate.flags, "-e", "."
4438
)
4539

4640
value = isolated.execute("import shared_pkg; shared_pkg.call_c_method()")
@@ -59,17 +53,9 @@ def test_navigate_editable(isolated, isolate, py_pkg):
5953
@pytest.mark.compile
6054
@pytest.mark.configure
6155
@pytest.mark.integration
62-
@pytest.mark.parametrize(
63-
("editable", "editable_mode"), [(False, ""), (True, "redirect"), (True, "inplace")]
64-
)
65-
def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
66-
editable_flag = ["-e"] if editable else []
67-
68-
config_mode_flags = []
69-
if editable:
70-
config_mode_flags.append(f"--config-settings=editable.mode={editable_mode}")
71-
if editable_mode != "inplace":
72-
config_mode_flags.append("--config-settings=build-dir=build/{wheel_tag}")
56+
@pytest.mark.parametrize("isolate", {False}, indirect=True)
57+
def test_cython_pxd(monkeypatch, tmp_path, editable, isolated, isolate):
58+
isolated.install("cython")
7359

7460
package1 = PackageInfo(
7561
"cython_pxd_editable/pkg1",
@@ -78,21 +64,10 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
7864
tmp_path1.mkdir()
7965
process_package(package1, tmp_path1, monkeypatch)
8066

81-
ninja = [
82-
"ninja" for f in isolated.wheelhouse.iterdir() if f.name.startswith("ninja-")
83-
]
84-
cmake = [
85-
"cmake" for f in isolated.wheelhouse.iterdir() if f.name.startswith("cmake-")
86-
]
87-
88-
isolated.install("pip>23")
89-
isolated.install("cython", "scikit-build-core", *ninja, *cmake)
90-
9167
isolated.install(
9268
"-v",
93-
*config_mode_flags,
94-
"--no-build-isolation",
95-
*editable_flag,
69+
*isolate.flags,
70+
*editable.flags,
9671
".",
9772
)
9873

@@ -105,9 +80,8 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
10580

10681
isolated.install(
10782
"-v",
108-
*config_mode_flags,
109-
"--no-build-isolation",
110-
*editable_flag,
83+
*isolate.flags,
84+
*editable.flags,
11185
".",
11286
)
11387

@@ -118,9 +92,6 @@ def test_cython_pxd(monkeypatch, tmp_path, editable, editable_mode, isolated):
11892
@pytest.mark.parametrize("package", {"simplest_c"}, indirect=True)
11993
@pytest.mark.usefixtures("package")
12094
def test_install_dir(isolated):
121-
isolated.install("pip>=23")
122-
isolated.install("scikit-build-core")
123-
12495
settings_overrides = {
12596
"build-dir": "build/{wheel_tag}",
12697
"wheel.install-dir": "other_pkg",
@@ -141,7 +112,6 @@ def test_install_dir(isolated):
141112
isolated.install(
142113
"-v",
143114
*[f"--config-settings={k}={v}" for k, v in settings_overrides.items()],
144-
"--no-build-isolation",
145115
"-e",
146116
".",
147117
)
@@ -163,67 +133,25 @@ def test_install_dir(isolated):
163133
assert not failed_c_module.exists()
164134

165135

166-
def _setup_package_for_editable_layout_tests(
167-
monkeypatch: pytest.MonkeyPatch,
168-
tmp_path: Path,
169-
editable: bool,
170-
editable_mode: str,
171-
isolated: VEnv,
172-
) -> None:
173-
editable_flag = ["-e"] if editable else []
174-
175-
config_mode_flags = []
176-
if editable:
177-
config_mode_flags.append(f"--config-settings=editable.mode={editable_mode}")
178-
if editable_mode != "inplace":
179-
config_mode_flags.append("--config-settings=build-dir=build/{wheel_tag}")
180-
181-
# Use a context so that we only change into the directory up until the point where
182-
# we run the editable install. We do not want to be in that directory when importing
183-
# to avoid importing the source directory instead of the installed package.
184-
with monkeypatch.context() as m:
185-
package = PackageInfo("importlib_editable")
186-
process_package(package, tmp_path, m)
187-
188-
assert isolated.wheelhouse
189-
190-
ninja = [
191-
"ninja"
192-
for f in isolated.wheelhouse.iterdir()
193-
if f.name.startswith("ninja-")
194-
]
195-
cmake = [
196-
"cmake"
197-
for f in isolated.wheelhouse.iterdir()
198-
if f.name.startswith("cmake-")
199-
]
200-
201-
isolated.install("pip>23")
202-
isolated.install("scikit-build-core", *ninja, *cmake)
203-
204-
isolated.install(
205-
"-v",
206-
*config_mode_flags,
207-
"--no-build-isolation",
208-
*editable_flag,
209-
".",
210-
)
211-
212-
213136
@pytest.mark.compile
214137
@pytest.mark.configure
215138
@pytest.mark.integration
216-
@pytest.mark.parametrize(
217-
("editable", "editable_mode"), [(False, ""), (True, "redirect"), (True, "inplace")]
218-
)
219-
def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated):
139+
@pytest.mark.parametrize("package", {"importlib_editable"}, indirect=True)
140+
@pytest.mark.usefixtures("package")
141+
def test_direct_import(editable, isolated, monkeypatch, tmp_path):
220142
# TODO: Investigate these failures
221-
if platform.system() == "Windows" and editable_mode == "inplace":
143+
if platform.system() == "Windows" and editable.mode == "inplace":
222144
pytest.xfail("Windows fails to import the top-level extension module")
223145

224-
_setup_package_for_editable_layout_tests(
225-
monkeypatch, tmp_path, editable, editable_mode, isolated
146+
isolated.install(
147+
"-v",
148+
*editable.flags,
149+
".",
226150
)
151+
152+
# Exit the package path before execution
153+
# TODO: Use src-layout instead
154+
monkeypatch.chdir(tmp_path)
227155
isolated.execute("import pkg")
228156
isolated.execute("import pmod")
229157
isolated.execute("import emod")
@@ -232,32 +160,27 @@ def test_direct_import(monkeypatch, tmp_path, editable, editable_mode, isolated)
232160
@pytest.mark.compile
233161
@pytest.mark.configure
234162
@pytest.mark.integration
235-
@pytest.mark.parametrize(
236-
("editable", "editable_mode"),
237-
[
238-
(False, ""),
239-
pytest.param(
240-
True,
241-
"redirect",
242-
marks=pytest.mark.xfail,
243-
),
244-
(True, "inplace"),
245-
],
246-
)
247-
def test_importlib_resources(monkeypatch, tmp_path, editable, editable_mode, isolated):
163+
@pytest.mark.parametrize("package", {"importlib_editable"}, indirect=True)
164+
@pytest.mark.usefixtures("package")
165+
def test_importlib_resources(editable, isolated, monkeypatch, tmp_path):
248166
if sys.version_info < (3, 9):
249167
pytest.skip("importlib.resources.files is introduced in Python 3.9")
250168

251169
# TODO: Investigate these failures
252-
if editable_mode == "redirect":
170+
if editable.mode == "redirect":
253171
pytest.xfail("Redirect mode is at navigating importlib.resources.files")
254-
if platform.system() == "Windows" and editable_mode == "inplace":
172+
if platform.system() == "Windows" and editable.mode == "inplace":
255173
pytest.xfail("Windows fails to import the top-level extension module")
256174

257-
_setup_package_for_editable_layout_tests(
258-
monkeypatch, tmp_path, editable, editable_mode, isolated
175+
isolated.install(
176+
"-v",
177+
*editable.flags,
178+
".",
259179
)
260180

181+
# Exit the package path before execution
182+
# TODO: Use src-layout instead
183+
monkeypatch.chdir(tmp_path)
261184
isolated.execute(
262185
textwrap.dedent(
263186
"""

tests/test_pyproject_pep660.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import sys
22
import sysconfig
3-
import typing
43
import zipfile
54
from pathlib import Path
65

@@ -9,11 +8,6 @@
98
from scikit_build_core.build import build_editable
109

1110

12-
@pytest.fixture(params=["redirect", "inplace"])
13-
def editable_mode(request: pytest.FixtureRequest) -> str:
14-
return typing.cast("str", request.param)
15-
16-
1711
# TODO: figure out why gmake is reporting no rule to make simple_pure.cpp
1812
@pytest.mark.compile
1913
@pytest.mark.configure
@@ -23,10 +17,11 @@ def editable_mode(request: pytest.FixtureRequest) -> str:
2317
reason="No idea why this fails on Cygwin",
2418
)
2519
@pytest.mark.parametrize("package", {"simplest_c"}, indirect=True)
20+
@pytest.mark.parametrize("editable", ["redirect", "inplace"], indirect=True)
2621
@pytest.mark.usefixtures("package")
27-
def test_pep660_wheel(editable_mode: str, tmp_path: Path):
22+
def test_pep660_wheel(editable, tmp_path: Path):
2823
dist = tmp_path / "dist"
29-
out = build_editable(str(dist), {"editable.mode": editable_mode})
24+
out = build_editable(str(dist), {"editable.mode": editable.mode})
3025
(wheel,) = dist.glob("simplest-0.0.1-*.whl")
3126
assert wheel == dist / out
3227

@@ -36,9 +31,9 @@ def test_pep660_wheel(editable_mode: str, tmp_path: Path):
3631
with zf.open("simplest-0.0.1.dist-info/METADATA") as f:
3732
metadata = f.read().decode("utf-8")
3833

39-
assert len(file_names) == 4 if editable_mode == "redirect" else 2
34+
assert len(file_names) == 4 if editable.mode == "redirect" else 2
4035
assert "simplest-0.0.1.dist-info" in file_names
41-
if editable_mode == "redirect":
36+
if editable.mode == "redirect":
4237
assert "simplest" in file_names
4338
assert "_simplest_editable.py" in file_names
4439
else:
@@ -54,23 +49,14 @@ def test_pep660_wheel(editable_mode: str, tmp_path: Path):
5449
@pytest.mark.compile
5550
@pytest.mark.configure
5651
@pytest.mark.integration
57-
@pytest.mark.parametrize("isolate", [True, False], ids=["isolated", "not_isolated"])
5852
@pytest.mark.parametrize("package", {"simplest_c"}, indirect=True)
53+
@pytest.mark.parametrize("editable", ["redirect", "inplace"], indirect=True)
5954
@pytest.mark.usefixtures("package")
60-
def test_pep660_pip_isolated(isolated, isolate, editable_mode: str):
61-
isolate_args = ["--no-build-isolation"] if not isolate else []
62-
isolated.install("pip>=23")
63-
if not isolate:
64-
isolated.install("scikit-build-core")
65-
66-
build_dir = "" if editable_mode == "inplace" else "build/{wheel_tag}"
67-
55+
def test_pep660_pip_isolated(isolated, isolate, editable):
6856
isolated.install(
6957
"-v",
70-
f"--config-settings=build-dir={build_dir}",
71-
f"--config-settings=editable.mode={editable_mode}",
72-
*isolate_args,
73-
"-e",
58+
*isolate.flags,
59+
*editable.flags,
7460
".",
7561
)
7662

@@ -87,7 +73,7 @@ def test_pep660_pip_isolated(isolated, isolate, editable_mode: str):
8773
assert any(x.samefile(python_source) for x in locations)
8874

8975
cmake_install = isolated.platlib.joinpath("simplest").resolve()
90-
if editable_mode == "redirect":
76+
if editable.mode == "redirect":
9177
# Second path is from the CMake install
9278
assert any(x.samefile(cmake_install) for x in locations)
9379

@@ -106,7 +92,7 @@ def test_pep660_pip_isolated(isolated, isolate, editable_mode: str):
10692
else:
10793
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
10894

109-
module_source = python_source if editable_mode == "inplace" else cmake_install
95+
module_source = python_source if editable.mode == "inplace" else cmake_install
11096
module_file = module_source / f"_module{ext_suffix}"
11197

11298
# Windows FindPython may produce the wrong extension

0 commit comments

Comments
 (0)