Skip to content

Commit

Permalink
fix: widen author name regex and introduce tests (#411)
Browse files Browse the repository at this point in the history
Support for names such as :Barry-Thomas-Paul: Moss

Co-authored-by: Bartosz Sokorski <[email protected]>
  • Loading branch information
Amourspirit and Secrus authored Sep 3, 2022
1 parent 323e277 commit e3ea1b1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

T = TypeVar("T", bound="Package")

AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"()&]+)(?: <(?P<email>.+?)>)?$")
AUTHOR_REGEX = re.compile(r"(?u)^(?P<name>[- .,\w\d'’\"():&]+)(?: <(?P<email>.+?)>)?$")


class Package(PackageSpecification):
Expand Down
52 changes: 52 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,58 @@ def test_package_authors_invalid() -> None:
)


@pytest.mark.parametrize(
("name", "email"),
[
("Sébastien Eustace", "[email protected]"),
("John Doe", None),
("'Jane Doe'", None),
('"Jane Doe"', None),
("MyCompany", None),
("Some Company’s", None),
("MyCompany's R&D", "[email protected]"),
("Doe, John", None),
("(Doe, John)", None),
("John Doe", "[email protected]"),
("Doe, John", "[email protected]"),
("MyCompanyName R&D", "[email protected]"),
("John-Paul: Doe", None),
("John-Paul: Doe", "[email protected]"),
("John Doe the 3rd", "[email protected]"),
],
)
def test_package_authors_valid(name: str, email: str | None) -> None:
package = Package("foo", "0.1.0")

if email is None:
author = name
else:
author = f"{name} <{email}>"
package.authors.insert(0, author)
assert package.author_name == name
assert package.author_email == email


@pytest.mark.parametrize(
("name",),
[
("<[email protected]>",),
("[email protected]",),
("<John Doe",),
("John? Doe",),
("Jane+Doe",),
("~John Doe",),
("John~Doe",),
],
)
def test_package_author_names_invalid(name: str) -> None:
package = Package("foo", "0.1.0")

package.authors.insert(0, name)
with pytest.raises(ValueError):
package.author_name


@pytest.mark.parametrize("groups", [["main"], ["dev"]])
def test_package_add_dependency_vcs_groups(groups: list[str], f: Factory) -> None:
package = Package("foo", "0.1.0")
Expand Down

0 comments on commit e3ea1b1

Please sign in to comment.