From b0ca3833dc282b022525153bca70e6aa6a077ace Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Tue, 3 Nov 2026 21:04:23 +0100 Subject: [PATCH] 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. --- .../missing-dynamic-version/meson.build | 5 -- .../missing-dynamic-version/pyproject.toml | 11 ---- .../missing-meson-version/meson.build | 5 -- .../missing-meson-version/pyproject.toml | 7 --- .../unsupported-python-version/meson.build | 5 -- .../unsupported-python-version/pyproject.toml | 12 ----- tests/test_project.py | 50 +++++++++++++++---- 7 files changed, 41 insertions(+), 54 deletions(-) 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/unsupported-python-version/meson.build delete mode 100644 tests/packages/unsupported-python-version/pyproject.toml 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/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/test_project.py b/tests/test_project.py index a6f711ccf..257a7b9fa 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -28,22 +28,54 @@ from .conftest import MESON_VERSION, in_git_repo_context, metadata, package_dir -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(''' + [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_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') -def test_missing_meson_version(package_missing_meson_version): 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')