1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
# stdlib
from textwrap import dedent
from typing import Tuple
# 3rd party
import pytest
from coincidence import AdvancedFileRegressionFixture
from domdf_python_tools.paths import PathPlus
# this package
from dist_meta import wheel
from dist_meta.metadata import MissingFieldError
from dist_meta.metadata_mapping import MetadataMapping
def test_loads():
wheel_content = dedent(
"""
Wheel-Version: 1.0
Generator: bdist_wheel (0.36.2)
Root-Is-Purelib: true
Tag: py3-none-any
Tag: py2-none-any
\r"""
)
fields = wheel.loads(wheel_content)
assert fields.keys() == ["Wheel-Version", "Generator", "Root-Is-Purelib", "Tag", "Tag"]
assert fields["Wheel-Version"] == "1.0"
assert fields["Generator"] == "bdist_wheel (0.36.2)"
assert fields["Root-Is-Purelib"] == "true"
assert fields.get_all("Tag") == ["py3-none-any", "py2-none-any"]
def test_load(tmp_pathplus: PathPlus):
(tmp_pathplus / "WHEEL").write_lines([
"Wheel-Version: 1.0",
"Generator: bdist_wheel (0.36.2)",
"Root-Is-Purelib: true",
"Tag: py3-none-any",
"Tag: py2-none-any",
])
fields = wheel.load(tmp_pathplus / "WHEEL")
assert fields.keys() == ["Wheel-Version", "Generator", "Root-Is-Purelib", "Tag", "Tag"]
assert fields["Wheel-Version"] == "1.0"
assert fields["Generator"] == "bdist_wheel (0.36.2)"
assert fields["Root-Is-Purelib"] == "true"
assert fields.get_all("Tag") == ["py3-none-any", "py2-none-any"]
def test_load_no_version(tmp_pathplus: PathPlus):
(tmp_pathplus / "WHEEL").write_lines([
"Generator: bdist_wheel (0.36.2)",
"Root-Is-Purelib: true",
"Tag: py3-none-any",
"Tag: py2-none-any",
])
with pytest.raises(MissingFieldError, match=f"No 'Wheel-Version' field was provided."):
wheel.load(tmp_pathplus / "WHEEL")
fields = MetadataMapping()
fields["Wheel-Version"] = "1.0"
fields["Generator"] = "bdist_wheel (0.36.2)"
fields["Root-Is-Purelib"] = "true"
fields["Tag"] = "py3-none-any"
fields["Tag"] = "py2-none-any"
fields_no_root_is_purelib = MetadataMapping()
fields_no_root_is_purelib["Wheel-Version"] = 1.0 # type: ignore[assignment]
fields_no_root_is_purelib["Generator"] = "bdist_wheel (0.36.2)"
fields_no_root_is_purelib["Tag"] = "py3-none-any"
fields_no_root_is_purelib["Tag"] = "py2-none-any"
fields_dict = {
"Wheel-Version": 1.0,
"Generator": "bdist_wheel (0.36.2)",
"Root-Is-Purelib": True,
"Tag": ["py3-none-any", "py2-none-any"],
}
fields_dict_no_root_is_purelib = {
"Wheel-Version": "1.0",
"Generator": "bdist_wheel (0.36.2)",
"Tag": ["py3-none-any", "py2-none-any"],
}
@pytest.mark.parametrize(
"fields",
[
pytest.param(fields, id="fields"),
pytest.param(fields_no_root_is_purelib, id="fields_no_root_is_purelib"),
pytest.param(fields_dict, id="fields_dict"),
pytest.param(fields_dict_no_root_is_purelib, id="fields_dict_no_root_is_purelib"),
]
)
def test_dumps(fields: MetadataMapping, advanced_file_regression: AdvancedFileRegressionFixture):
advanced_file_regression.check(wheel.dumps(fields), extension='')
@pytest.mark.parametrize(
"fields",
[
pytest.param(fields, id="fields"),
pytest.param(fields_no_root_is_purelib, id="fields_no_root_is_purelib"),
pytest.param(fields_dict, id="fields_dict"),
pytest.param(fields_dict_no_root_is_purelib, id="fields_dict_no_root_is_purelib"),
]
)
def test_dump(
fields: MetadataMapping,
tmp_pathplus: PathPlus,
advanced_file_regression: AdvancedFileRegressionFixture,
):
wheel.dump(fields, tmp_pathplus / "WHEEL")
advanced_file_regression.check_file(tmp_pathplus / "WHEEL")
def test_dump_no_version(tmp_pathplus: PathPlus):
fields = MetadataMapping()
fields["Generator"] = "bdist_wheel (0.36.2)"
fields["Root-Is-Purelib"] = "true"
fields["Tag"] = "py3-none-any"
fields["Tag"] = "py2-none-any"
with pytest.raises(MissingFieldError, match=f"No 'Wheel-Version' field was provided."):
wheel.dump(fields, tmp_pathplus / "WHEEL")
assert not (tmp_pathplus / "WHEEL").exists()
@pytest.mark.parametrize(
"generator, expected",
[
("bdist_wheel (0.34.2)", ("bdist_wheel", "0.34.2")),
("bdist_wheel (0.36.2)", ("bdist_wheel", "0.36.2")),
("bdist_wheel (0.37.0)", ("bdist_wheel", "0.37.0")),
("poetry 1.0.7", ("poetry", "1.0.7")),
("poetry-core 1.1.0", ("poetry-core", "1.1.0")),
("skbuild 0.15.0", ("skbuild", "0.15.0")),
("hatchling 1.10.0", ("hatchling", "1.10.0")),
("flit 3.5.1", ("flit", "3.5.1")),
("flit 3.7.1", ("flit", "3.7.1")),
("act (2.2)", ("act", "2.2")),
("foo", ("foo", None)),
("pdm-pep517 0.12.7", ("pdm-pep517", "0.12.7")),
]
)
def test_parse_generator_string(generator: str, expected: Tuple[str, str]):
assert wheel.parse_generator_string(generator) == expected
|