From a3206073b87a8e939cf699777882ebfaced689a0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 25 Jun 2024 12:43:02 -0400 Subject: [PATCH] Split test for no_metadata and unrecognized_version. --- tests/test_package.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test_package.py b/tests/test_package.py index 221b33c2..3c6b1091 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -383,11 +383,6 @@ def test_fips_metadata_excludes_md5_and_blake2(monkeypatch): @pytest.mark.parametrize( "read_data, missing_fields", [ - pytest.param( - b"Metadata-Version: 102.3\nName: test-package\nVersion: 1.0.0\n", - "Name, Version", - id="unsupported Metadata-Version", - ), pytest.param( b"Metadata-Version: 2.3\nName: UNKNOWN\nVersion: UNKNOWN\n", "Name, Version", @@ -421,10 +416,7 @@ def test_fips_metadata_excludes_md5_and_blake2(monkeypatch): ], ) 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. - """ + """Raise an exception when pkginfo can't interpret the metadata.""" monkeypatch.setattr(package_file.wheel.Wheel, "read", lambda _: read_data) filename = "tests/fixtures/twine-1.5.0-py2.py3-none-any.whl" @@ -434,6 +426,17 @@ def test_pkginfo_returns_no_metadata(read_data, missing_fields, monkeypatch): assert ( f"Metadata is missing required fields: {missing_fields}." in err.value.args[0] ) + + +def test_pkginfo_unrecognized_version(monkeypatch): + """Raise an exception when pkginfo doesn't recognize the version.""" + data = b"Metadata-Version: 102.3\nName: test-package\nVersion: 1.0.0\n" + monkeypatch.setattr(package_file.wheel.Wheel, "read", lambda _: 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 "1.0, 1.1, 1.2, 2.0, 2.1, 2.2" in err.value.args[0]