Skip to content

Commit

Permalink
Rework metadata test
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Jan 22, 2022
1 parent b1d69e1 commit c2ed7f7
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,45 @@ def test_fips_metadata_excludes_md5_and_blake2(monkeypatch):
assert "blake2_256_digest" not in mddict


def test_pkginfo_returns_no_metadata(monkeypatch):
@pytest.mark.parametrize(
"read_data, missing_fields",
[
pytest.param(
b"Metadata-Version: 2.3\nName: test-package\nVersion: 1.0.0\n",
"Name, Version",
id="unsupported Metadata-Version",
),
pytest.param(
b"Metadata-Version: 2.2\nName: UNKNOWN\nVersion: UNKNOWN\n",
"Name, Version",
id="missing Name and Version",
),
pytest.param(
b"Metadata-Version: 2.2\nName: UNKNOWN\nVersion: 1.0.0\n",
"Name",
id="missing Name",
),
pytest.param(
b"Metadata-Version: 2.2\nName: test-package\nVersion: UNKNOWN\n",
"Version",
id="missing Version",
),
],
)
def test_pkginfo_returns_no_metadata(read_data, missing_fields, monkeypatch):
"""Raise an exception when pkginfo can't interpret the metadata.
This could be caused by a version number or format it doesn't support yet.
"""

def EmptyDist(filename):
return pretend.stub(name=None, version=None)

monkeypatch.setattr(package_file, "DIST_TYPES", {"bdist_wheel": EmptyDist})
monkeypatch.setattr(package_file.wheel.Wheel, "read", lambda _: read_data)
filename = "tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"

with pytest.raises(exceptions.InvalidDistribution) as err:
package_file.PackageFile.from_filename(filename, comment=None)

assert (
"Distribution metadata is missing required fields: Name, Version."
f"Distribution metadata is missing required fields: {missing_fields}."
in err.value.args[0]
)
assert "1.0, 1.1, 1.2, 2.0, 2.1, 2.2" in err.value.args[0]
Expand Down

0 comments on commit c2ed7f7

Please sign in to comment.