Skip to content

Commit

Permalink
TST: move tests building sdists from test_metadata to test_sdist
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi authored and rgommers committed Oct 7, 2023
1 parent 33cc0e1 commit bf3386c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 66 deletions.
66 changes: 0 additions & 66 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# SPDX-License-Identifier: MIT

import pathlib
import tarfile
import textwrap

import packaging.version
import pyproject_metadata
Expand Down Expand Up @@ -34,67 +32,3 @@ def test_package_name_from_pyproject():
def test_package_name_invalid():
with pytest.raises(pyproject_metadata.ConfigurationError, match='Invalid project name'):
Metadata(name='.test', version=packaging.version.Version('0.0.1'))


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('''\
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()

assert sdist_pkg_info == 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
Home-page: https://example.com
Author: Jane Doe
Author-Email: Unknown <[email protected]>
Maintainer-Email: Jane Doe <[email protected]>
License: some license
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Project-URL: Homepage, https://example.com
Project-URL: Documentation, https://readthedocs.org
Project-URL: Repository, https://github.com/mesonbuild/meson-python
Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
Requires-Python: >=3.7
Requires-Dist: a
Requires-Dist: b>1
Requires-Dist: c>2; os_name != "nt"
Requires-Dist: d<3; extra == "test"
Requires-Dist: e[all]; extra == "test"
Provides-Extra: test
Description-Content-Type: text/markdown
<!--
SPDX-FileCopyrightText: 2021 The meson-python developers
SPDX-License-Identifier: MIT
-->
# full-metadata
An example package with all of the PEP 621 metadata!
''')


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('''\
Metadata-Version: 2.1
Name: dynamic-version
Version: 1.0.0
''')
64 changes: 64 additions & 0 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,70 @@
from .conftest import in_git_repo_context


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('''\
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()

assert sdist_pkg_info == 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
Home-page: https://example.com
Author: Jane Doe
Author-Email: Unknown <[email protected]>
Maintainer-Email: Jane Doe <[email protected]>
License: some license
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python
Project-URL: Homepage, https://example.com
Project-URL: Documentation, https://readthedocs.org
Project-URL: Repository, https://github.com/mesonbuild/meson-python
Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
Requires-Python: >=3.7
Requires-Dist: a
Requires-Dist: b>1
Requires-Dist: c>2; os_name != "nt"
Requires-Dist: d<3; extra == "test"
Requires-Dist: e[all]; extra == "test"
Provides-Extra: test
Description-Content-Type: text/markdown
<!--
SPDX-FileCopyrightText: 2021 The meson-python developers
SPDX-License-Identifier: MIT
-->
# full-metadata
An example package with all of the PEP 621 metadata!
''')


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('''\
Metadata-Version: 2.1
Name: dynamic-version
Version: 1.0.0
''')


def test_contents(sdist_library):
with tarfile.open(sdist_library, 'r:gz') as sdist:
names = {member.name for member in sdist.getmembers()}
Expand Down

0 comments on commit bf3386c

Please sign in to comment.