Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions tests/packages/dynamic-version/meson.build

This file was deleted.

13 changes: 0 additions & 13 deletions tests/packages/dynamic-version/pyproject.toml

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions tests/packages/missing-dynamic-version/pyproject.toml

This file was deleted.

5 changes: 0 additions & 5 deletions tests/packages/missing-meson-version/meson.build

This file was deleted.

7 changes: 0 additions & 7 deletions tests/packages/missing-meson-version/pyproject.toml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/packages/unknown-user-args-meson-args/pyproject.toml

This file was deleted.

10 changes: 0 additions & 10 deletions tests/packages/unknown-user-args-top-level/pyproject.toml

This file was deleted.

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

This file was deleted.

12 changes: 0 additions & 12 deletions tests/packages/unsupported-python-version/pyproject.toml

This file was deleted.

9 changes: 0 additions & 9 deletions tests/packages/user-args/meson.build

This file was deleted.

6 changes: 0 additions & 6 deletions tests/packages/user-args/pure.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/packages/user-args/pyproject.toml

This file was deleted.

108 changes: 91 additions & 17 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
23 changes: 21 additions & 2 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import mesonpy

from mesonpy._util import chdir

from .conftest import MESON_VERSION, in_git_repo_context, metadata


Expand Down Expand Up @@ -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('''\
Expand Down
Loading