Skip to content

Commit

Permalink
Sort metadata fields in tests more rigorously
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Dec 1, 2024
1 parent 5e68bf3 commit 3631920
Showing 1 changed file with 68 additions and 65 deletions.
133 changes: 68 additions & 65 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,52 +174,51 @@ def test_package_safe_name_is_correct(pkg_name, expected_name):
def test_supported_metadata_fields():
"""Check that ``twine.package.PackageMetadata`` contains the expected fields."""
assert set(package_file.PackageMetadata.__annotations__) == {
# identify release
# Metadata 1.0 - PEP 241
"metadata_version",
"name",
"version",
# file content
"filetype",
"pyversion",
# additional meta-data
"metadata_version",
"platforms",
"summary",
"description",
"keywords",
"home_page",
"author",
"author_email",
"maintainer",
"maintainer_email",
"license",
"description",
"keywords",
"platforms",
"classifiers",
"download_url",
# Metadata 1.1 - PEP 314
"supported_platforms",
"comment",
"md5_digest",
"sha256_digest",
"blake2_256_digest",
"gpg_signature",
"attestations",
# PEP 314
"download_url",
"classifiers",
"provides",
"requires",
"obsoletes",
# Metadata 1.2
"project_urls",
# Metadata 1.2 - PEP 345
"maintainer",
"maintainer_email",
"requires_dist",
"provides_dist",
"obsoletes_dist",
"requires_dist",
"requires_external",
"requires_python",
# Metadata 2.1
"provides_extra",
"requires_external",
"project_urls",
# Metadata 2.1 - PEP 566
"description_content_type",
# Metadata 2.2
"provides_extra",
# Metadata 2.2 - PEP 643
"dynamic",
# Metadata 2.4
# Metadata 2.4 - PEP 639
"license_expression",
"license_files",
# additional meta-data
"filetype",
"pyversion",
"comment",
"md5_digest",
"sha256_digest",
"blake2_256_digest",
"gpg_signature",
"attestations",
}


Expand All @@ -228,34 +227,36 @@ def test_supported_metadata_fields():
def test_metadata_dictionary_values(gpg_signature, attestation):
"""Pass values from pkginfo.Distribution through to dictionary."""
meta = dict(
metadata_version=pretend.stub(),
name="whatever",
version="1.2.3",
metadata_version=pretend.stub(),
platform=pretend.stub(),
summary=pretend.stub(),
description=pretend.stub(),
keywords=pretend.stub(),
home_page=pretend.stub(),
author=pretend.stub(),
author_email=pretend.stub(),
maintainer=pretend.stub(),
maintainer_email=pretend.stub(),
license=pretend.stub(),
description=pretend.stub(),
keywords=pretend.stub(),
platform=pretend.stub(),
classifiers=pretend.stub(),
download_url=pretend.stub(),
supported_platform=pretend.stub(),
download_url=pretend.stub(),
classifiers=pretend.stub(),
provides=pretend.stub(),
requires=pretend.stub(),
obsoletes=pretend.stub(),
project_urls=pretend.stub(),
maintainer=pretend.stub(),
maintainer_email=pretend.stub(),
requires_dist=pretend.stub(),
provides_dist=pretend.stub(),
obsoletes_dist=pretend.stub(),
requires_dist=pretend.stub(),
requires_external=pretend.stub(),
requires_python=pretend.stub(),
provides_extra=pretend.stub(),
requires_external=pretend.stub(),
project_urls=pretend.stub(),
description_content_type=pretend.stub(),
provides_extra=pretend.stub(),
dynamic=pretend.stub(),
license_expression=pretend.stub(),
license_files=pretend.stub(),
)

package = package_file.PackageFile(
Expand All @@ -271,51 +272,53 @@ def test_metadata_dictionary_values(gpg_signature, attestation):

result = package.metadata_dictionary()

# identify release
# Medata 1.0 - PEP 241
assert result["metadata_version"] == meta["metadata_version"]
assert result["name"] == package.safe_name
assert result["version"] == package.version == meta["version"]

# file content
assert result["filetype"] == package.filetype
assert result["pyversion"] == package.python_version

# additional meta-data
assert result["metadata_version"] == meta["metadata_version"]
assert result["platform"] == meta["platform"]
assert result["summary"] == meta["summary"]
assert result["description"] == meta["description"]
assert result["keywords"] == meta["keywords"]
assert result["home_page"] == meta["home_page"]
assert result["author"] == meta["author"]
assert result["author_email"] == meta["author_email"]
assert result["maintainer"] == meta["maintainer"]
assert result["maintainer_email"] == meta["maintainer_email"]
assert result["license"] == meta["license"]
assert result["description"] == meta["description"]
assert result["keywords"] == meta["keywords"]
assert result["platform"] == meta["platform"]
assert result["classifiers"] == meta["classifiers"]
assert result["download_url"] == meta["download_url"]
assert result["supported_platform"] == meta["supported_platform"]
assert result["comment"] == package.comment

# PEP 314
# Metadata 1.1 - PEP 314
assert result["supported_platform"] == meta["supported_platform"]
assert result["download_url"] == meta["download_url"]
assert result["classifiers"] == meta["classifiers"]
assert result["provides"] == meta["provides"]
assert result["requires"] == meta["requires"]
assert result["obsoletes"] == meta["obsoletes"]

# Metadata 1.2
assert result["project_urls"] == meta["project_urls"]
# Metadata 1.2 - PEP 345
assert result["maintainer"] == meta["maintainer"]
assert result["maintainer_email"] == meta["maintainer_email"]
assert result["requires_dist"] == meta["requires_dist"]
assert result["provides_dist"] == meta["provides_dist"]
assert result["obsoletes_dist"] == meta["obsoletes_dist"]
assert result["requires_dist"] == meta["requires_dist"]
assert result["requires_external"] == meta["requires_external"]
assert result["requires_python"] == meta["requires_python"]
assert result["requires_external"] == meta["requires_external"]
assert result["project_urls"] == meta["project_urls"]

# Metadata 2.1
assert result["provides_extra"] == meta["provides_extra"]
# Metadata 2.1 - PEP 566
assert result["description_content_type"] == meta["description_content_type"]
assert result["provides_extra"] == meta["provides_extra"]

# Metadata 2.2
# Metadata 2.2 - PEP 643
assert result["dynamic"] == meta["dynamic"]

# Metadata 2.4 - PEP 639
assert result["license_expression"] == meta["license_expression"]
assert result["license_files"] == meta["license_files"]

# Additional metadata.
assert result["comment"] == package.comment
assert result["filetype"] == package.filetype
assert result["pyversion"] == package.python_version

# GPG signature
assert result.get("gpg_signature") == gpg_signature

Expand Down

0 comments on commit 3631920

Please sign in to comment.