Skip to content

Commit 057e290

Browse files
authored
Merge pull request #24 from simple-repository/feature/improved-testing
Add a test for the fetch_description behaviour, and adapt for simple-repository v0.10
2 parents a16ae33 + 06666e1 commit 057e290

File tree

4 files changed

+122
-4
lines changed

4 files changed

+122
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies = [
2626
"parsley",
2727
"pkginfo>=1.12",
2828
"readme-renderer[md]",
29-
"simple-repository~=0.9",
29+
"simple-repository~=0.10",
3030
"typing-extensions",
3131
"uvicorn",
3232
"authlib",

simple_repository_browser/fetch_description.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ def _enhance_author_maintainer_info(info: pkginfo.Distribution) -> None:
214214

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

simple_repository_browser/filesize_enrichment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async def get_project_page(
5656
self,
5757
project_name: str,
5858
*,
59-
request_context: model.RequestContext = model.RequestContext.DEFAULT,
59+
request_context: model.RequestContext | None = None,
6060
) -> model.ProjectDetail:
6161
"""
6262
Get project page with file sizes enriched.
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import pkginfo
2+
import pytest
3+
4+
from ..fetch_description import _enhance_author_maintainer_info
5+
6+
7+
@pytest.mark.parametrize(
8+
[
9+
"author",
10+
"author_email",
11+
"maintainer",
12+
"maintainer_email",
13+
"expected_author",
14+
"expected_maintainer",
15+
],
16+
[
17+
# Test extracting author from email when no author
18+
(None, "John Doe <[email protected]>", None, None, "John Doe", None),
19+
# Test extracting maintainer from email when no maintainer
20+
(None, None, None, "Jane Smith <[email protected]>", None, "Jane Smith"),
21+
# Test extracting both author and maintainer
22+
(
23+
None,
24+
"John Doe <[email protected]>",
25+
None,
26+
"Jane Smith <[email protected]>",
27+
"John Doe",
28+
"Jane Smith",
29+
),
30+
# Test preserving existing author name
31+
(
32+
"Existing Author",
33+
"John Doe <[email protected]>",
34+
None,
35+
None,
36+
"Existing Author",
37+
None,
38+
),
39+
# Test preserving existing maintainer name
40+
(
41+
None,
42+
None,
43+
"Existing Maintainer",
44+
"Jane Smith <[email protected]>",
45+
None,
46+
"Existing Maintainer",
47+
),
48+
# Test handling empty author email
49+
(None, "", None, None, None, None),
50+
# Test handling None author email
51+
(None, None, None, None, None, None),
52+
# Test handling multiple emails
53+
(
54+
None,
55+
"John Doe <[email protected]>, Jane Smith <[email protected]>",
56+
None,
57+
None,
58+
"John Doe, Jane Smith",
59+
None,
60+
),
61+
# Test handling email without display name
62+
(None, "[email protected]", None, None, "", None),
63+
# Test handling mixed email formats
64+
(
65+
None,
66+
67+
None,
68+
None,
69+
"John Doe, ",
70+
None,
71+
),
72+
# Test handling empty string author (should be treated as missing)
73+
("", "John Doe <[email protected]>", None, None, "John Doe", None),
74+
# Test handling empty string maintainer (should be treated as missing)
75+
(None, None, "", "Jane Smith <[email protected]>", None, "Jane Smith"),
76+
# Test complex real-world scenario
77+
(
78+
"",
79+
"John Doe <[email protected]>, Support Team <[email protected]>",
80+
"",
81+
"Jane Smith <[email protected]>",
82+
"John Doe, Support Team",
83+
"Jane Smith",
84+
),
85+
# Test whitespace in emails
86+
(None, " John Doe <[email protected]> ", None, None, "John Doe", None),
87+
# Test no changes needed
88+
(
89+
"John Doe",
90+
91+
"Jane Smith",
92+
93+
"John Doe",
94+
"Jane Smith",
95+
),
96+
],
97+
)
98+
def test_enhance_author_maintainer_info(
99+
author,
100+
author_email,
101+
maintainer,
102+
maintainer_email,
103+
expected_author,
104+
expected_maintainer,
105+
):
106+
"""Test _enhance_author_maintainer_info with various email and name combinations."""
107+
# Create a real pkginfo.Distribution instance
108+
info = pkginfo.Distribution()
109+
info.name = "test-package"
110+
info.author = author
111+
info.author_email = author_email
112+
info.maintainer = maintainer
113+
info.maintainer_email = maintainer_email
114+
115+
_enhance_author_maintainer_info(info)
116+
117+
assert info.author == expected_author
118+
assert info.maintainer == expected_maintainer

0 commit comments

Comments
 (0)