|
14 | 14 | import json
|
15 | 15 | import string
|
16 | 16 |
|
| 17 | +import packaging |
17 | 18 | import pretend
|
18 | 19 | import pytest
|
19 | 20 | from packaging import metadata
|
| 21 | +from packaging import version |
20 | 22 |
|
21 | 23 | from twine import exceptions
|
22 | 24 | from twine import package as package_file
|
@@ -175,6 +177,10 @@ def test_package_safe_name_is_correct(pkg_name, expected_name):
|
175 | 177 | def test_metadata_keys_consistency():
|
176 | 178 | """Check that the translation keys exist in the respective ``TypedDict``."""
|
177 | 179 | raw_keys = metadata.RawMetadata.__annotations__.keys()
|
| 180 | + if version.Version(packaging.__version__) < version.Version("24.1"): |
| 181 | + # ``packaging`` version 24.0 and earlier do not know about the |
| 182 | + # License-Expression and License-File metadata fields yet. |
| 183 | + raw_keys = raw_keys | set(("license_files", "license_expression")) |
178 | 184 | assert set(package_file._RAW_TO_PACKAGE_METADATA.keys()).issubset(raw_keys)
|
179 | 185 | package_keys = package_file.PackageMetadata.__annotations__.keys()
|
180 | 186 | assert set(package_file._RAW_TO_PACKAGE_METADATA.values()).issubset(package_keys)
|
@@ -434,32 +440,36 @@ def test_package_from_unrecognized_file_error():
|
434 | 440 | assert "Unknown distribution format" in err.value.args[0]
|
435 | 441 |
|
436 | 442 |
|
437 |
| -@pytest.mark.parametrize( |
438 |
| - "read_data, filtered", |
439 |
| - [ |
440 |
| - pytest.param( |
441 |
| - "Metadata-Version: 2.1\n" |
442 |
| - "Name: test-package\n" |
443 |
| - "Version: 1.0.0\n" |
444 |
| - "License-File: LICENSE\n", |
445 |
| - True, |
446 |
| - id="invalid License-File", |
447 |
| - ), |
448 |
| - pytest.param( |
449 |
| - "Metadata-Version: 2.4\n" |
450 |
| - "Name: test-package\n" |
451 |
| - "Version: 1.0.0\n" |
452 |
| - "License-File: LICENSE\n", |
453 |
| - False, |
454 |
| - id="valid License-File", |
455 |
| - ), |
456 |
| - ], |
457 |
| -) |
458 |
| -def test_setuptools_license_file(read_data, filtered, monkeypatch): |
| 443 | +def test_setuptools_license_file_invalid(monkeypatch): |
459 | 444 | """Drop License-File metadata entries if Metadata-Version is less than 2.4."""
|
| 445 | + read_data = ( |
| 446 | + "Metadata-Version: 2.1\n" |
| 447 | + "Name: test-package\n" |
| 448 | + "Version: 1.0.0\n" |
| 449 | + "License-File: LICENSE\n" |
| 450 | + ) |
| 451 | + monkeypatch.setattr(package_file.wheel.Wheel, "read", lambda _: read_data) |
| 452 | + filename = "tests/fixtures/twine-1.5.0-py2.py3-none-any.whl" |
| 453 | + |
| 454 | + package = package_file.PackageFile.from_filename(filename, comment=None) |
| 455 | + meta = package.metadata_dictionary() |
| 456 | + assert "license_file" not in meta |
| 457 | + |
| 458 | + |
| 459 | +@pytest.mark.skipif( |
| 460 | + version.Version(packaging.__version__) < version.Version("24.1"), |
| 461 | + reason="packaging is too old", |
| 462 | +) |
| 463 | +def test_setuptools_license_file_valid(monkeypatch): |
| 464 | + read_data = ( |
| 465 | + "Metadata-Version: 2.1\n" |
| 466 | + "Name: test-package\n" |
| 467 | + "Version: 1.0.0\n" |
| 468 | + "License-File: LICENSE\n" |
| 469 | + ) |
460 | 470 | monkeypatch.setattr(package_file.wheel.Wheel, "read", lambda _: read_data)
|
461 | 471 | filename = "tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"
|
462 | 472 |
|
463 | 473 | package = package_file.PackageFile.from_filename(filename, comment=None)
|
464 | 474 | meta = package.metadata_dictionary()
|
465 |
| - assert filtered != ("license_file" in meta) |
| 475 | + assert "license_file" not in meta |
0 commit comments