Skip to content

Commit c2e7039

Browse files
committed
TST: adjust for changes in pyproject-metadata 0.9.0
1 parent 35f2842 commit c2e7039

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

tests/test_metadata.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def test_missing_version(package_missing_version):
5353
re.escape('Required "project.version" field is missing'),
5454
# pyproject-metatadata 0.8.0 and later
5555
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
56+
# pyproject-metatadata 0.9.0 and later
57+
re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'),
5658
))
5759
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
5860
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,49 @@
44

55
import os
66
import pathlib
7-
import re
87
import stat
98
import sys
109
import tarfile
1110
import textwrap
1211
import time
1312

13+
from itertools import chain
14+
15+
import packaging.metadata
1416
import pytest
1517

1618
import mesonpy
1719

1820
from .conftest import in_git_repo_context
1921

2022

23+
def metadata(data):
24+
meta, other = packaging.metadata.parse_email(data)
25+
assert not other
26+
return meta
27+
28+
2129
def test_no_pep621(sdist_library):
2230
with tarfile.open(sdist_library, 'r:gz') as sdist:
2331
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()
2432

25-
assert sdist_pkg_info == textwrap.dedent('''\
33+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
2634
Metadata-Version: 2.1
2735
Name: library
2836
Version: 1.0.0
29-
''')
37+
'''))
3038

3139

3240
def test_pep621(sdist_full_metadata):
3341
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
34-
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
42+
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read()
3543

36-
metadata = re.escape(textwrap.dedent('''\
44+
expected = metadata(textwrap.dedent('''\
3745
Metadata-Version: 2.1
3846
Name: full-metadata
3947
Version: 1.2.3
4048
Summary: Some package with all of the PEP 621 metadata
41-
Keywords: full metadata
49+
Keywords: full, metadata
4250
Home-page: https://example.com
4351
Author: Jane Doe
4452
Author-Email: Unknown <[email protected]>
@@ -70,20 +78,25 @@ def test_pep621(sdist_full_metadata):
7078
An example package with all of the PEP 621 metadata!
7179
'''))
7280

73-
# pyproject-metadata 0.8.0 and later uses a comma to separate keywords
74-
expr = metadata.replace(r'Keywords:\ full\ metadata', r'Keywords:\ full[ ,]metadata')
75-
assert re.fullmatch(expr, sdist_pkg_info)
81+
meta = metadata(sdist_pkg_info)
82+
83+
# pyproject-metadata prior to 0.8.0 incorrectly uses whitespace to separate keywords
84+
meta['keywords'] = list(chain(*(k.split(' ') for k in meta['keywords'])))
85+
# pyproject-metadata prior to 0.9.0 strips trailing newlines
86+
meta['license'] = meta['license'].rstrip()
87+
88+
assert meta == expected
7689

7790

7891
def test_dynamic_version(sdist_dynamic_version):
7992
with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
8093
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode()
8194

82-
assert sdist_pkg_info == textwrap.dedent('''\
95+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
8396
Metadata-Version: 2.1
8497
Name: dynamic-version
8598
Version: 1.0.0
86-
''')
99+
'''))
87100

88101

89102
def test_contents(sdist_library):

0 commit comments

Comments
 (0)