|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 | 4 |
|
5 |
| -import contextlib |
6 | 5 | import platform
|
7 |
| -import subprocess |
8 |
| -import sys |
9 | 6 |
|
10 | 7 | import pytest
|
11 | 8 |
|
@@ -52,35 +49,29 @@ def test_unsupported_python_version(package_unsupported_python_version):
|
52 | 49 | pass
|
53 | 50 |
|
54 | 51 |
|
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 = [] |
61 | 55 |
|
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) |
64 | 62 |
|
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] |
67 | 65 |
|
68 | 66 | config_settings = {
|
69 |
| - 'builddir': builddir, # use the build directory we created |
70 | 67 | 'dist-args': ('cli-dist',),
|
71 | 68 | 'setup-args': ('cli-setup',),
|
72 | 69 | 'compile-args': ('cli-compile',),
|
73 | 70 | 'install-args': ('cli-install',),
|
74 | 71 | }
|
75 | 72 |
|
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) |
84 | 75 |
|
85 | 76 | assert last_two_meson_args() == [
|
86 | 77 | # sdist: calls to 'meson setup' and 'meson dist'
|
|
0 commit comments