Skip to content

Commit b75d773

Browse files
committed
tests: tests from pyproject-metadata
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 880bf04 commit b75d773

File tree

24 files changed

+1633
-14
lines changed

24 files changed

+1633
-14
lines changed

src/packaging/_pyproject.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
from .errors import ErrorCollector
1515

16-
if typing.TYPE_CHECKING:
16+
if typing.TYPE_CHECKING: # pragma: no cover
1717
from collections.abc import Generator, Iterable, Sequence
1818

1919
from .project_table import ContactTable, Dynamic, ProjectTable
@@ -26,10 +26,6 @@
2626
]
2727

2828

29-
def __dir__() -> list[str]:
30-
return __all__
31-
32-
3329
@dataclasses.dataclass(frozen=True)
3430
class License:
3531
"""

src/packaging/errors.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import dataclasses
55
import sys
66
from collections.abc import Generator
7-
from typing import Any, NoReturn
7+
from typing import Any
88

99
__all__ = ["ExceptionGroup", "ConfigurationError", "ConfigurationWarning"]
1010

@@ -75,9 +75,10 @@ def config_error(
7575

7676
self.errors.append(ConfigurationError(msg, key=key))
7777

78-
def finalize(self, msg: str) -> NoReturn:
78+
def finalize(self, msg: str) -> None:
7979
"""Raise a group exception if there are any errors."""
80-
raise ExceptionGroup(msg, self.errors)
80+
if self.errors:
81+
raise ExceptionGroup(msg, self.errors)
8182

8283
@contextlib.contextmanager
8384
def collect(self) -> Generator[None, None, None]:

src/packaging/project.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
import sys
1616
import typing
1717
import warnings
18+
from collections.abc import Sequence
1819

1920
from . import markers, specifiers, utils
2021
from . import metadata as packaging_metadata
2122
from . import version as packaging_version
2223
from ._pyproject import License, PyProjectReader, Readme
2324
from .errors import ConfigurationError, ConfigurationWarning, ErrorCollector
2425

25-
if typing.TYPE_CHECKING:
26+
if typing.TYPE_CHECKING: # pragma: no cover
2627
from collections.abc import Mapping
2728
from typing import Any
2829

@@ -143,7 +144,7 @@ def from_pyproject(
143144
Read metadata from a pyproject.toml table. This is the main method for
144145
creating an instance of this class. It also supports two additional
145146
fields: ``allow_extra_keys`` to control what happens when extra keys are
146-
present in the pyproject table, and ``all_errors``, to raise all errors
147+
present in the pyproject table, and ``all_errors``, to raise all errors
147148
in an ExceptionGroup instead of raising the first one.
148149
"""
149150
pyproject = PyProjectReader()
@@ -368,7 +369,7 @@ def validate(self) -> None:
368369
errors.finalize("[project] table validation failed")
369370

370371
def metadata(
371-
self, metadata_version: str, dynamic_metadata: list[str]
372+
self, *, metadata_version: str, dynamic_metadata: Sequence[str] = ()
372373
) -> packaging_metadata.Metadata:
373374
"""
374375
Return an Message with the metadata.
@@ -431,8 +432,8 @@ def metadata(
431432
message["requires_dist"] = [str(d) for d in self.dependencies]
432433
for extra, requirements in self.optional_dependencies.items():
433434
norm_extra = extra.replace(".", "-").replace("_", "-").lower()
434-
message.get("provides_extra", []).append(norm_extra)
435-
message.get("requires_dist", []).extend(
435+
message.setdefault("provides_extra", []).append(norm_extra)
436+
message.setdefault("requires_dist", []).extend(
436437
str(_build_extra_req(norm_extra, requirement))
437438
for requirement in requirements
438439
)
@@ -449,7 +450,7 @@ def metadata(
449450
if field.lower() not in packaging_metadata.ALL_FIELDS:
450451
msg = f"Field is not known: {field}"
451452
raise ConfigurationError(msg)
452-
message["dynamic"] = dynamic_metadata
453+
message["dynamic"] = list(dynamic_metadata)
453454

454455
return packaging_metadata.Metadata.from_raw(message)
455456

tests/project/dynamic-description/dynamic_description.py

Whitespace-only changes.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[project]
2+
name = 'dynamic-description'
3+
version = '1.0.0'
4+
dynamic = [
5+
'description',
6+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some readme 👋

tests/project/full-metadata/full_metadata.py

Whitespace-only changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[project]
2+
name = 'full_metadata'
3+
version = '3.2.1'
4+
description = 'A package with all the metadata :)'
5+
readme = 'README.md'
6+
license = { text = 'some license text' }
7+
keywords = ['trampolim', 'is', 'interesting']
8+
authors = [
9+
{ email = '[email protected]' },
10+
{ name = 'Example!' },
11+
]
12+
maintainers = [
13+
{ name = 'Other Example', email = '[email protected]' },
14+
]
15+
classifiers = [
16+
'Development Status :: 4 - Beta',
17+
'Programming Language :: Python',
18+
]
19+
20+
requires-python = '>=3.8'
21+
dependencies = [
22+
'dependency1',
23+
'dependency2>1.0.0',
24+
'dependency3[extra]',
25+
'dependency4; os_name != "nt"',
26+
'dependency5[other-extra]>1.0; os_name == "nt"',
27+
]
28+
29+
[project.optional-dependencies]
30+
test = [
31+
'test_dependency',
32+
'test_dependency[test_extra]',
33+
'test_dependency[test_extra2] > 3.0; os_name == "nt"',
34+
]
35+
36+
[project.urls]
37+
homepage = 'example.com'
38+
documentation = 'readthedocs.org'
39+
repository = 'github.com/some/repo'
40+
changelog = 'github.com/some/repo/blob/master/CHANGELOG.rst'
41+
42+
[project.scripts]
43+
full-metadata = 'full_metadata:main_cli'
44+
45+
[project.gui-scripts]
46+
full-metadata-gui = 'full_metadata:main_gui'
47+
48+
[project.entry-points.custom]
49+
full-metadata = 'full_metadata:main_custom'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some license! 👋
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
some readme 👋

0 commit comments

Comments
 (0)