Skip to content

Commit c730c5c

Browse files
committed
Fix: tests for the big fixed in this pr
1 parent fe3de9b commit c730c5c

File tree

5 files changed

+63
-12
lines changed

5 files changed

+63
-12
lines changed

src/pyosmeta/cli/update_review_teams.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,7 @@
3030
from pyosmeta.file_io import clean_export_yml, load_pickle
3131
from pyosmeta.github_api import GitHubAPI
3232
from pyosmeta.models import PersonModel
33-
34-
35-
def get_clean_user(username: str) -> str:
36-
"""A small helper that removes whitespace and ensures username is
37-
lower case"""
38-
# If the github username has spaces there is an error which might be
39-
# that someone added a name after the username. Only return the github
40-
# username
41-
if len(username.split()) > 1:
42-
username = username.split()[0]
43-
return username.lower().strip()
33+
from pyosmeta.utils_clean import get_clean_user
4434

4535

4636
def main():

src/pyosmeta/utils_clean.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@
99
from typing import Any
1010

1111

12+
def get_clean_user(username: str) -> str:
13+
"""Cleans a GitHub username provided in a review issue by removing any
14+
additional text after a space and converting to lowercase.
15+
16+
This function assumes that a valid username should not contain spaces. If a
17+
space is detected, only the part before the first space is considered the
18+
username. The resulting string is then trimmed of whitespace and converted
19+
to lowercase.
20+
21+
Parameters
22+
----------
23+
username : str
24+
The input username string which may contain extra text or spaces.
25+
26+
Returns
27+
-------
28+
str
29+
The cleaned username in lowercase without any extra text or spaces.
30+
31+
Examples
32+
--------
33+
>>> get_clean_user("@githubusername")
34+
'githubusername'
35+
36+
>>> get_clean_user("@githubusername name after text")
37+
'githubusername'
38+
"""
39+
40+
if len(username.split()) > 1:
41+
username = username.split()[0]
42+
return username.lower().strip()
43+
44+
1245
def clean_date(source_date: str | None) -> datetime | str:
1346
"""Cleans up a date string to a consistent datetime format.
1447

tests/unit/test_github_api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ def test_get_token(mock_github_token):
3434

3535

3636
def test_missing_token(mock_missing_github_token, tmpdir):
37-
"""Test that a keyerror is raised when the token is missing."""
37+
"""Test that a keyerror is raised when the token is missing.
38+
If you have a token in your temporary environment, this will
39+
fail and not return a keyerror."""
3840
os.chdir(tmpdir)
3941
github_api = GitHubAPI()
4042

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def get_clean_user(username: str) -> str:
2+
"""A small helper that removes whitespace and ensures username is
3+
lower case"""
4+
# If the github username has spaces there is an error which might be
5+
# that someone added a name after the username. Only return the github
6+
# username
7+
if len(username.split()) > 1:
8+
username = username.split()[0]
9+
return username.lower().strip()

tests/unit/test_utils_clean.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
clean_date_accepted_key,
88
clean_markdown,
99
clean_name,
10+
get_clean_user,
1011
)
1112

1213

@@ -84,3 +85,19 @@ def test_clean_name(input_name, expected_output):
8485
)
8586
def test_clean_date_accepted_key(input_dict, expected_output):
8687
assert clean_date_accepted_key(input_dict) == expected_output
88+
89+
90+
@pytest.mark.parametrize(
91+
"input_username, expected_output",
92+
[
93+
("githubusername", "githubusername"),
94+
("githubusername name after text", "githubusername"),
95+
("username (full name here)", "username"),
96+
("githubusername", "githubusername"),
97+
("githubusername extra text", "githubusername"),
98+
("username (just the username)", "username"),
99+
],
100+
)
101+
def test_get_clean_user(input_username, expected_output):
102+
print(input_username)
103+
assert get_clean_user(input_username) == expected_output

0 commit comments

Comments
 (0)