Repository: scikit-build/scikit-build-core
Pull request #785 (2024-06-28 05:23:14)

tests: use zipfile
A better fit in general, and doesn't require Python 3.8.


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/785?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 81.94%. Comparing base [(`83afeb2`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/83afeb2cad1f9f0168d92df6b9b0f9d43abd53a4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build) to head [(`5a3ad8a`)](https://app.codecov.io/gh/scikit-build/scikit-build-core/commit/5a3ad8a37fd39bf08b126a6e1637a7a6d8602030?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).
> Report is 1 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #785      +/-   ##
==========================================
- Coverage   81.99%   81.94%   -0.06%     
==========================================
  Files          68       68              
  Lines        3933     3933              
==========================================
- Hits         3225     3223       -2     
- Misses        708      710       +2     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/scikit-build/scikit-build-core/pull/785?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=scikit-build).


Patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8cc0450..0c8c624 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -38,7 +38,7 @@ jobs:
 
   checks:
     name:
-      Check 🐍 ${{ matrix.python-version }} • CMake ${{ matrix.cmake-version }}
+      🐍 ${{ matrix.python-version }} • CMake ${{ matrix.cmake-version }}
       on ${{ matrix.runs-on }}
     runs-on: ${{ matrix.runs-on }}
     timeout-minutes: 40
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index a201aca..a7616ad 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -19,7 +19,7 @@ repos:
       - id: mixed-line-ending
       - id: name-tests-test
         args: ["--pytest-test-first"]
-        exclude: "^tests/packages/"
+        exclude: "^tests/packages/|^tests/utils"
       - id: requirements-txt-fixer
       - id: trailing-whitespace
         exclude: "^tests"
diff --git a/docs/getting_started.md b/docs/getting_started.md
index c56187e..d14814c 100644
--- a/docs/getting_started.md
+++ b/docs/getting_started.md
@@ -381,9 +381,8 @@ your `pyproject.toml`. You should specify exactly what language you use to keep
 CMake from searching for both `C` and `CXX` compilers (the default).
 
 You'll need to handle the generation of files by NumPy directly at the moment.
-A helper (similar to scikti-build classic) might be added in the future. On
-macOS, you may need to set the Fortran compiler and C compiler to different
-toolchains with `CC=clang FC=gfortran`.
+A helper (similar to scikti-build classic) might be added in the future. You'll
+need gfortran on macOS.
 
 ````
 
diff --git a/pyproject.toml b/pyproject.toml
index bf12d06..0fadfa4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -125,7 +125,7 @@ build.hooks.vcs.version-file = "src/scikit_build_core/_version.py"
 
 [tool.pytest.ini_options]
 minversion = "7.0"
-addopts = ["-ra", "--strict-markers", "--strict-config"]
+addopts = ["-rfEsX", "--strict-markers", "--strict-config"]
 xfail_strict = true
 filterwarnings = [
     "error",
@@ -137,6 +137,7 @@ filterwarnings = [
     "default:check_home argument is deprecated and ignored.:DeprecationWarning",  # Caused by setuptools sometimes
 ]
 log_cli_level = "info"
+pythonpath = ["tests/utils"]
 testpaths = ["tests"]
 markers = [
     "broken_on_urct: Broken for now due to lib not found",
@@ -154,7 +155,7 @@ norecursedirs = ["tests/packages/**"]
 
 [tool.mypy]
 files = ["src", "tests", "noxfile.py"]
-mypy_path = ["$MYPY_CONFIG_FILE_DIR/src"]
+mypy_path = ["$MYPY_CONFIG_FILE_DIR/src", "$MYPY_CONFIG_FILE_DIR/tests/utils"]
 python_version = "3.8"
 warn_unused_configs = true
 enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
@@ -264,6 +265,9 @@ ignore = [
 ]
 typing-modules = ["scikit_build_core._compat.typing"]
 
+[tool.ruff.lint.isort]
+known-local-folder = ["pathutils"]
+
 [tool.ruff.lint.flake8-tidy-imports.banned-api]
 "typing.Callable".msg = "Use collections.abc.Callable instead."
 "typing.Iterator".msg = "Use collections.abc.Iterator instead."


Test patch:
diff --git a/tests/test_dynamic_metadata.py b/tests/test_dynamic_metadata.py
index 39f1984..e23c26a 100644
--- a/tests/test_dynamic_metadata.py
+++ b/tests/test_dynamic_metadata.py
@@ -20,6 +20,8 @@ from scikit_build_core.builder.get_requires import GetRequires
 from scikit_build_core.metadata import regex
 from scikit_build_core.settings.skbuild_read_settings import SettingsReader
 
+from pathutils import contained
+
 
 # these are mock plugins returning known results
 # it turns out to be easier to create EntryPoint objects pointing to real
@@ -242,18 +244,15 @@ def test_pep517_wheel(virtualenv):
         )
         assert license == "MIT License"
 
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = {x.name for x in p.iterdir()}
-            dynamic_pkg = {x.name for x in p.joinpath("dynamic").iterdir()}
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(n) for n in zf.namelist()}
 
-        filtered_pkg = {x for x in dynamic_pkg if not x.startswith("_module")}
+    dynamic_pkg = {x.name for x in contained(file_paths, "dynamic")}
+    filtered_pkg = {x for x in dynamic_pkg if not x.startswith("_module")}
 
-        assert len(filtered_pkg) == len(dynamic_pkg) - 1
-        assert {"dynamic-0.0.2.dist-info", "dynamic"} == file_names
-        assert {
-            "__init__.py",
-        } == filtered_pkg
+    assert len(filtered_pkg) == len(dynamic_pkg) - 1
+    assert {"dynamic-0.0.2.dist-info", "dynamic"} == {p.parts[0] for p in file_paths}
+    assert {"__init__.py"} == filtered_pkg
 
     version = virtualenv.execute("from dynamic import square; print(square(2))")
     assert version == "4.0"
diff --git a/tests/test_fortran.py b/tests/test_fortran.py
index 544685b..21de6dd 100644
--- a/tests/test_fortran.py
+++ b/tests/test_fortran.py
@@ -1,5 +1,4 @@
 import shutil
-import sys
 import sysconfig
 import zipfile
 from pathlib import Path
@@ -48,20 +47,17 @@ def test_pep517_wheel(tmp_path, monkeypatch, virtualenv):
     out = build_wheel(str(dist))
     (wheel,) = dist.glob("fibby-0.0.1-*.whl")
     assert wheel == dist / out
-    print(wheel)
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 2
-        assert "fibby-0.0.1.dist-info" in file_names
-        file_names.remove("fibby-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "fibby-0.0.1.dist-info" in file_names
+    file_names.remove("fibby-0.0.1.dist-info")
+    (so_file,) = file_names
 
-        assert so_file.startswith("fibby")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("fibby")
+    print("SOFILE:", so_file)
 
     virtualenv.install(wheel)
 
diff --git a/tests/test_pyproject_abi3.py b/tests/test_pyproject_abi3.py
index 260f2fc..92339e0 100644
--- a/tests/test_pyproject_abi3.py
+++ b/tests/test_pyproject_abi3.py
@@ -40,30 +40,28 @@ def test_abi3_wheel(tmp_path, monkeypatch, virtualenv):
     else:
         assert "-cp37-abi3-" not in out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 2
-        assert "abi3_example-0.0.1.dist-info" in file_names
-        file_names.remove("abi3_example-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "abi3_example-0.0.1.dist-info" in file_names
+    file_names.remove("abi3_example-0.0.1.dist-info")
+    (so_file,) = file_names
 
-        if sysconfig.get_platform().startswith("win"):
-            if sys.implementation.name == "cpython":
-                assert so_file == "abi3_example.pyd"
-            else:
-                assert so_file.endswith(".pyd")
-        elif sys.platform.startswith("cygwin"):
-            if abi3:
-                assert so_file == "abi3_example.abi3.dll"
-            else:
-                assert so_file != "abi3_example.abi3.dll"
-        elif abi3:
-            assert so_file == "abi3_example.abi3.so"
+    if sysconfig.get_platform().startswith("win"):
+        if sys.implementation.name == "cpython":
+            assert so_file == "abi3_example.pyd"
         else:
-            assert so_file != "abi3_example.abi3.so"
+            assert so_file.endswith(".pyd")
+    elif sys.platform.startswith("cygwin"):
+        if abi3:
+            assert so_file == "abi3_example.abi3.dll"
+        else:
+            assert so_file != "abi3_example.abi3.dll"
+    elif abi3:
+        assert so_file == "abi3_example.abi3.so"
+    else:
+        assert so_file != "abi3_example.abi3.so"
 
     virtualenv.install(wheel)
 
diff --git a/tests/test_pyproject_extra_dirs.py b/tests/test_pyproject_extra_dirs.py
index b91ea22..f9a6f55 100644
--- a/tests/test_pyproject_extra_dirs.py
+++ b/tests/test_pyproject_extra_dirs.py
@@ -1,4 +1,3 @@
-import sys
 import zipfile
 from pathlib import Path
 
@@ -7,13 +6,11 @@ import pytest
 from scikit_build_core.build import build_wheel
 from scikit_build_core.errors import CMakeConfigError
 
+from pathutils import contained
+
 
 @pytest.mark.compile()
 @pytest.mark.configure()
-@pytest.mark.skipif(
-    sys.version_info < (3, 8),
-    reason="Python 3.7 doesn't have a nice Path zipfile interface",
-)
 @pytest.mark.usefixtures("package_filepath_pure")
 def test_pep517_wheel_extra_dirs(monkeypatch):
     monkeypatch.setenv("SKBUILD_CMAKE_DEFINE", "SOME_DEFINE3=baz;SOME_DEFINE4=baz")
@@ -27,33 +24,30 @@ def test_pep517_wheel_extra_dirs(monkeypatch):
     (wheel,) = dist.glob("cmake_dirs-0.0.1-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = {p.name for p in p.iterdir()}
-            data_dir = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data").iterdir()}
-            package = {p.name for p in p.joinpath("cmake_dirs").iterdir()}
-            data = {p.name for p in p.joinpath("cmake_dirs-0.0.1.data/data").iterdir()}
-            headers = {
-                p.name for p in p.joinpath("cmake_dirs-0.0.1.data/headers").iterdir()
-            }
-            scripts = {
-                p.name for p in p.joinpath("cmake_dirs-0.0.1.data/scripts").iterdir()
-            }
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(n) for n in zf.namelist()}
+    data_paths = set(contained(file_paths, "cmake_dirs-0.0.1.data"))
+
+    file_names = {p.parts[0] for p in file_paths}
+    data_dir = {p.parts[0] for p in data_paths}
+    package = {p.name for p in contained(file_paths, "cmake_dirs")}
+    data = {p.name for p in contained(data_paths, "data")}
+    headers = {p.name for p in contained(data_paths, "headers")}
+    scripts = {p.name for p in contained(data_paths, "scripts")}
 
-        assert {
-            "cmake_dirs-0.0.1.dist-info",
-            "cmake_dirs-0.0.1.data",
-            "cmake_dirs",
-            "random_file.py",
-        } == file_names
+    assert {
+        "cmake_dirs-0.0.1.dist-info",
+        "cmake_dirs-0.0.1.data",
+        "cmake_dirs",
+        "random_file.py",
+    } == file_names
 
-        assert data_dir == {"data", "headers", "scripts"}
+    assert data_dir == {"data", "headers", "scripts"}
 
-        assert package == {"main.py"}
-        assert data == {"in_data.txt"}
-        assert headers == {"in_headers.h"}
-        assert scripts == {"in_scripts.py"}
+    assert package == {"main.py"}
+    assert data == {"in_data.txt"}
+    assert headers == {"in_headers.h"}
+    assert scripts == {"in_scripts.py"}
 
 
 @pytest.mark.usefixtures("package_filepath_pure")
diff --git a/tests/test_pyproject_pep517.py b/tests/test_pyproject_pep517.py
index 7cb3729..5714bb8 100644
--- a/tests/test_pyproject_pep517.py
+++ b/tests/test_pyproject_pep517.py
@@ -198,31 +198,33 @@ def test_pep517_wheel(virtualenv):
     (wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
-            metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
-            entry_points = p.joinpath(
-                "cmake_example-0.0.1.dist-info/entry_points.txt"
-            ).read_text()
-            assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
-
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
-
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
-
-        print(entry_points == ENTRYPOINTS)
-        assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
-        assert "Metadata-Version: 2.1" in metadata
-        assert "Name: CMake.Example" in metadata
-        assert "Version: 0.0.1" in metadata
-        assert "Requires-Python: >=3.7" in metadata
-        assert "Provides-Extra: test" in metadata
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(p) for p in zf.namelist()}
+        file_names = {p.parts[0] for p in file_paths}
+
+        with zf.open("cmake_example-0.0.1.dist-info/METADATA") as f:
+            metadata = f.read().decode("utf-8")
+
+        with zf.open("cmake_example-0.0.1.dist-info/entry_points.txt") as f:
+            entry_points = f.read().decode("utf-8")
+
+    assert Path("cmake_example-0.0.1.dist-info/licenses/LICENSE") in file_paths
+
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
+
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
+
+    print(entry_points == ENTRYPOINTS)
+    assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
+    assert "Metadata-Version: 2.1" in metadata
+    assert "Name: CMake.Example" in metadata
+    assert "Version: 0.0.1" in metadata
+    assert "Requires-Python: >=3.7" in metadata
+    assert "Provides-Extra: test" in metadata
 
     virtualenv.install(wheel)
 
@@ -246,39 +248,41 @@ def test_pep517_wheel_source_dir(virtualenv):
     (wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
-            metadata = p.joinpath("cmake_example-0.0.1.dist-info/METADATA").read_text()
-            wheel_metadata = p.joinpath(
-                "cmake_example-0.0.1.dist-info/WHEEL"
-            ).read_text()
-            entry_points = p.joinpath(
-                "cmake_example-0.0.1.dist-info/entry_points.txt"
-            ).read_text()
-            assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
-
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
-
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
-
-        print(entry_points == ENTRYPOINTS)
-        assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
-        assert "Metadata-Version: 2.1" in metadata
-        assert "Name: CMake.Example" in metadata
-        assert "Version: 0.0.1" in metadata
-        assert "Requires-Python: >=3.7" in metadata
-        assert "Provides-Extra: test" in metadata
-
-        assert "Build: 1foo" in wheel_metadata
-        assert "Wheel-Version: 1.0" in wheel_metadata
-        assert "Generator: scikit-build" in wheel_metadata
-        assert "Root-Is-Purelib: false" in wheel_metadata
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(p) for p in zf.namelist()}
+        file_names = {p.parts[0] for p in file_paths}
+
+        with zf.open("cmake_example-0.0.1.dist-info/METADATA") as f:
+            metadata = f.read().decode("utf-8")
+
+        with zf.open("cmake_example-0.0.1.dist-info/WHEEL") as f:
+            wheel_metadata = f.read().decode("utf-8")
+
+        with zf.open("cmake_example-0.0.1.dist-info/entry_points.txt") as f:
+            entry_points = f.read().decode("utf-8")
+
+    assert Path("cmake_example-0.0.1.dist-info/licenses/LICENSE") in file_paths
+
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
+
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
+
+    print(entry_points == ENTRYPOINTS)
+    assert 'Requires-Dist: pytest>=6.0; extra == "test"' in metadata
+    assert "Metadata-Version: 2.1" in metadata
+    assert "Name: CMake.Example" in metadata
+    assert "Version: 0.0.1" in metadata
+    assert "Requires-Python: >=3.7" in metadata
+    assert "Provides-Extra: test" in metadata
+
+    assert "Build: 1foo" in wheel_metadata
+    assert "Wheel-Version: 1.0" in wheel_metadata
+    assert "Generator: scikit-build" in wheel_metadata
+    assert "Root-Is-Purelib: false" in wheel_metadata
 
     virtualenv.install(wheel)
 
diff --git a/tests/test_pyproject_pep518.py b/tests/test_pyproject_pep518.py
index 8f9f388..db7640a 100644
--- a/tests/test_pyproject_pep518.py
+++ b/tests/test_pyproject_pep518.py
@@ -133,18 +133,16 @@ def test_pep518_wheel_sdist_with_cmake_config(
 
     (wheel,) = Path("dist").glob("sdist_config-0.1.0-*.whl")
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 3
-        file_names.remove("sdist_config-0.1.0.dist-info")
-        file_names.remove("output.py")
-        (so_file,) = file_names
+    assert len(file_names) == 3
+    file_names.remove("sdist_config-0.1.0.dist-info")
+    file_names.remove("output.py")
+    (so_file,) = file_names
 
-        assert so_file.startswith("sdist_config")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("sdist_config")
+    print("SOFILE:", so_file)
 
     isolated.install(wheel)
 
@@ -174,19 +172,19 @@ def test_pep518_wheel(isolated, build_args):
     )
     (wheel,) = Path("dist").glob("cmake_example-0.0.1-*.whl")
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
-            assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(n) for n in zf.namelist()}
+    file_names = {p.parts[0] for p in file_paths}
 
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert Path("cmake_example-0.0.1.dist-info/licenses/LICENSE") in file_paths
 
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
+
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
 
     isolated.install(wheel)
 
@@ -224,19 +222,19 @@ def test_pep518_rebuild_build_dir(isolated, tmp_path, build_args):
         )
     (wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
-            assert p.joinpath("cmake_example-0.0.1.dist-info/licenses/LICENSE").exists()
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(p) for p in zf.namelist()}
+        file_names = {p.parts[0] for p in file_paths}
+
+    assert Path("cmake_example-0.0.1.dist-info/licenses/LICENSE") in file_paths
 
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
 
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
 
     isolated.install(wheel)
 
diff --git a/tests/test_pyproject_pep660.py b/tests/test_pyproject_pep660.py
index 390214a..f21ddbc 100644
--- a/tests/test_pyproject_pep660.py
+++ b/tests/test_pyproject_pep660.py
@@ -29,25 +29,25 @@ def test_pep660_wheel(editable_mode: str):
     (wheel,) = dist.glob("simplest-0.0.1-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
-            metadata = p.joinpath("simplest-0.0.1.dist-info/METADATA").read_text()
-
-        assert len(file_names) == 4 if editable_mode == "redirect" else 2
-        assert "simplest-0.0.1.dist-info" in file_names
-        if editable_mode == "redirect":
-            assert "simplest" in file_names
-            assert "_simplest_editable.py" in file_names
-        else:
-            assert "simplest" not in file_names
-            assert "_simplest_editable.py" not in file_names
-        assert "_simplest_editable.pth" in file_names
-
-        assert "Metadata-Version: 2.1" in metadata
-        assert "Name: simplest" in metadata
-        assert "Version: 0.0.1" in metadata
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(p).parts[0] for p in zf.namelist()}
+
+        with zf.open("simplest-0.0.1.dist-info/METADATA") as f:
+            metadata = f.read().decode("utf-8")
+
+    assert len(file_names) == 4 if editable_mode == "redirect" else 2
+    assert "simplest-0.0.1.dist-info" in file_names
+    if editable_mode == "redirect":
+        assert "simplest" in file_names
+        assert "_simplest_editable.py" in file_names
+    else:
+        assert "simplest" not in file_names
+        assert "_simplest_editable.py" not in file_names
+    assert "_simplest_editable.pth" in file_names
+
+    assert "Metadata-Version: 2.1" in metadata
+    assert "Name: simplest" in metadata
+    assert "Version: 0.0.1" in metadata
 
 
 @pytest.mark.compile()
diff --git a/tests/test_setuptools_abi3.py b/tests/test_setuptools_abi3.py
index 9ceb65f..03513cb 100644
--- a/tests/test_setuptools_abi3.py
+++ b/tests/test_setuptools_abi3.py
@@ -47,17 +47,15 @@ def test_abi3_wheel(tmp_path, monkeypatch, virtualenv):
 
     assert virtualenv.execute("print('hello')") == "hello"
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = {p.name for p in p.iterdir()}
-
-        if sysconfig.get_platform().startswith("win"):
-            assert "abi3_example.pyd" in file_names
-        elif sys.platform.startswith("cygwin"):
-            assert "abi3_example.abi3.dll" in file_names
-        else:
-            assert "abi3_example.abi3.so" in file_names
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
+
+    if sysconfig.get_platform().startswith("win"):
+        assert "abi3_example.pyd" in file_names
+    elif sys.platform.startswith("cygwin"):
+        assert "abi3_example.abi3.dll" in file_names
+    else:
+        assert "abi3_example.abi3.so" in file_names
 
     virtualenv.install(wheel)
 
diff --git a/tests/test_setuptools_pep517.py b/tests/test_setuptools_pep517.py
index af737ac..91d4446 100644
--- a/tests/test_setuptools_pep517.py
+++ b/tests/test_setuptools_pep517.py
@@ -77,18 +77,16 @@ def test_pep517_wheel(virtualenv):
     (wheel,) = dist.glob("cmake_example-0.0.1-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
 
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
 
     virtualenv.install(wheel)
 
@@ -110,18 +108,16 @@ def test_pep517_mixed_wheel(virtualenv):
     (wheel,) = dist.glob("mixed_setuptools-3.1.4-*.whl")
     assert wheel == dist / out
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 2
-        assert "mixed_setuptools-3.1.4.dist-info" in file_names
-        file_names.remove("mixed_setuptools-3.1.4.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "mixed_setuptools-3.1.4.dist-info" in file_names
+    file_names.remove("mixed_setuptools-3.1.4.dist-info")
+    (so_file,) = file_names
 
-        assert so_file.startswith("mixed_setuptools")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("mixed_setuptools")
+    print("SOFILE:", so_file)
 
     virtualenv.install(wheel)
 
diff --git a/tests/test_setuptools_pep518.py b/tests/test_setuptools_pep518.py
index 2559701..6dde9c1 100644
--- a/tests/test_setuptools_pep518.py
+++ b/tests/test_setuptools_pep518.py
@@ -26,18 +26,16 @@ def test_pep518_wheel(isolated):
     assert "cmake_example-0.0.1" in wheel.name
     assert wheel.suffix == ".whl"
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = [p.name for p in p.iterdir()]
+    with zipfile.ZipFile(wheel) as zf:
+        file_names = {Path(n).parts[0] for n in zf.namelist()}
 
-        assert len(file_names) == 2
-        assert "cmake_example-0.0.1.dist-info" in file_names
-        file_names.remove("cmake_example-0.0.1.dist-info")
-        (so_file,) = file_names
+    assert len(file_names) == 2
+    assert "cmake_example-0.0.1.dist-info" in file_names
+    file_names.remove("cmake_example-0.0.1.dist-info")
+    (so_file,) = file_names
 
-        assert so_file.startswith("cmake_example")
-        print("SOFILE:", so_file)
+    assert so_file.startswith("cmake_example")
+    print("SOFILE:", so_file)
 
     isolated.install(wheel)
 
diff --git a/tests/test_simplest_c.py b/tests/test_simplest_c.py
index 8e55093..15a8ca1 100644
--- a/tests/test_simplest_c.py
+++ b/tests/test_simplest_c.py
@@ -1,5 +1,4 @@
 import shutil
-import sys
 import tarfile
 import zipfile
 from pathlib import Path
@@ -8,6 +7,8 @@ import pytest
 
 from scikit_build_core.build import build_sdist, build_wheel
 
+from pathutils import contained
+
 DIR = Path(__file__).parent.resolve()
 SIMPLEST = DIR / "packages/simplest_c"
 
@@ -61,37 +62,37 @@ def test_pep517_wheel(tmp_path, monkeypatch, virtualenv, component):
 
     virtualenv.install(wheel)
 
-    if sys.version_info >= (3, 8):
-        with wheel.open("rb") as f:
-            p = zipfile.Path(f)
-            file_names = {x.name for x in p.iterdir()}
-            simplest_pkg = {x.name for x in p.joinpath("simplest").iterdir()}
-
-        filtered_pkg = {x for x in simplest_pkg if not x.startswith("_module")}
-        if not component or "PythonModule" in component:
-            assert filtered_pkg != simplest_pkg
-        else:
-            assert filtered_pkg == simplest_pkg
-
-        expected_wheel_files = {
-            "__init__.py",
-            "data.txt",
-            "excluded.txt",
-            "sdist_only.txt",
-        }
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(n) for n in zf.namelist()}
+
+    file_names = {p.parts[0] for p in file_paths}
+    simplest_pkg = {p.name for p in contained(file_paths, "simplest")}
+    filtered_pkg = {x for x in simplest_pkg if not x.startswith("_module")}
+
+    if not component or "PythonModule" in component:
+        assert filtered_pkg != simplest_pkg
+    else:
+        assert filtered_pkg == simplest_pkg
+
+    expected_wheel_files = {
+        "__init__.py",
+        "data.txt",
+        "excluded.txt",
+        "sdist_only.txt",
+    }
 
-        if not component:
-            expected_wheel_files.add("generated_ignored.txt")
-            expected_wheel_files.add("generated_no_wheel.txt")
+    if not component:
+        expected_wheel_files.add("generated_ignored.txt")
+        expected_wheel_files.add("generated_no_wheel.txt")
 
-        if not component or "Generated" in component:
-            expected_wheel_files.add("generated.txt")
+    if not component or "Generated" in component:
+        expected_wheel_files.add("generated.txt")
 
-        assert len(filtered_pkg) == len(simplest_pkg) - 2
-        assert {"simplest-0.0.1.dist-info", "simplest"} == file_names
-        assert expected_wheel_files == filtered_pkg
-        # Note that generated_ignored.txt is here because all CMake installed files are
-        # present, CMake has the final say.
+    assert len(filtered_pkg) == len(simplest_pkg) - 2
+    assert {"simplest-0.0.1.dist-info", "simplest"} == file_names
+    assert expected_wheel_files == filtered_pkg
+    # Note that generated_ignored.txt is here because all CMake installed files are
+    # present, CMake has the final say.
 
     version = virtualenv.execute("from simplest import square; print(square(2))")
     assert version == "4.0"
@@ -124,37 +125,26 @@ def test_pep517_wheel_incexl(tmp_path, monkeypatch, virtualenv):
 
     virtualenv.install(wheel)
 
-    with wheel.open("rb") as f:
-        file_names = set(zipfile.ZipFile(f).namelist())
+    with zipfile.ZipFile(wheel) as zf:
+        file_paths = {Path(n) for n in zf.namelist()}
+    file_names = {p.parts[0] for p in file_paths}
 
-    simplest_pkg = {
-        x.split("/", maxsplit=1)[-1] for x in file_names if x.startswith("simplest/")
-    }
-    not_a_pkg = {
-        x.split("/", maxsplit=1)[-1]
-        for x in file_names
-        if x.startswith("not_a_package/")
-    }
-    metadata_items = {
-        x.split("/", maxsplit=1)[-1]
-        for x in file_names
-        if x.startswith("simplest-0.0.1.dist-info/")
-    }
+    simplest_pkg = {x.name for x in contained(file_paths, "simplest")}
+    not_a_pkg = {x.name for x in contained(file_paths, "not_a_package")}
+    metadata_items = set(contained(file_paths, "simplest-0.0.1.dist-info"))
 
     assert {
-        "licenses/LICENSE.txt",
-        "metadata_file.txt",
-        "RECORD",
-        "METADATA",
-        "WHEEL",
+        Path("licenses/LICENSE.txt"),
+        Path("metadata_file.txt"),
+        Path("RECORD"),
+        Path("METADATA"),
+        Path("WHEEL"),
     } == metadata_items
 
     filtered_pkg = {x for x in simplest_pkg if not x.startswith("_module")}
 
     assert len(filtered_pkg) == len(simplest_pkg) - 2
-    assert {"simplest-0.0.1.dist-info", "simplest", "not_a_package"} == {
-        x.split("/")[0] for x in file_names
-    }
+    assert {"simplest-0.0.1.dist-info", "simplest", "not_a_package"} == file_names
     assert {
         "__init__.py",
         "data.txt",
diff --git a/tests/utils/pathutils.py b/tests/utils/pathutils.py
new file mode 100644
index 0000000..d245942
--- /dev/null
+++ b/tests/utils/pathutils.py
@@ -0,0 +1,14 @@
+from __future__ import annotations
+
+import contextlib
+import typing
+
+if typing.TYPE_CHECKING:
+    from collections.abc import Generator, Iterable
+    from pathlib import Path
+
+
+def contained(paths: Iterable[Path], rel: str) -> Generator[Path, None, None]:
+    for p in paths:
+        with contextlib.suppress(ValueError):
+            yield p.relative_to(rel)