Skip to content

Commit da3ed13

Browse files
committed
TST: adapt to recent changes
Running 'meson setup' is now required to create a Project object for a package that does not specify its metadata in pyproject.toml. Mocking the calls to meson away in tests does not work anymore. Adapt the tests.
1 parent 615f768 commit da3ed13

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

tests/test_project.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
import contextlib
65
import platform
7-
import subprocess
8-
import sys
96

107
import pytest
118

@@ -52,35 +49,29 @@ def test_unsupported_python_version(package_unsupported_python_version):
5249
pass
5350

5451

55-
@pytest.mark.skipif(
56-
sys.version_info < (3, 8),
57-
reason="unittest.mock doesn't support the required APIs for this test",
58-
)
59-
def test_user_args(package_user_args, mocker, tmp_path_session):
60-
mocker.patch('mesonpy.Project._meson')
52+
def test_user_args(package_user_args, tmp_path, monkeypatch):
53+
meson = mesonpy.Project._meson
54+
call_args_list = []
6155

62-
def last_two_meson_args():
63-
return [call.args[-2:] for call in mesonpy.Project._meson.call_args_list]
56+
def wrapper(self, *args):
57+
# intercept and filter out test arguments and forward the call
58+
call_args_list.append(args)
59+
return meson(self, *[x for x in args if not x.startswith(('config-', 'cli-'))])
60+
61+
monkeypatch.setattr(mesonpy.Project, '_meson', wrapper)
6462

65-
# create the build directory ourselves because Project._meson is mocked
66-
builddir = str(tmp_path_session / 'build')
63+
def last_two_meson_args():
64+
return [args[-2:] for args in call_args_list]
6765

6866
config_settings = {
69-
'builddir': builddir, # use the build directory we created
7067
'dist-args': ('cli-dist',),
7168
'setup-args': ('cli-setup',),
7269
'compile-args': ('cli-compile',),
7370
'install-args': ('cli-install',),
7471
}
7572

76-
with contextlib.suppress(FileNotFoundError):
77-
mesonpy.build_sdist(tmp_path_session / 'dist', config_settings)
78-
79-
# run setup ourselves because Project._meson is mocked
80-
subprocess.run(['meson', 'setup', '.', builddir], check=True)
81-
82-
with contextlib.suppress(FileNotFoundError):
83-
mesonpy.build_wheel(tmp_path_session / 'dist', config_settings)
73+
mesonpy.build_sdist(tmp_path, config_settings)
74+
mesonpy.build_wheel(tmp_path, config_settings)
8475

8576
assert last_two_meson_args() == [
8677
# sdist: calls to 'meson setup' and 'meson dist'

0 commit comments

Comments
 (0)