44
55import os
66import pathlib
7- import re
87import stat
98import sys
109import tarfile
1110import textwrap
1211import time
1312
13+ from itertools import chain
14+
1415import pytest
1516
1617import mesonpy
@@ -22,23 +23,23 @@ def test_no_pep621(sdist_library):
2223 with tarfile .open (sdist_library , 'r:gz' ) as sdist :
2324 sdist_pkg_info = sdist .extractfile ('library-1.0.0/PKG-INFO' ).read ().decode ()
2425
25- assert sdist_pkg_info == textwrap .dedent ('''\
26+ assert metadata ( sdist_pkg_info ) == metadata ( textwrap .dedent ('''\
2627 Metadata-Version: 2.1
2728 Name: library
2829 Version: 1.0.0
29- ''' )
30+ ''' ))
3031
3132
3233def test_pep621 (sdist_full_metadata ):
3334 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 ()
35+ sdist_pkg_info = sdist .extractfile ('full_metadata-1.2.3/PKG-INFO' ).read ()
3536
36- metadata = re . escape (textwrap .dedent ('''\
37+ expected = metadata (textwrap .dedent ('''\
3738 Metadata-Version: 2.1
3839 Name: full-metadata
3940 Version: 1.2.3
4041 Summary: Some package with all of the PEP 621 metadata
41- Keywords: full metadata
42+ Keywords: full, metadata
4243 Home-page: https://example.com
4344 Author: Jane Doe
4445 Author-Email: Unknown <[email protected] > @@ -70,20 +71,25 @@ def test_pep621(sdist_full_metadata):
7071 An example package with all of the PEP 621 metadata!
7172 ''' ))
7273
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 )
74+ meta = metadata (sdist_pkg_info )
75+
76+ # pyproject-metadata prior to 0.8.0 incorrectly uses whitespace to separate keywords
77+ meta ['keywords' ] = list (chain (* (k .split (' ' ) for k in meta ['keywords' ])))
78+ # pyproject-metadata prior to 0.9.0 strips trailing newlines
79+ meta ['license' ] = meta ['license' ].rstrip ()
80+
81+ assert meta == expected
7682
7783
7884def test_dynamic_version (sdist_dynamic_version ):
7985 with tarfile .open (sdist_dynamic_version , 'r:gz' ) as sdist :
8086 sdist_pkg_info = sdist .extractfile ('dynamic_version-1.0.0/PKG-INFO' ).read ().decode ()
8187
82- assert sdist_pkg_info == textwrap .dedent ('''\
88+ assert metadata ( sdist_pkg_info ) == metadata ( textwrap .dedent ('''\
8389 Metadata-Version: 2.1
8490 Name: dynamic-version
8591 Version: 1.0.0
86- ''' )
92+ ''' ))
8793
8894
8995def test_contents (sdist_library ):
0 commit comments