11import logging
2- import re
3- import os
42import sys
53from pathlib import Path
6- from unittest .mock import patch
74import pytest
85
96from flit_core import config
@@ -147,6 +144,7 @@ def test_bad_include_paths(path, err_match):
147144 ({'license-files' : ["/LICENSE" ]}, r"'/LICENSE'.+must not start with '/'" ),
148145 ({'license-files' : ["../LICENSE" ]}, r"'../LICENSE'.+must not contain '..'" ),
149146 ({'license-files' : ["NOT_FOUND" ]}, r"No files found.+'NOT_FOUND'" ),
147+ ({'license-files' : ["(LICENSE | LICENCE)" ]}, "Pattern contains invalid characters" ),
150148 pytest .param (
151149 {'license-files' : ["**LICENSE" ]}, r"'\*\*LICENSE'.+Invalid pattern" ,
152150 marks = [pytest .mark .skipif (
@@ -159,6 +157,10 @@ def test_bad_include_paths(path, err_match):
159157 sys .version_info < (3 , 13 ), reason = "Pattern started to raise ValueError in 3.13"
160158 )]
161159 ),
160+ (
161+ {'license' : {'file' : 'LICENSE' }, 'license-files' : ["LICENSE" ]},
162+ "license-files cannot be used with a license table" ,
163+ ),
162164 ({'keywords' : 'foo' }, 'list' ),
163165 ({'keywords' : ['foo' , 7 ]}, 'strings' ),
164166 ({'entry-points' : {'foo' : 'module1:main' }}, 'entry-point.*tables' ),
@@ -181,7 +183,7 @@ def test_bad_pep621_info(proj_bad, err_match):
181183 proj = {'name' : 'module1' , 'version' : '1.0' , 'description' : 'x' }
182184 proj .update (proj_bad )
183185 with pytest .raises (config .ConfigError , match = err_match ):
184- config .read_pep621_metadata (proj , samples_dir / 'pep621' )
186+ config .read_pep621_metadata (proj , samples_dir / 'pep621' / 'pyproject.toml' )
185187
186188@pytest .mark .parametrize (('readme' , 'err_match' ), [
187189 ({'file' : 'README.rst' }, 'required' ),
@@ -197,29 +199,23 @@ def test_bad_pep621_readme(readme, err_match):
197199 'name' : 'module1' , 'version' : '1.0' , 'description' : 'x' , 'readme' : readme
198200 }
199201 with pytest .raises (config .ConfigError , match = err_match ):
200- config .read_pep621_metadata (proj , samples_dir / 'pep621' )
201-
202-
203- @pytest .mark .parametrize (('value' , 'files' ), [
204- ('[]' , []),
205- ('["LICENSE"]' , ["LICENSE" ]),
206- ('["LICENSE*"]' , ["LICENSE" ]),
207- ('["**/LICENSE*"]' , ["LICENSE" , "module/vendor/LICENSE_VENDOR" ]),
208- ('["module/vendor/LICENSE*"]' , ["module/vendor/LICENSE_VENDOR" ]),
209- ('["LICENSE", "module/**/LICENSE*"]' , ["LICENSE" , "module/vendor/LICENSE_VENDOR" ]),
202+ config .read_pep621_metadata (proj , samples_dir / 'pep621' / 'pyproject.toml' )
203+
204+
205+ @pytest .mark .parametrize (('proj_license_files' , 'files' ), [
206+ ({}, ["LICENSE" ]), # Only match default patterns
207+ ({'license-files' : []}, []),
208+ ({'license-files' : ["LICENSE" ]}, ["LICENSE" ]),
209+ ({'license-files' : ["LICENSE*" ]}, ["LICENSE" ]),
210+ ({'license-files' : ["LICEN[CS]E*" ]}, ["LICENSE" ]),
211+ ({'license-files' : ["**/LICENSE*" ]}, ["LICENSE" , "module/vendor/LICENSE_VENDOR" ]),
212+ ({'license-files' : ["module/vendor/LICENSE*" ]}, ["module/vendor/LICENSE_VENDOR" ]),
213+ ({'license-files' : ["LICENSE" , "module/**/LICENSE*" ]}, ["LICENSE" , "module/vendor/LICENSE_VENDOR" ]),
214+ # Add project.license.file + match default patterns
215+ ({'license' : {'file' : 'module/vendor/LICENSE_VENDOR' }}, ["LICENSE" , "module/vendor/LICENSE_VENDOR" ]),
210216])
211- def test_pep621_license_files (value , files ):
212- path = samples_dir / 'pep621_license_files' / 'pyproject.toml'
213- data = path .read_text ()
214- data = re .sub (
215- r"(^license-files = )(?:\[.*\])" , r"\g<1>{}" .format (value ),
216- data , count = 1 , flags = re .M
217- )
218- dir = os .getcwd ()
219- try :
220- os .chdir (samples_dir / 'pep621_license_files' )
221- with patch ("pathlib.Path.read_text" , return_value = data ):
222- info = config .read_flit_config (path )
223- assert info .metadata ['license_files' ] == files
224- finally :
225- os .chdir (dir )
217+ def test_pep621_license_files (proj_license_files , files ):
218+ proj = {'name' : 'module1' , 'version' : '1.0' , 'description' : 'x' }
219+ proj .update (proj_license_files )
220+ info = config .read_pep621_metadata (proj , samples_dir / 'pep621_license_files' / 'pyproject.toml' )
221+ assert info .metadata ['license_files' ] == files
0 commit comments