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,138 @@ 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_list (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'] 
112+     ''' ), encoding = 'utf8' )
113+ 
114+     tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent (''' 
115+         project('test', license: ['MIT', 'BSD-3-Clause']) 
116+     ''' ), encoding = 'utf8' )
117+ 
118+     with  pytest .raises (pyproject_metadata .ConfigurationError , match = 'Using a list of strings for the license' ):
119+         mesonpy .Project (tmp_path , tmp_path  /  'build' )
120+ 
121+ 
122+ @pytest .mark .skipif (MESON_VERSION  <  (1 , 6 , 0 ), reason = 'meson too old' ) 
123+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' ) 
124+ def  test_dynamic_license_missing (tmp_path ):
125+     tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent (''' 
126+         [build-system] 
127+         build-backend = 'mesonpy' 
128+         requires = ['meson-python'] 
129+ 
130+         [project] 
131+         name = 'test' 
132+         version = '1.0.0' 
133+         dynamic = ['license'] 
134+     ''' ), encoding = 'utf8' )
135+ 
136+     tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent (''' 
137+         project('test') 
138+     ''' ), encoding = 'utf8' )
139+ 
140+     with  pytest .raises (pyproject_metadata .ConfigurationError , match = 'Field "license" declared as dynamic but' ):
141+         mesonpy .Project (tmp_path , tmp_path  /  'build' )
142+ 
143+ 
144+ @pytest .mark .skipif (MESON_VERSION  <  (1 , 6 , 0 ), reason = 'meson too old' ) 
145+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' ) 
146+ def  test_dynamic_license_files (tmp_path ):
147+     tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent (''' 
148+         [build-system] 
149+         build-backend = 'mesonpy' 
150+         requires = ['meson-python'] 
151+ 
152+         [project] 
153+         name = 'test' 
154+         version = '1.0.0' 
155+         dynamic = ['license', 'license-files'] 
156+     ''' ), encoding = 'utf8' )
157+ 
158+     tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent (''' 
159+         project('test', license: 'MIT', license_files: ['LICENSE']) 
160+     ''' ), encoding = 'utf8' )
161+ 
162+     tmp_path .joinpath ('LICENSE' ).write_text ('' )
163+ 
164+     p  =  mesonpy .Project (tmp_path , tmp_path  /  'build' )
165+ 
166+     assert  metadata (bytes (p ._metadata .as_rfc822 ())) ==  metadata (textwrap .dedent ('''\  
167+          Metadata-Version: 2.4
168+         Name: test 
169+         Version: 1.0.0 
170+         License-Expression: MIT 
171+         License-File: LICENSE 
172+     ''' ))
173+ 
174+ 
43175def  test_user_args (package_user_args , tmp_path , monkeypatch ):
44176    project_run  =  mesonpy .Project ._run 
45177    cmds  =  []
0 commit comments