Add unit tests for ecosystem/github.py to increase code coverage from 28% to 94%#1163
Open
abzsd wants to merge 4 commits into
Open
Add unit tests for ecosystem/github.py to increase code coverage from 28% to 94%#1163abzsd wants to merge 4 commits into
abzsd wants to merge 4 commits into
Conversation
1ucian0
requested changes
May 20, 2026
Comment on lines
+22
to
+26
| self.assertIsNone(gh._json_repo) | ||
| self.assertIsNone(gh._json_events) | ||
| self.assertIsNone(gh._json_package_ids) | ||
| self.assertIsNone(gh._json_dependants) | ||
| self.assertIsNone(gh._json_contributors_sidebar) |
Member
There was a problem hiding this comment.
No need to check the internals.
Suggested change
| self.assertIsNone(gh._json_repo) | |
| self.assertIsNone(gh._json_events) | |
| self.assertIsNone(gh._json_package_ids) | |
| self.assertIsNone(gh._json_dependants) | |
| self.assertIsNone(gh._json_contributors_sidebar) |
| @@ -0,0 +1,226 @@ | |||
| """Tests for ecosystem/github.py""" | |||
|
|
|||
| # pylint: disable=protected-access | |||
|
|
||
|
|
||
| class TestGitHubDataInit(TestCase): | ||
| """Tests for GitHubData.__init__""" |
Member
There was a problem hiding this comment.
Suggested change
| """Tests for GitHubData.__init__""" | |
| """Tests for GitHubData builder""" |
| def test_init_with_kwargs(self): | ||
| """extra kwargs are stored in _kwargs""" | ||
| gh = GitHubData(owner="Qiskit", repo="qiskit-ecosystem", stars=100) | ||
| self.assertEqual(gh._kwargs["stars"], 100) |
Member
There was a problem hiding this comment.
Suggested change
| self.assertEqual(gh._kwargs["stars"], 100) | |
| self.assertEqual(gh.stars, 100) |
| """Tests for GitHubData.__getattr__""" | ||
|
|
||
| def setUp(self): | ||
| self.gh = GitHubData(owner="Qiskit", repo="qiskit-ecosystem") |
Member
There was a problem hiding this comment.
consider network mocking to populate _json_repo instead of hardcode it. Internal might change at any point.
Comment on lines
+180
to
+182
| gh._json_package_ids = {} | ||
| gh.update_json() | ||
| self.assertIsNotNone(gh._json_repo) |
Comment on lines
+213
to
+216
| gh._json_dependants = { | ||
| "pkg1": {"repositories": 10}, | ||
| "pkg2": {"repositories": 5}, | ||
| } |
Member
There was a problem hiding this comment.
Network mock for populating _json_dependants
Suggested change
| gh._json_dependants = { | |
| "pkg1": {"repositories": 10}, | |
| "pkg2": {"repositories": 5}, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Added unit tests for
ecosystem/github.pyto increase code coverageFixes the following Issue : #1107
Details and comments
Added
tests/github/test_github.pywith 25 tests covering:GitHubData.__init__: Default values and kwargs storageGitHubData.from_url: Valid URLs, non-GitHub URLS, tree paths, and invalid URLsGitHubData.to_dict: serialization and None value exclusionGitHubData.__getattr__: type transform and AttributeError casesGitHubData.update_owner_repo: rename detectionGitHubData.update_json: verifies JSON fields are populated and dependents are fetched per packageGitHubData.dependants: refresh behaviourGitHubData.total_dependent_repositories/total_dependent_packages: property computationsI have added the tests to cover my changes.
I have updated the documentation accordingly.
I have read the CONTRIBUTING document.