Skip to content

Commit 965483c

Browse files
committed
TST: adjust for changes in pyproject-metadata 0.9.0
1 parent d638bc8 commit 965483c

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dynamic = [
4747
[project.optional-dependencies]
4848
test = [
4949
'build',
50+
'packaging >= 23.1',
5051
'pytest >= 6.0',
5152
'pytest-cov[toml]',
5253
'pytest-mock',

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from venv import EnvBuilder
1818

19+
import packaging.metadata
1920
import packaging.version
2021
import pytest
2122

@@ -24,6 +25,12 @@
2425
from mesonpy._util import chdir
2526

2627

28+
def metadata(data):
29+
meta, other = packaging.metadata.parse_email(data)
30+
assert not other
31+
return meta
32+
33+
2734
def adjust_packaging_platform_tag(platform: str) -> str:
2835
if platform.startswith(('manylinux', 'musllinux')):
2936
# The packaging module generates overly specific platforms tags on

tests/test_metadata.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,11 @@ def test_missing_version(package_missing_version):
4848
pyproject = {'project': {
4949
'name': 'missing-version',
5050
}}
51-
with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'):
51+
match = '|'.join((
52+
# pyproject-metatadata 0.8.0 and later
53+
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
54+
# pyproject-metatadata 0.9.0 and later
55+
re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'),
56+
))
57+
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
5258
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,36 @@
1010
import textwrap
1111
import time
1212

13+
from itertools import chain
14+
1315
import pytest
1416

1517
import mesonpy
1618

17-
from .conftest import in_git_repo_context
19+
from .conftest import in_git_repo_context, metadata
1820

1921

2022
def test_no_pep621(sdist_library):
2123
with tarfile.open(sdist_library, 'r:gz') as sdist:
22-
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()
24+
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read()
2325

24-
assert sdist_pkg_info == textwrap.dedent('''\
26+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
2527
Metadata-Version: 2.1
2628
Name: library
2729
Version: 1.0.0
28-
''')
30+
'''))
2931

3032

3133
def test_pep621(sdist_full_metadata):
3234
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
33-
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
35+
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read()
36+
37+
meta = metadata(sdist_pkg_info)
3438

35-
metadata = textwrap.dedent('''\
39+
# pyproject-metadata prior to 0.9.0 strips trailing newlines
40+
meta['license'] = meta['license'].rstrip()
41+
42+
assert meta == metadata(textwrap.dedent('''\
3643
Metadata-Version: 2.1
3744
Name: full-metadata
3845
Version: 1.2.3
@@ -67,20 +74,18 @@ def test_pep621(sdist_full_metadata):
6774
# full-metadata
6875
6976
An example package with all of the PEP 621 metadata!
70-
''')
71-
72-
assert sdist_pkg_info == metadata
77+
'''))
7378

7479

7580
def test_dynamic_version(sdist_dynamic_version):
7681
with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
77-
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode()
82+
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read()
7883

79-
assert sdist_pkg_info == textwrap.dedent('''\
84+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
8085
Metadata-Version: 2.1
8186
Name: dynamic-version
8287
Version: 1.0.0
83-
''')
88+
'''))
8489

8590

8691
def test_contents(sdist_library):

0 commit comments

Comments
 (0)