feat: support test-groups (#2063)

* feat: support test-groups

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* refactor: address review comments

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* tests: add a integration test

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Apply suggestions from code review

Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com>

* fix: better error messages based on feedback

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com>
This commit is contained in:
Henry Schreiner
2024-11-04 21:25:01 +01:00
committed by GitHub
co-authored by Matthieu Darbois
parent d2c7614c3a
commit cc1d977359
11 changed files with 200 additions and 24 deletions
+8
View File
@@ -22,6 +22,7 @@ environment = {THING = "OTHER", FOO="BAR"}
test-command = "pyproject"
test-requires = "something"
test-extras = ["one", "two"]
test-groups = ["three", "four"]
manylinux-x86_64-image = "manylinux1"
@@ -60,6 +61,7 @@ def test_simple_settings(tmp_path, platform, fname):
== 'THING="OTHER" FOO="BAR"'
)
assert options_reader.get("test-extras", option_format=ListFormat(",")) == "one,two"
assert options_reader.get("test-groups", option_format=ListFormat(" ")) == "three four"
assert options_reader.get("manylinux-x86_64-image") == "manylinux1"
assert options_reader.get("manylinux-i686-image") == "manylinux2014"
@@ -85,7 +87,9 @@ def test_envvar_override(tmp_path, platform):
"CIBW_MANYLINUX_X86_64_IMAGE": "manylinux_2_24",
"CIBW_TEST_COMMAND": "mytest",
"CIBW_TEST_REQUIRES": "docs",
"CIBW_TEST_GROUPS": "mgroup two",
"CIBW_TEST_REQUIRES_LINUX": "scod",
"CIBW_TEST_GROUPS_LINUX": "lgroup",
},
)
@@ -99,6 +103,10 @@ def test_envvar_override(tmp_path, platform):
options_reader.get("test-requires", option_format=ListFormat(" "))
== {"windows": "docs", "macos": "docs", "linux": "scod"}[platform]
)
assert (
options_reader.get("test-groups", option_format=ListFormat(" "))
== {"windows": "mgroup two", "macos": "mgroup two", "linux": "lgroup"}[platform]
)
assert options_reader.get("test-command") == "mytest"
+42 -13
View File
@@ -2,7 +2,14 @@ from __future__ import annotations
from textwrap import dedent
from cibuildwheel.projectfiles import get_requires_python_str, setup_py_python_requires
import pytest
from cibuildwheel._compat import tomllib
from cibuildwheel.projectfiles import (
get_requires_python_str,
resolve_dependency_groups,
setup_py_python_requires,
)
def test_read_setup_py_simple(tmp_path):
@@ -23,7 +30,7 @@ def test_read_setup_py_simple(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) == "1.23"
assert get_requires_python_str(tmp_path) == "1.23"
assert get_requires_python_str(tmp_path, {}) == "1.23"
def test_read_setup_py_if_main(tmp_path):
@@ -45,7 +52,7 @@ def test_read_setup_py_if_main(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) == "1.23"
assert get_requires_python_str(tmp_path) == "1.23"
assert get_requires_python_str(tmp_path, {}) == "1.23"
def test_read_setup_py_if_main_reversed(tmp_path):
@@ -67,7 +74,7 @@ def test_read_setup_py_if_main_reversed(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) == "1.23"
assert get_requires_python_str(tmp_path) == "1.23"
assert get_requires_python_str(tmp_path, {}) == "1.23"
def test_read_setup_py_if_invalid(tmp_path):
@@ -89,7 +96,7 @@ def test_read_setup_py_if_invalid(tmp_path):
)
assert not setup_py_python_requires(tmp_path.joinpath("setup.py").read_text())
assert not get_requires_python_str(tmp_path)
assert not get_requires_python_str(tmp_path, {})
def test_read_setup_py_full(tmp_path):
@@ -115,7 +122,7 @@ def test_read_setup_py_full(tmp_path):
assert (
setup_py_python_requires(tmp_path.joinpath("setup.py").read_text(encoding="utf8")) == "1.24"
)
assert get_requires_python_str(tmp_path) == "1.24"
assert get_requires_python_str(tmp_path, {}) == "1.24"
def test_read_setup_py_assign(tmp_path):
@@ -138,7 +145,7 @@ def test_read_setup_py_assign(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
assert get_requires_python_str(tmp_path, {}) is None
def test_read_setup_py_None(tmp_path):
@@ -161,7 +168,7 @@ def test_read_setup_py_None(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
assert get_requires_python_str(tmp_path, {}) is None
def test_read_setup_py_empty(tmp_path):
@@ -183,7 +190,7 @@ def test_read_setup_py_empty(tmp_path):
)
assert setup_py_python_requires(tmp_path.joinpath("setup.py").read_text()) is None
assert get_requires_python_str(tmp_path) is None
assert get_requires_python_str(tmp_path, {}) is None
def test_read_setup_cfg(tmp_path):
@@ -199,7 +206,7 @@ def test_read_setup_cfg(tmp_path):
)
)
assert get_requires_python_str(tmp_path) == "1.234"
assert get_requires_python_str(tmp_path, {}) == "1.234"
def test_read_setup_cfg_empty(tmp_path):
@@ -215,7 +222,7 @@ def test_read_setup_cfg_empty(tmp_path):
)
)
assert get_requires_python_str(tmp_path) is None
assert get_requires_python_str(tmp_path, {}) is None
def test_read_pyproject_toml(tmp_path):
@@ -231,8 +238,10 @@ def test_read_pyproject_toml(tmp_path):
"""
)
)
with open(tmp_path / "pyproject.toml", "rb") as f:
pyproject_toml = tomllib.load(f)
assert get_requires_python_str(tmp_path) == "1.654"
assert get_requires_python_str(tmp_path, pyproject_toml) == "1.654"
def test_read_pyproject_toml_empty(tmp_path):
@@ -245,5 +254,25 @@ def test_read_pyproject_toml_empty(tmp_path):
"""
)
)
with open(tmp_path / "pyproject.toml", "rb") as f:
pyproject_toml = tomllib.load(f)
assert get_requires_python_str(tmp_path) is None
assert get_requires_python_str(tmp_path, pyproject_toml) is None
def test_read_dep_groups():
pyproject_toml = {"dependency-groups": {"group1": ["pkg1", "pkg2"], "group2": ["pkg3"]}}
assert resolve_dependency_groups(pyproject_toml) == ()
assert resolve_dependency_groups(pyproject_toml, "group1") == ("pkg1", "pkg2")
assert resolve_dependency_groups(pyproject_toml, "group2") == ("pkg3",)
assert resolve_dependency_groups(pyproject_toml, "group1", "group2") == ("pkg1", "pkg2", "pkg3")
def test_dep_group_no_file_error():
with pytest.raises(FileNotFoundError, match="pyproject.toml"):
resolve_dependency_groups(None, "test")
def test_dep_group_no_section_error():
with pytest.raises(KeyError, match="pyproject.toml"):
resolve_dependency_groups({}, "test")