Skip to content

Add unit tests for ecosystem/github.py to increase code coverage from 28% to 94%#1163

Open
abzsd wants to merge 4 commits into
Qiskit:mainfrom
abzsd:test/github-coverage
Open

Add unit tests for ecosystem/github.py to increase code coverage from 28% to 94%#1163
abzsd wants to merge 4 commits into
Qiskit:mainfrom
abzsd:test/github-coverage

Conversation

@abzsd
Copy link
Copy Markdown

@abzsd abzsd commented May 20, 2026

Summary

Added unit tests for ecosystem/github.py to increase code coverage

Fixes the following Issue : #1107

Details and comments

Added tests/github/test_github.py with 25 tests covering:

  • GitHubData.__init__ : Default values and kwargs storage

  • GitHubData.from_url : Valid URLs, non-GitHub URLS, tree paths, and invalid URLs

  • GitHubData.to_dict : serialization and None value exclusion

  • GitHubData.__getattr__ : type transform and AttributeError cases

  • GitHubData.update_owner_repo : rename detection

  • GitHubData.update_json : verifies JSON fields are populated and dependents are fetched per package

  • GitHubData.dependants : refresh behaviour

  • GitHubData.total_dependent_repositories / total_dependent_packages : property computations

  • I have added the tests to cover my changes.

  • I have updated the documentation accordingly.

  • I have read the CONTRIBUTING document.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 20, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! maybe, consider mocking more instead of populating internal structures.

(also, I renamed some of the strings in your branch)

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be more specific?



class TestGitHubDataInit(TestCase):
"""Tests for GitHubData.__init__"""
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.assertEqual(gh._kwargs["stars"], 100)
self.assertEqual(gh.stars, 100)

Comment thread tests/github/test_github.py Outdated
"""Tests for GitHubData.__getattr__"""

def setUp(self):
self.gh = GitHubData(owner="Qiskit", repo="qiskit-ecosystem")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for empty data instead

Comment on lines +213 to +216
gh._json_dependants = {
"pkg1": {"repositories": 10},
"pkg2": {"repositories": 5},
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Network mock for populating _json_dependants

Suggested change
gh._json_dependants = {
"pkg1": {"repositories": 10},
"pkg2": {"repositories": 5},
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants