Skip to content

Commit

Permalink
TST: adjust for changes in pyproject-metadata 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Oct 12, 2024
1 parent 35f2842 commit b775f74
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ dynamic = [
[project.optional-dependencies]
test = [
'build',
'packaging >= 23.1',
'pytest >= 6.0',
'pytest-cov[toml]',
'pytest-mock',
Expand Down
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@
from venv import EnvBuilder

import packaging.version
import packaging.metadata

import pytest

import mesonpy

from mesonpy._util import chdir


def metadata(data):
meta, other = packaging.metadata.parse_email(data)
assert not other
return meta


def adjust_packaging_platform_tag(platform: str) -> str:
if platform.startswith(('manylinux', 'musllinux')):
# The packaging module generates overly specific platforms tags on
Expand Down
2 changes: 2 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def test_missing_version(package_missing_version):
re.escape('Required "project.version" field is missing'),
# pyproject-metatadata 0.8.0 and later
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
# pyproject-metatadata 0.9.0 and later
re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'),
))
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
Metadata.from_pyproject(pyproject, pathlib.Path())
30 changes: 18 additions & 12 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@

import os
import pathlib
import re
import stat
import sys
import tarfile
import textwrap
import time

from itertools import chain

import pytest

import mesonpy

from .conftest import in_git_repo_context
from .conftest import in_git_repo_context, metadata


def test_no_pep621(sdist_library):
with tarfile.open(sdist_library, 'r:gz') as sdist:
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()

assert sdist_pkg_info == textwrap.dedent('''\
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
Metadata-Version: 2.1
Name: library
Version: 1.0.0
''')
'''))


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

metadata = re.escape(textwrap.dedent('''\
expected = metadata(textwrap.dedent('''\
Metadata-Version: 2.1
Name: full-metadata
Version: 1.2.3
Summary: Some package with all of the PEP 621 metadata
Keywords: full metadata
Keywords: full, metadata
Home-page: https://example.com
Author: Jane Doe
Author-Email: Unknown <jhon.doe@example.com>
Expand Down Expand Up @@ -70,20 +71,25 @@ def test_pep621(sdist_full_metadata):
An example package with all of the PEP 621 metadata!
'''))

# pyproject-metadata 0.8.0 and later uses a comma to separate keywords
expr = metadata.replace(r'Keywords:\ full\ metadata', r'Keywords:\ full[ ,]metadata')
assert re.fullmatch(expr, sdist_pkg_info)
meta = metadata(sdist_pkg_info)

# pyproject-metadata prior to 0.8.0 incorrectly uses whitespace to separate keywords
meta['keywords'] = list(chain(*(k.split(' ') for k in meta['keywords'])))
# pyproject-metadata prior to 0.9.0 strips trailing newlines
meta['license'] = meta['license'].rstrip()

assert meta == expected


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

assert sdist_pkg_info == textwrap.dedent('''\
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
Metadata-Version: 2.1
Name: dynamic-version
Version: 1.0.0
''')
'''))


def test_contents(sdist_library):
Expand Down

0 comments on commit b775f74

Please sign in to comment.