Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"parsley",
"pkginfo>=1.12",
"readme-renderer[md]",
"simple-repository~=0.9",
"simple-repository~=0.10",
"typing-extensions",
"uvicorn",
"authlib",
Expand Down
4 changes: 2 additions & 2 deletions simple_repository_browser/fetch_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ def _enhance_author_maintainer_info(info: pkginfo.Distribution) -> None:

def extract_usernames(emails: str) -> str:
names = []
parsed = email.parser.Parser(policy=email.policy.default).parsestr(
parsed = email.parser.Parser(policy=email.policy.default).parsestr( # type: ignore[arg-type]
f"To: {emails}",
)
for address in parsed["to"].addresses:
for address in getattr(parsed["to"], "addresses", []):
names.append(address.display_name)
return ", ".join(names)

Expand Down
2 changes: 1 addition & 1 deletion simple_repository_browser/filesize_enrichment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def get_project_page(
self,
project_name: str,
*,
request_context: model.RequestContext = model.RequestContext.DEFAULT,
request_context: model.RequestContext | None = None,
) -> model.ProjectDetail:
"""
Get project page with file sizes enriched.
Expand Down
118 changes: 118 additions & 0 deletions simple_repository_browser/tests/test_fetch_description.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import pkginfo
import pytest

from ..fetch_description import _enhance_author_maintainer_info


@pytest.mark.parametrize(
[
"author",
"author_email",
"maintainer",
"maintainer_email",
"expected_author",
"expected_maintainer",
],
[
# Test extracting author from email when no author
(None, "John Doe <[email protected]>", None, None, "John Doe", None),
# Test extracting maintainer from email when no maintainer
(None, None, None, "Jane Smith <[email protected]>", None, "Jane Smith"),
# Test extracting both author and maintainer
(
None,
"John Doe <[email protected]>",
None,
"Jane Smith <[email protected]>",
"John Doe",
"Jane Smith",
),
# Test preserving existing author name
(
"Existing Author",
"John Doe <[email protected]>",
None,
None,
"Existing Author",
None,
),
# Test preserving existing maintainer name
(
None,
None,
"Existing Maintainer",
"Jane Smith <[email protected]>",
None,
"Existing Maintainer",
),
# Test handling empty author email
(None, "", None, None, None, None),
# Test handling None author email
(None, None, None, None, None, None),
# Test handling multiple emails
(
None,
"John Doe <[email protected]>, Jane Smith <[email protected]>",
None,
None,
"John Doe, Jane Smith",
None,
),
# Test handling email without display name
(None, "[email protected]", None, None, "", None),
# Test handling mixed email formats
(
None,
"John Doe <[email protected]>, [email protected]",
None,
None,
"John Doe, ",
None,
),
# Test handling empty string author (should be treated as missing)
("", "John Doe <[email protected]>", None, None, "John Doe", None),
# Test handling empty string maintainer (should be treated as missing)
(None, None, "", "Jane Smith <[email protected]>", None, "Jane Smith"),
# Test complex real-world scenario
(
"",
"John Doe <[email protected]>, Support Team <[email protected]>",
"",
"Jane Smith <[email protected]>",
"John Doe, Support Team",
"Jane Smith",
),
# Test whitespace in emails
(None, " John Doe <[email protected]> ", None, None, "John Doe", None),
# Test no changes needed
(
"John Doe",
"[email protected]",
"Jane Smith",
"[email protected]",
"John Doe",
"Jane Smith",
),
],
)
def test_enhance_author_maintainer_info(
author,
author_email,
maintainer,
maintainer_email,
expected_author,
expected_maintainer,
):
"""Test _enhance_author_maintainer_info with various email and name combinations."""
# Create a real pkginfo.Distribution instance
info = pkginfo.Distribution()
info.name = "test-package"
info.author = author
info.author_email = author_email
info.maintainer = maintainer
info.maintainer_email = maintainer_email

_enhance_author_maintainer_info(info)

assert info.author == expected_author
assert info.maintainer == expected_maintainer