|
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 | + |
14 | 15 | import pytest |
15 | 16 |
|
16 | 17 | import mesonpy |
17 | 18 |
|
18 | | -from .conftest import in_git_repo_context |
| 19 | +from .conftest import in_git_repo_context, metadata |
19 | 20 |
|
20 | 21 |
|
21 | 22 | def test_no_pep621(sdist_library): |
22 | 23 | with tarfile.open(sdist_library, 'r:gz') as sdist: |
23 | 24 | sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode() |
24 | 25 |
|
25 | | - assert sdist_pkg_info == textwrap.dedent('''\ |
| 26 | + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ |
26 | 27 | Metadata-Version: 2.1 |
27 | 28 | Name: library |
28 | 29 | Version: 1.0.0 |
29 | | - ''') |
| 30 | + ''')) |
30 | 31 |
|
31 | 32 |
|
32 | 33 | def test_pep621(sdist_full_metadata): |
33 | 34 | 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() |
35 | 36 |
|
36 | | - metadata = re.escape(textwrap.dedent('''\ |
| 37 | + expected = metadata(textwrap.dedent('''\ |
37 | 38 | Metadata-Version: 2.1 |
38 | 39 | Name: full-metadata |
39 | 40 | Version: 1.2.3 |
40 | 41 | Summary: Some package with all of the PEP 621 metadata |
41 | | - Keywords: full metadata |
| 42 | + Keywords: full, metadata |
42 | 43 | Home-page: https://example.com |
43 | 44 | Author: Jane Doe |
44 | 45 | Author-Email: Unknown <[email protected]> |
@@ -70,20 +71,25 @@ def test_pep621(sdist_full_metadata): |
70 | 71 | An example package with all of the PEP 621 metadata! |
71 | 72 | ''')) |
72 | 73 |
|
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 |
76 | 82 |
|
77 | 83 |
|
78 | 84 | def test_dynamic_version(sdist_dynamic_version): |
79 | 85 | with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist: |
80 | 86 | sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode() |
81 | 87 |
|
82 | | - assert sdist_pkg_info == textwrap.dedent('''\ |
| 88 | + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ |
83 | 89 | Metadata-Version: 2.1 |
84 | 90 | Name: dynamic-version |
85 | 91 | Version: 1.0.0 |
86 | | - ''') |
| 92 | + ''')) |
87 | 93 |
|
88 | 94 |
|
89 | 95 | def test_contents(sdist_library): |
|
0 commit comments