Skip to content

Commit

Permalink
TST: move metadata tests from test_project to test_metadata
Browse files Browse the repository at this point in the history
And make them unit tests for the Metadata class.
  • Loading branch information
dnicolodi authored and rgommers committed Oct 7, 2023
1 parent bf3386c commit 8b0733f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 103 deletions.
11 changes: 0 additions & 11 deletions tests/packages/library-pep621/example.c

This file was deleted.

7 changes: 0 additions & 7 deletions tests/packages/library-pep621/examplelib.c

This file was deleted.

18 changes: 0 additions & 18 deletions tests/packages/library-pep621/meson.build

This file was deleted.

11 changes: 0 additions & 11 deletions tests/packages/library-pep621/pyproject.toml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/packages/unsupported-dynamic/meson.build

This file was deleted.

14 changes: 0 additions & 14 deletions tests/packages/unsupported-dynamic/pyproject.toml

This file was deleted.

18 changes: 18 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
38 changes: 1 addition & 37 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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():
Expand Down

0 comments on commit 8b0733f

Please sign in to comment.