forked from mesonbuild/meson-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_project.py
More file actions
91 lines (72 loc) · 2.49 KB
/
Copy pathtest_project.py
File metadata and controls
91 lines (72 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# SPDX-License-Identifier: MIT
import contextlib
import platform
import subprocess
import sys
import pytest
import mesonpy
from .conftest import cd_package
@pytest.mark.parametrize(
('package'),
[
'library',
'library-pep621',
]
)
def test_name(package):
with cd_package(package), mesonpy.Project.with_temp_working_dir() as project:
assert project.name == package.replace('-', '_')
@pytest.mark.parametrize(
('package'),
[
'library',
'library-pep621',
]
)
def test_version(package):
with cd_package(package), mesonpy.Project.with_temp_working_dir() as project:
assert project.version == '1.0.0'
def test_unsupported_dynamic(package_unsupported_dynamic):
with pytest.raises(mesonpy.MesonBuilderError, match='Unsupported dynamic fields: dependencies'):
with mesonpy.Project.with_temp_working_dir():
pass
def test_unsupported_python_version(package_unsupported_python_version):
with pytest.raises(mesonpy.MesonBuilderError, match=(
f'Unsupported Python version `{platform.python_version()}`, '
'expected `==1.0.0`'
)):
with mesonpy.Project.with_temp_working_dir():
pass
@pytest.mark.skipif(
sys.version_info < (3, 8),
reason="unittest.mock doesn't support the required APIs for this test",
)
def test_user_args(package_user_args, mocker, tmp_dir_session):
mocker.patch('mesonpy.Project._meson')
def last_two_meson_args():
return [
call.args[-2:] for call in mesonpy.Project._meson.call_args_list
]
# create the build directory ourselves because Project._meson is mocked
builddir = str(tmp_dir_session / 'build')
subprocess.run(['meson', 'setup', '.', builddir], check=True)
config_settings = {
'builddir': builddir, # use the build directory we created
'dist_args': ('cli-dist',),
'setup_args': ('cli-setup',),
'compile_args': ('cli-compile',),
'install_args': ('cli-install',),
}
with contextlib.suppress(Exception):
mesonpy.build_sdist(tmp_dir_session / 'dist', config_settings)
with contextlib.suppress(Exception):
mesonpy.build_wheel(tmp_dir_session / 'dist', config_settings)
assert last_two_meson_args() == [
# sdist
('config-setup', 'cli-setup'),
('config-dist', 'cli-dist'),
# wheel
('config-setup', 'cli-setup'),
('config-compile', 'cli-compile'),
('config-install', 'cli-install'),
]