|
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 |
| - 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() |
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() |
| 36 | + |
| 37 | + meta = metadata(sdist_pkg_info) |
35 | 38 |
|
36 |
| - metadata = re.escape(textwrap.dedent('''\ |
| 39 | + # pyproject-metadata prior to 0.8.0 incorrectly uses whitespace to separate keywords |
| 40 | + meta['keywords'] = list(chain(*(k.split(' ') for k in meta['keywords']))) |
| 41 | + # pyproject-metadata prior to 0.9.0 strips trailing newlines |
| 42 | + meta['license'] = meta['license'].rstrip() |
| 43 | + |
| 44 | + assert meta == 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 <jhon.doe@example.com>
|
@@ -70,20 +78,16 @@ 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) |
76 |
| - |
77 | 81 |
|
78 | 82 | def test_dynamic_version(sdist_dynamic_version):
|
79 | 83 | with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
|
80 |
| - sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode() |
| 84 | + sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read() |
81 | 85 |
|
82 |
| - assert sdist_pkg_info == textwrap.dedent('''\ |
| 86 | + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ |
83 | 87 | Metadata-Version: 2.1
|
84 | 88 | Name: dynamic-version
|
85 | 89 | Version: 1.0.0
|
86 |
| - ''') |
| 90 | + ''')) |
87 | 91 |
|
88 | 92 |
|
89 | 93 | def test_contents(sdist_library):
|
|
0 commit comments