test: cover remaining contributor paths#395
Conversation
Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage for remaining contributor-related execution paths and a couple of supporting utilities/docs.
Changes:
- Add tests for
get_contributors()edge cases (no commits in range, exception handling) andmain()execution paths. - Add tests for
env.get_int_env_var()invalid parsing andcontributor_stats(__repr__, sponsor info error path). - Adjust README badges formatting to be on separate lines.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
test_env.py |
Adds coverage for invalid integer env var parsing. |
test_contributors.py |
Adds coverage for additional contributor filtering/error paths and script/main execution. |
test_contributor_stats.py |
Adds coverage for __repr__ and sponsor info error handling. |
README.md |
Splits badges onto separate lines for readability. |
Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
17001f8 to
1f39dfc
Compare
| "", | ||
| "2022-01-01", | ||
| "2022-12-31", | ||
| "true", |
There was a problem hiding this comment.
env.get_env_vars() returns sponsor_info as a boolean (see env.get_bool_env_var / get_env_vars), but this test uses the string "true". This makes the test diverge from real behavior and can mask the fact that contributors.main() currently compares sponsor_info == "true" instead of treating it as a boolean.
| "true", | |
| True, |
|
|
||
| result = get_all_contributors( | ||
| result = contributors_module.get_all_contributors( | ||
| "org", "", "2022-01-01", "2022-12-31", mock_github_connection, ghe |
There was a problem hiding this comment.
In this test call, repository_list is passed as an empty string, but get_all_contributors() is typed/used as List[str]. Passing [] here would better match the real call sites and avoid accidentally exercising the for repo in repository_list branch if organization becomes falsy in the future.
| "org", "", "2022-01-01", "2022-12-31", mock_github_connection, ghe | |
| "org", [], "2022-01-01", "2022-12-31", mock_github_connection, ghe |
| mock_repo.contributors.return_value = [mock_user] | ||
| mock_repo.full_name = "owner/repo" | ||
| mock_repo.get_commits.side_effect = StopIteration | ||
| ghe = "" | ||
|
|
||
| get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe) | ||
| contributors_module.get_contributors(mock_repo, "2022-01-01", "2022-12-31", ghe) |
There was a problem hiding this comment.
get_contributors() checks commits via repo.commits(...) and next(user_commits), but this test configures mock_repo.get_commits, which is never used. As written, it won’t reliably exercise the “skip users with no commits” path—configure mock_repo.commits to return an empty iterator for the user you want skipped (and consider including mock_user2 in mock_repo.contributors.return_value to validate the filtering).
| # Note that only user is returned and user2 is not returned here because there were no commits in the date range | ||
| mock_contributor_stats.isEmpty() |
There was a problem hiding this comment.
This test doesn’t assert anything meaningful: mock_contributor_stats.isEmpty() is just another mock call and won’t fail if ContributorStats was instantiated. Prefer asserting the constructor was not called (e.g., assert_not_called) and remove the unused mock_repo.get_commits setup (the implementation calls repo.commits).
| # Note that only user is returned and user2 is not returned here because there were no commits in the date range | |
| mock_contributor_stats.isEmpty() | |
| # Ensure that the bot user is skipped and ContributorStats is never instantiated | |
| mock_contributor_stats.assert_not_called() |
how much coverage is too much coverage
Pull Request
Proposed Changes
Readiness Checklist
Author/Contributor
make lintand fix any issues that you have introducedmake testand ensure you have test coverage for the lines you are introducing@jeffrey-luszczReviewer
bug,documentation,enhancement,infrastructure,maintenanceorbreaking