Skip to content

Commit

Permalink
Raise a ValueError when author name has invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
yamagen0915 committed Jun 26, 2020
1 parent 808fd81 commit 6a0ac4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
6 changes: 2 additions & 4 deletions poetry/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ def _get_author(self): # type: () -> dict
m = AUTHOR_REGEX.match(self._authors[0])

if m is None:
logger.warning(
raise ValueError(
"Invalid author string. Must be in the format: "
"John Smith <john@example.com>"
)
return {"name": None, "email": None}

name = m.group("name")
email = m.group("email")
Expand All @@ -181,11 +180,10 @@ def _get_maintainer(self): # type: () -> dict
m = AUTHOR_REGEX.match(self._maintainers[0])

if m is None:
logger.warning(
raise ValueError(
"Invalid maintainer string. Must be in the format: "
"John Smith <john@example.com>"
)
return {"name": None, "email": None}

name = m.group("name")
email = m.group("email")
Expand Down
13 changes: 11 additions & 2 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ def test_package_authors():
assert package.author_name == "John Doe"
assert package.author_email is None


def test_package_authors_invalid():
package = Package("foo", "0.1.0")

package.authors.insert(0, "<John Doe")
assert package.author_name is None
assert package.author_email is None
with pytest.raises(ValueError) as e:
package.author_name

assert (
str(e.value)
== "Invalid author string. Must be in the format: John Smith <john@example.com>"
)


@pytest.mark.parametrize("category", ["main", "dev"])
Expand Down

0 comments on commit 6a0ac4a

Please sign in to comment.