From a29f8005226245ff5427130cb05b2d26954a583e Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Tue, 3 Nov 2026 21:04:23 +0100 Subject: [PATCH 1/2] TST: use generated package files Generating package contents on the fly, when only minimal package metadata is required, makes the tests easier to inspect and understand. --- tests/packages/dynamic-version/meson.build | 5 - tests/packages/dynamic-version/pyproject.toml | 13 --- .../missing-dynamic-version/meson.build | 5 - .../missing-dynamic-version/pyproject.toml | 11 -- .../missing-meson-version/meson.build | 5 - .../missing-meson-version/pyproject.toml | 7 -- .../pyproject.toml | 10 -- .../pyproject.toml | 10 -- .../unsupported-python-version/meson.build | 5 - .../unsupported-python-version/pyproject.toml | 12 -- tests/packages/user-args/meson.build | 9 -- tests/packages/user-args/pure.py | 6 - tests/packages/user-args/pyproject.toml | 13 --- tests/test_project.py | 108 +++++++++++++++--- tests/test_sdist.py | 23 +++- 15 files changed, 112 insertions(+), 130 deletions(-) delete mode 100644 tests/packages/dynamic-version/meson.build delete mode 100644 tests/packages/dynamic-version/pyproject.toml delete mode 100644 tests/packages/missing-dynamic-version/meson.build delete mode 100644 tests/packages/missing-dynamic-version/pyproject.toml delete mode 100644 tests/packages/missing-meson-version/meson.build delete mode 100644 tests/packages/missing-meson-version/pyproject.toml delete mode 100644 tests/packages/unknown-user-args-meson-args/pyproject.toml delete mode 100644 tests/packages/unknown-user-args-top-level/pyproject.toml delete mode 100644 tests/packages/unsupported-python-version/meson.build delete mode 100644 tests/packages/unsupported-python-version/pyproject.toml delete mode 100644 tests/packages/user-args/meson.build delete mode 100644 tests/packages/user-args/pure.py delete mode 100644 tests/packages/user-args/pyproject.toml diff --git a/tests/packages/dynamic-version/meson.build b/tests/packages/dynamic-version/meson.build deleted file mode 100644 index 24eb3bf26..000000000 --- a/tests/packages/dynamic-version/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('dynamic-version', version: '1.0.0') diff --git a/tests/packages/dynamic-version/pyproject.toml b/tests/packages/dynamic-version/pyproject.toml deleted file mode 100644 index 8e778fcef..000000000 --- a/tests/packages/dynamic-version/pyproject.toml +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[project] -name = 'dynamic-version' -dynamic = [ - 'version', -] diff --git a/tests/packages/missing-dynamic-version/meson.build b/tests/packages/missing-dynamic-version/meson.build deleted file mode 100644 index 7f0ac9f8f..000000000 --- a/tests/packages/missing-dynamic-version/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('missing-dynamic-version') diff --git a/tests/packages/missing-dynamic-version/pyproject.toml b/tests/packages/missing-dynamic-version/pyproject.toml deleted file mode 100644 index 22a1ff801..000000000 --- a/tests/packages/missing-dynamic-version/pyproject.toml +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[project] -name = 'missing-dynamic-version' -dynamic = ['version'] diff --git a/tests/packages/missing-meson-version/meson.build b/tests/packages/missing-meson-version/meson.build deleted file mode 100644 index 74cbf651e..000000000 --- a/tests/packages/missing-meson-version/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('missing-meson-version') diff --git a/tests/packages/missing-meson-version/pyproject.toml b/tests/packages/missing-meson-version/pyproject.toml deleted file mode 100644 index 79b6ea07f..000000000 --- a/tests/packages/missing-meson-version/pyproject.toml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2023 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] diff --git a/tests/packages/unknown-user-args-meson-args/pyproject.toml b/tests/packages/unknown-user-args-meson-args/pyproject.toml deleted file mode 100644 index 0f9ee3a97..000000000 --- a/tests/packages/unknown-user-args-meson-args/pyproject.toml +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[tool.meson-python.args] -unknown = [] diff --git a/tests/packages/unknown-user-args-top-level/pyproject.toml b/tests/packages/unknown-user-args-top-level/pyproject.toml deleted file mode 100644 index 06aaabfa2..000000000 --- a/tests/packages/unknown-user-args-top-level/pyproject.toml +++ /dev/null @@ -1,10 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[tool.meson-python] -unknown = {} diff --git a/tests/packages/unsupported-python-version/meson.build b/tests/packages/unsupported-python-version/meson.build deleted file mode 100644 index 009cb3ca3..000000000 --- a/tests/packages/unsupported-python-version/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('unsupported-python-version', version: '1.0.0') diff --git a/tests/packages/unsupported-python-version/pyproject.toml b/tests/packages/unsupported-python-version/pyproject.toml deleted file mode 100644 index ab00c7022..000000000 --- a/tests/packages/unsupported-python-version/pyproject.toml +++ /dev/null @@ -1,12 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[project] -name = 'unsupported-python-version' -version = '1.2.3' -requires-python = '==1.0.0' diff --git a/tests/packages/user-args/meson.build b/tests/packages/user-args/meson.build deleted file mode 100644 index f0e0f12ac..000000000 --- a/tests/packages/user-args/meson.build +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('user-args', version: '1.0.0') - -py = import('python').find_installation() - -py.install_sources('pure.py') diff --git a/tests/packages/user-args/pure.py b/tests/packages/user-args/pure.py deleted file mode 100644 index d8e597a88..000000000 --- a/tests/packages/user-args/pure.py +++ /dev/null @@ -1,6 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -def foo(): - return 'bar' diff --git a/tests/packages/user-args/pyproject.toml b/tests/packages/user-args/pyproject.toml deleted file mode 100644 index f2a4aad7e..000000000 --- a/tests/packages/user-args/pyproject.toml +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-FileCopyrightText: 2022 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[tool.meson-python.args] -dist = ['config-dist'] -setup = ['config-setup'] -compile = ['config-compile'] -install = ['--skip-subprojects=config'] diff --git a/tests/test_project.py b/tests/test_project.py index 1438844f1..8fd157187 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -25,13 +25,27 @@ from mesonpy._util import chdir -from .conftest import MESON_VERSION, in_git_repo_context, metadata, package_dir +from .conftest import MESON_VERSION, in_git_repo_context, metadata -def test_unsupported_python_version(package_unsupported_python_version): +def test_unsupported_python_version(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [project] + name = 'test' + version = '1.0.0' + requires-python = '==1.0.0' + '''), encoding='utf8') + + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('test', version: '1.0.0') + '''), encoding='utf8') + with pytest.raises(mesonpy.MesonBuilderError, match='The package requires Python version ==1.0.0'): - with mesonpy._project(): - pass + mesonpy.Project(tmp_path, tmp_path / 'build') def test_prerelease_python_version(tmp_path, monkeypatch): @@ -55,16 +69,38 @@ def test_prerelease_python_version(tmp_path, monkeypatch): mesonpy.Project(tmp_path, tmp_path / 'build') -def test_missing_meson_version(package_missing_meson_version): +def test_missing_meson_version(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + '''), encoding='utf8') + + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('test') + '''), encoding='utf8') + with pytest.raises(pyproject_metadata.ConfigurationError, match='Section "project" missing in pyproject.toml'): - with mesonpy._project(): - pass + mesonpy.Project(tmp_path, tmp_path / 'build') + + +def test_missing_dynamic_version(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [project] + name = 'test' + dynamic = ['version'] + '''), encoding='utf8') + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('test') + '''), encoding='utf8') -def test_missing_dynamic_version(package_missing_dynamic_version): with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "version" declared as dynamic but'): - with mesonpy._project(): - pass + mesonpy.Project(tmp_path, tmp_path / 'build') @pytest.mark.skipif(MESON_VERSION < (1, 6, 0), reason='meson too old') @@ -196,7 +232,23 @@ def test_dynamic_license_files(tmp_path): ''')) -def test_user_args(package_user_args, tmp_path, monkeypatch): +def test_user_args(tmp_path, monkeypatch): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [tool.meson-python.args] + dist = ['config-dist'] + setup = ['config-setup'] + compile = ['config-compile'] + install = ['--skip-subprojects=config'] + '''), encoding='utf8') + + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('test', version: '1.0.0') + '''), encoding='utf8') + project_run = mesonpy.Project._run cmds = [] args = [] @@ -227,9 +279,9 @@ def wrapper(self, cmd): 'compile-args': ('cli-compile',), } - with in_git_repo_context(): - mesonpy.build_sdist(tmp_path, config_settings) - mesonpy.build_wheel(tmp_path, config_settings) + with chdir(tmp_path), in_git_repo_context(): + mesonpy.build_sdist(tmp_path / 'dist', config_settings) + mesonpy.build_wheel(tmp_path / 'dist', config_settings) # check that the right commands are executed, namely that 'meson # compile' is used on Windows rather than a 'ninja' direct @@ -256,10 +308,32 @@ def wrapper(self, cmd): assert expected_args.issubset(cmd_args) -@pytest.mark.parametrize('package', ('top-level', 'meson-args')) -def test_unknown_user_args(package, tmp_path_session): +def test_unknown_user_args_key(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [tool.meson-python] + unknown = {} + '''), encoding='utf8') + with pytest.raises(mesonpy.ConfigError): - mesonpy.Project(package_dir / f'unknown-user-args-{package}', tmp_path_session) + mesonpy.Project(tmp_path, tmp_path / 'build') + + +def test_unknown_meson_args_key(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [tool.meson-python.args] + unknown = [] + '''), encoding='utf8') + + with pytest.raises(mesonpy.ConfigError): + mesonpy.Project(tmp_path, tmp_path / 'build') def test_install_tags(package_purelib_and_platlib, tmp_path_session): diff --git a/tests/test_sdist.py b/tests/test_sdist.py index 9048a4e23..d20878fe0 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -13,6 +13,8 @@ import mesonpy +from mesonpy._util import chdir + from .conftest import MESON_VERSION, in_git_repo_context, metadata @@ -72,8 +74,25 @@ def test_pep621_metadata(sdist_full_metadata): ''')) -def test_dynamic_version(sdist_dynamic_version): - with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist: +def test_dynamic_version(tmp_path): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [project] + name = 'dynamic-version' + dynamic = ['version'] + '''), encoding='utf8') + + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('dynamic-version', version: '1.0.0') + '''), encoding='utf8') + + with chdir(tmp_path), in_git_repo_context(): + archive = mesonpy.build_sdist(tmp_path / 'dist', {}) + + with tarfile.open(tmp_path / 'dist' / archive, 'r:gz') as sdist: sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read() assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ From 4c42389d032180ca035eacf423262f73e4f0e7e9 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sun, 8 Nov 2026 17:54:58 +0100 Subject: [PATCH 2/2] TST: remove obsolete editable package cleanup The build directory for editable packages was changed a long time ago. --- tests/conftest.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0f24a30f3..f0eecf296 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -166,7 +166,6 @@ def fixture(tmp_path_session): def generate_editable_fixture(package): @pytest.fixture(scope='session') def fixture(tmp_path_session): - shutil.rmtree(package_dir / package / '.mesonpy' / 'editable', ignore_errors=True) with chdir(package_dir / package): return tmp_path_session / mesonpy.build_editable(tmp_path_session) return fixture