Skip to content

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

Open
abzsd wants to merge 10 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 10 commits into
Qiskit:mainfrom
abzsd:test/github-coverage

Conversation

@abzsd

@abzsd abzsd commented May 20, 2026

Copy link
Copy Markdown

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

CLAassistant commented May 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@1ucian0 1ucian0 left a comment

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.

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

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

Comment thread tests/github/test_github.py Outdated
Comment thread tests/github/test_github.py Outdated
@@ -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?

Comment thread tests/github/test_github.py Outdated
Comment thread tests/github/test_github.py Outdated
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 thread tests/github/test_github.py Outdated
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 thread tests/github/test_github.py Outdated
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},
}

@abzsd abzsd requested a review from 1ucian0 May 26, 2026 07:22
Comment thread tests/github/test_github.py
@abzsd

abzsd commented Jun 3, 2026

Copy link
Copy Markdown
Author

Hi there @1ucian0, just saw the coverage and tests check/Github actions giving an error, just let me know if I need to make some more changes. Does my code need to pass those checks as well to get merged?

@abzsd

abzsd commented Jun 3, 2026

Copy link
Copy Markdown
Author

Got it, I had used datetime instead of date in the tests, I have made the changes pushing the changes. Please do a review of the same, apologies for the inconvenience caused

@abzsd

abzsd commented Jun 15, 2026

Copy link
Copy Markdown
Author

Hi there @1ucian0, Hope you're doing well,
I wanted to request if you could please do a review of the code and allow starting the checks again?

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