|
4 | 4 |
|
5 | 5 | import os |
6 | 6 | import pathlib |
7 | | -import re |
8 | 7 | import stat |
9 | 8 | import sys |
10 | 9 | import tarfile |
11 | 10 | import textwrap |
12 | 11 | import time |
13 | 12 |
|
| 13 | +from itertools import chain |
| 14 | + |
| 15 | +import packaging.metadata |
14 | 16 | import pytest |
15 | 17 |
|
16 | 18 | import mesonpy |
17 | 19 |
|
18 | 20 | from .conftest import in_git_repo_context |
19 | 21 |
|
20 | 22 |
|
| 23 | +def metadata(data): |
| 24 | + meta, other = packaging.metadata.parse_email(data) |
| 25 | + assert not other |
| 26 | + return meta |
| 27 | + |
| 28 | + |
21 | 29 | def test_no_pep621(sdist_library): |
22 | 30 | with tarfile.open(sdist_library, 'r:gz') as sdist: |
23 | 31 | sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode() |
24 | 32 |
|
25 | | - assert sdist_pkg_info == textwrap.dedent('''\ |
| 33 | + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ |
26 | 34 | Metadata-Version: 2.1 |
27 | 35 | Name: library |
28 | 36 | Version: 1.0.0 |
29 | | - ''') |
| 37 | + ''')) |
30 | 38 |
|
31 | 39 |
|
32 | 40 | def test_pep621(sdist_full_metadata): |
33 | 41 | 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() |
35 | 43 |
|
36 | | - metadata = re.escape(textwrap.dedent('''\ |
| 44 | + expected = metadata(textwrap.dedent('''\ |
37 | 45 | Metadata-Version: 2.1 |
38 | 46 | Name: full-metadata |
39 | 47 | Version: 1.2.3 |
40 | 48 | Summary: Some package with all of the PEP 621 metadata |
41 | | - Keywords: full metadata |
| 49 | + Keywords: full, metadata |
42 | 50 | Home-page: https://example.com |
43 | 51 | Author: Jane Doe |
44 | 52 | Author-Email: Unknown <[email protected]> |
@@ -70,20 +78,25 @@ def test_pep621(sdist_full_metadata): |
70 | 78 | An example package with all of the PEP 621 metadata! |
71 | 79 | ''')) |
72 | 80 |
|
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 |
76 | 89 |
|
77 | 90 |
|
78 | 91 | def test_dynamic_version(sdist_dynamic_version): |
79 | 92 | with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist: |
80 | 93 | sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode() |
81 | 94 |
|
82 | | - assert sdist_pkg_info == textwrap.dedent('''\ |
| 95 | + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ |
83 | 96 | Metadata-Version: 2.1 |
84 | 97 | Name: dynamic-version |
85 | 98 | Version: 1.0.0 |
86 | | - ''') |
| 99 | + ''')) |
87 | 100 |
|
88 | 101 |
|
89 | 102 | def test_contents(sdist_library): |
|
0 commit comments