1919
2020import mesonpy
2121
22- from .conftest import in_git_repo_context , package_dir
22+ from .conftest import MESON_VERSION , PYPROJECT_METADATA_VERSION , in_git_repo_context , metadata , package_dir
2323
2424
2525def test_unsupported_python_version (package_unsupported_python_version ):
@@ -40,6 +40,94 @@ def test_missing_dynamic_version(package_missing_dynamic_version):
4040 pass
4141
4242
43+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
44+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
45+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
46+ def test_meson_build_metadata (tmp_path ):
47+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
48+ [build-system]
49+ build-backend = 'mesonpy'
50+ requires = ['meson-python']
51+ ''' ), encoding = 'utf8' )
52+
53+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
54+ project('test', version: '1.2.3', license: 'MIT', license_files: 'LICENSE')
55+ ''' ), encoding = 'utf8' )
56+
57+ tmp_path .joinpath ('LICENSE' ).write_text ('' )
58+
59+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
60+
61+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
62+ Metadata-Version: 2.4
63+ Name: test
64+ Version: 1.2.3
65+ License-Expression: MIT
66+ License-File: LICENSE
67+ ''' ))
68+
69+
70+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
71+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
72+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
73+ def test_dynamic_license (tmp_path ):
74+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
75+ [build-system]
76+ build-backend = 'mesonpy'
77+ requires = ['meson-python']
78+
79+ [project]
80+ name = 'test'
81+ version = '1.0.0'
82+ dynamic = ['license']
83+ ''' ), encoding = 'utf8' )
84+
85+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
86+ project('test', license: 'MIT')
87+ ''' ), encoding = 'utf8' )
88+
89+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
90+
91+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
92+ Metadata-Version: 2.4
93+ Name: test
94+ Version: 1.0.0
95+ License-Expression: MIT
96+ ''' ))
97+
98+
99+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
100+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
101+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
102+ def test_dynamic_license_files (tmp_path ):
103+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
104+ [build-system]
105+ build-backend = 'mesonpy'
106+ requires = ['meson-python']
107+
108+ [project]
109+ name = 'test'
110+ version = '1.0.0'
111+ dynamic = ['license', 'license-files']
112+ ''' ), encoding = 'utf8' )
113+
114+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
115+ project('test', license: 'MIT', license_files: ['LICENSE'])
116+ ''' ), encoding = 'utf8' )
117+
118+ tmp_path .joinpath ('LICENSE' ).write_text ('' )
119+
120+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
121+
122+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
123+ Metadata-Version: 2.4
124+ Name: test
125+ Version: 1.0.0
126+ License-Expression: MIT
127+ License-File: LICENSE
128+ ''' ))
129+
130+
43131def test_user_args (package_user_args , tmp_path , monkeypatch ):
44132 project_run = mesonpy .Project ._run
45133 cmds = []
0 commit comments