Skip to content

Commit 17001f8

Browse files
committed
test: harden repr assertions and sponsor_info handling
Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
1 parent 1ecbf17 commit 17001f8

4 files changed

Lines changed: 24 additions & 19 deletions

File tree

contributor_stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ def __repr__(self) -> str:
5959
f"contributor_stats(username={self.username}, "
6060
f"new_contributor={self.new_contributor}, "
6161
f"avatar_url={self.avatar_url}, "
62-
f"contribution_count={self.contribution_count}, commit_url={self.commit_url})"
62+
f"contribution_count={self.contribution_count}, "
63+
f"commit_url={self.commit_url}, "
6364
f"sponsor_info={self.sponsor_info})"
6465
)
6566

contributors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def main():
6767
)
6868

6969
# Get sponsor information on the contributor
70-
if sponsor_info == "true":
70+
if sponsor_info:
7171
contributors = contributor_stats.get_sponsor_information(
7272
contributors, token, ghe
7373
)

test_contributor_stats.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ def test_init(self):
4747

4848
def test_repr(self):
4949
"""Test the __repr__ method includes key fields."""
50-
representation = repr(self.contributor)
51-
self.assertIn("contributor_stats(username=zkoppert", representation)
52-
self.assertIn("new_contributor=False", representation)
53-
self.assertIn(
54-
"avatar_url=https://avatars.githubusercontent.com/u/29484535?v=4",
55-
representation,
50+
expected = (
51+
"contributor_stats(username=zkoppert, "
52+
"new_contributor=False, "
53+
"avatar_url=https://avatars.githubusercontent.com/u/29484535?v=4, "
54+
"contribution_count=1261, "
55+
"commit_url=commit_url5, "
56+
"sponsor_info=)"
5657
)
57-
self.assertIn("contribution_count=1261", representation)
58+
self.assertEqual(repr(self.contributor), expected)
5859

5960
def test_merge_contributors(self):
6061
"""

test_contributors.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import contributors as contributors_module
88
from contributor_stats import ContributorStats
9-
from contributors import get_all_contributors, get_contributors
109

1110

1211
class TestContributors(unittest.TestCase):
@@ -27,7 +26,7 @@ def test_get_contributors(self, mock_contributor_stats):
2726
mock_repo.contributors.return_value = [mock_user]
2827
mock_repo.full_name = "owner/repo"
2928

30-
get_contributors(mock_repo, "2022-01-01", "2022-12-31", "")
29+
contributors_module.get_contributors(mock_repo, "2022-01-01", "2022-12-31", "")
3130

3231
mock_contributor_stats.assert_called_once_with(
3332
"user",
@@ -60,7 +59,7 @@ def test_get_all_contributors_with_organization(self, mock_get_contributors):
6059
]
6160
ghe = ""
6261

63-
result = get_all_contributors(
62+
result = contributors_module.get_all_contributors(
6463
"org", "", "2022-01-01", "2022-12-31", mock_github_connection, ghe
6564
)
6665

@@ -99,7 +98,7 @@ def test_get_all_contributors_with_repository(self, mock_get_contributors):
9998
]
10099
ghe = ""
101100

102-
result = get_all_contributors(
101+
result = contributors_module.get_all_contributors(
103102
"", ["owner/repo"], "2022-01-01", "2022-12-31", mock_github_connection, ghe
104103
)
105104

@@ -140,7 +139,7 @@ def test_get_contributors_skip_users_with_no_commits(self, mock_contributor_stat
140139
mock_repo.get_commits.side_effect = StopIteration
141140
ghe = ""
142141

143-
get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe)
142+
contributors_module.get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe)
144143

145144
# Note that only user is returned and user2 is not returned here because there were no commits in the date range
146145
mock_contributor_stats.assert_called_once_with(
@@ -168,7 +167,7 @@ def test_get_contributors_skip_bot(self, mock_contributor_stats):
168167
mock_repo.get_commits.side_effect = StopIteration
169168
ghe = ""
170169

171-
get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe)
170+
contributors_module.get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe)
172171

173172
# Note that only user is returned and user2 is not returned here because there were no commits in the date range
174173
mock_contributor_stats.isEmpty()
@@ -189,7 +188,7 @@ def test_get_contributors_no_commit_end_date(self, mock_contributor_stats):
189188
mock_repo.get_commits.side_effect = StopIteration
190189
ghe = ""
191190

192-
get_contributors(mock_repo, "2022-01-01", "", ghe)
191+
contributors_module.get_contributors(mock_repo, "2022-01-01", "", ghe)
193192

194193
# Note that only user is returned and user2 is not returned here because there were no commits in the date range
195194
mock_contributor_stats.assert_called_once_with(
@@ -212,7 +211,9 @@ def test_get_contributors_skips_when_no_commits_in_range(self):
212211
mock_repo.full_name = "owner/repo"
213212
mock_repo.commits.return_value = iter([])
214213

215-
result = get_contributors(mock_repo, "2022-01-01", "2022-12-31", "")
214+
result = contributors_module.get_contributors(
215+
mock_repo, "2022-01-01", "2022-12-31", ""
216+
)
216217

217218
self.assertEqual(result, [])
218219

@@ -230,7 +231,9 @@ def __iter__(self):
230231
mock_repo.contributors.return_value = BoomIterable()
231232

232233
with patch("builtins.print") as mock_print:
233-
result = get_contributors(mock_repo, "2022-01-01", "2022-12-31", "")
234+
result = contributors_module.get_contributors(
235+
mock_repo, "2022-01-01", "2022-12-31", ""
236+
)
234237

235238
self.assertIsNone(result)
236239
mock_print.assert_any_call(
@@ -251,7 +254,7 @@ def test_main_runs_under_main_guard(self):
251254
"",
252255
"2022-01-01",
253256
"2022-12-31",
254-
"true",
257+
True,
255258
False,
256259
)
257260

0 commit comments

Comments
 (0)