From 8b0733fd85c98b7e8528e68edb86c629a0958adf Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sat, 9 Sep 2023 21:32:20 +0200 Subject: [PATCH] TST: move metadata tests from test_project to test_metadata And make them unit tests for the Metadata class. --- tests/packages/library-pep621/example.c | 11 ------ tests/packages/library-pep621/examplelib.c | 7 ---- tests/packages/library-pep621/meson.build | 18 --------- tests/packages/library-pep621/pyproject.toml | 11 ------ .../packages/unsupported-dynamic/meson.build | 5 --- .../unsupported-dynamic/pyproject.toml | 14 ------- tests/test_metadata.py | 18 +++++++++ tests/test_project.py | 38 +------------------ 8 files changed, 19 insertions(+), 103 deletions(-) delete mode 100644 tests/packages/library-pep621/example.c delete mode 100644 tests/packages/library-pep621/examplelib.c delete mode 100644 tests/packages/library-pep621/meson.build delete mode 100644 tests/packages/library-pep621/pyproject.toml delete mode 100644 tests/packages/unsupported-dynamic/meson.build delete mode 100644 tests/packages/unsupported-dynamic/pyproject.toml diff --git a/tests/packages/library-pep621/example.c b/tests/packages/library-pep621/example.c deleted file mode 100644 index ac7e022ec..000000000 --- a/tests/packages/library-pep621/example.c +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-FileCopyrightText: 2021 The meson-python developers -// -// SPDX-License-Identifier: MIT - -#include - -int sum(int, int); - -int main() { - printf("sum: %d", sum(1, 2)); -} diff --git a/tests/packages/library-pep621/examplelib.c b/tests/packages/library-pep621/examplelib.c deleted file mode 100644 index add7c8911..000000000 --- a/tests/packages/library-pep621/examplelib.c +++ /dev/null @@ -1,7 +0,0 @@ -// SPDX-FileCopyrightText: 2021 The meson-python developers -// -// SPDX-License-Identifier: MIT - -int sum(int a, int b) { - return a + b; -} diff --git a/tests/packages/library-pep621/meson.build b/tests/packages/library-pep621/meson.build deleted file mode 100644 index f4f56e50e..000000000 --- a/tests/packages/library-pep621/meson.build +++ /dev/null @@ -1,18 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('library-pep621', 'c') - -example_lib = shared_library( - 'example', - 'examplelib.c', - install: true, -) - -executable( - 'example', - 'example.c', - link_with: example_lib, - install: true, -) diff --git a/tests/packages/library-pep621/pyproject.toml b/tests/packages/library-pep621/pyproject.toml deleted file mode 100644 index a979bc1af..000000000 --- a/tests/packages/library-pep621/pyproject.toml +++ /dev/null @@ -1,11 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[project] -name = 'library-pep621' -version = '1.0.0' diff --git a/tests/packages/unsupported-dynamic/meson.build b/tests/packages/unsupported-dynamic/meson.build deleted file mode 100644 index 88e7a3553..000000000 --- a/tests/packages/unsupported-dynamic/meson.build +++ /dev/null @@ -1,5 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The meson-python developers -# -# SPDX-License-Identifier: MIT - -project('unsupported-dynamic', version: '1.0.0') diff --git a/tests/packages/unsupported-dynamic/pyproject.toml b/tests/packages/unsupported-dynamic/pyproject.toml deleted file mode 100644 index ee63c29b9..000000000 --- a/tests/packages/unsupported-dynamic/pyproject.toml +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2021 The meson-python developers -# -# SPDX-License-Identifier: MIT - -[build-system] -build-backend = 'mesonpy' -requires = ['meson-python'] - -[project] -name = 'unsupported-dynamic' -version = '1.0.0' -dynamic = [ - 'dependencies', -] diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 6e54153a6..0c278da63 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -32,3 +32,21 @@ def test_package_name_from_pyproject(): def test_package_name_invalid(): with pytest.raises(pyproject_metadata.ConfigurationError, match='Invalid project name'): Metadata(name='.test', version=packaging.version.Version('0.0.1')) + + +def test_unsupported_dynamic(): + pyproject = {'project': { + 'name': 'unsupported-dynamic', + 'version': '0.0.1', + 'dynamic': ['dependencies'], + }} + with pytest.raises(pyproject_metadata.ConfigurationError, match='Unsupported dynamic fields: "dependencies"'): + Metadata.from_pyproject(pyproject, pathlib.Path()) + + +def test_missing_version(package_missing_version): + pyproject = {'project': { + 'name': 'missing-version', + }} + with pytest.raises(pyproject_metadata.ConfigurationError, match='Required "project.version" field is missing'): + Metadata.from_pyproject(pyproject, pathlib.Path()) diff --git a/tests/test_project.py b/tests/test_project.py index 532bd60a7..3f27e6ff5 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -19,37 +19,7 @@ import mesonpy -from .conftest import chdir, in_git_repo_context, package_dir - - -@pytest.mark.parametrize( - ('package'), - [ - 'library', - 'library-pep621', - ] -) -def test_name(package): - with chdir(package_dir / package), mesonpy._project() as project: - assert project._metadata.distribution_name == package.replace('-', '_') - - -@pytest.mark.parametrize( - ('package'), - [ - 'library', - 'library-pep621', - ] -) -def test_version(package): - with chdir(package_dir / package), mesonpy._project() as project: - assert str(project._metadata.version) == '1.0.0' - - -def test_unsupported_dynamic(package_unsupported_dynamic): - with pytest.raises(pyproject_metadata.ConfigurationError, match='Unsupported dynamic fields: "dependencies"'): - with mesonpy._project(): - pass +from .conftest import in_git_repo_context, package_dir def test_unsupported_python_version(package_unsupported_python_version): @@ -58,12 +28,6 @@ def test_unsupported_python_version(package_unsupported_python_version): pass -def test_missing_version(package_missing_version): - with pytest.raises(pyproject_metadata.ConfigurationError, match='Required "project.version" field is missing'): - with mesonpy._project(): - pass - - 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():