Skip to content

Restructuring and adding tests#8

Merged
oraNod merged 13 commits into
fedora-copr:mainfrom
oraNod:pytest-unit-read-file
May 29, 2025
Merged

Restructuring and adding tests#8
oraNod merged 13 commits into
fedora-copr:mainfrom
oraNod:pytest-unit-read-file

Conversation

@oraNod

@oraNod oraNod commented Oct 11, 2024

Copy link
Copy Markdown
Collaborator

This PR adds some initial tests.

Comment thread tests/json/github-payload.json
Comment thread tests/test_webhook_parser.py Outdated
@oraNod oraNod force-pushed the pytest-unit-read-file branch from be8c210 to d1ff364 Compare March 21, 2025 18:27
@oraNod oraNod marked this pull request as ready for review March 21, 2025 18:43
@oraNod oraNod requested a review from FrostyX March 21, 2025 18:43
@oraNod oraNod changed the title Adding some tests Restructuring and adding tests Mar 21, 2025
@oraNod

oraNod commented Mar 21, 2025

Copy link
Copy Markdown
Collaborator Author

@FrostyX Hey I know this has been sitting around for a super long time but I'd like to revive it. Hopefully the restructure and direction makes sense. I'd like to add some more tests but I'll hold off for now and do that in follow on PRs. There's already a bunch of changes in here. And figuring out the tests has been challenging...

@FrostyX

FrostyX commented Mar 24, 2025

Copy link
Copy Markdown
Member

Thank you for the PR @oraNod, I will try to review once I can

@oraNod

oraNod commented Mar 24, 2025

Copy link
Copy Markdown
Collaborator Author

Thank you for the PR @oraNod, I will try to review once I can

No panic. I might make some changes once again. I'm unsure about using MagicMock now. It might be total overkill and unnecessary for all that abstraction. Maybe it's sort of a roundabout way of doing things. Cheers, man.

@FrostyX FrostyX 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.

Thank you very much for the PR @oraNod, I left some comments for you. It doesn't really matter to me if we merge the PR as is and address them in a follow-up PR or if we do it here.

Comment thread .gitignore Outdated

# Test repository names
project-for-testing-tito/
wireplumber/

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.

It would be better if we had a git-ignored dst/tmp/output/something directory and clone the repositories there. That way we won't have to list all of them explicitly.

Comment thread tests/conftest.py
import pytest

TESTS_DIR = Path(__file__).parent
JSON_DIR = TESTS_DIR / "json"

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.

I had absolutely no idea we can join paths like this. That's kinda cool.

Comment thread tests/conftest.py Outdated
file_path = JSON_DIR / "github-payload.json"
with open(file_path, encoding="utf-8") as file:
return json.load(file)
except FileNotFoundError:

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.

Under what circumstances can this happen? The file_path isn't affected by any arguments and is always the same.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll remove this to make it simpler. I was probably just being overzealous.

Comment thread tests/test_parser_functions.py Outdated
data = load_json_data(mock_args_file)

assert data == gitlab_payload
mock_open.assert_called_once_with("payload.json", "r", encoding="utf-8")

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.

It's IMHO not worth having both test_load_from_file_github and test_load_from_file_gitlab. The test only makes sure that load_json_data chooses the correct place to load the data from (the file in this case). There is no way that one of the tests passes and the other one doesn't.

The same for test_load_from_url_github and test_load_from_url_gitlab below.

Comment thread tests/test_parser_functions.py Outdated
data = load_json_data(mock_args_url)

assert data == gitlab_payload
mock_get.assert_called_once_with("http://example.com/payload.json")

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.

I think the most valuable tests will be for extract_repository_url, extract_project_name, and parse_commits. And at the same time, those will be the easiest to write :-)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, now that the basic pytest setup is in there I hope those will come easily. I'll do that as a follow on PR though.

@oraNod oraNod requested a review from FrostyX May 28, 2025 20:25
@oraNod

oraNod commented May 28, 2025

Copy link
Copy Markdown
Collaborator Author

Thanks for the review @FrostyX I've pushed a couple of commits here to address things. I feel like there were a couple more things to simplify but I've forgotten pretty much everything after summit. If this looks good, I'd like to merge and handle all other refactoring and new tests in follow on PRs. Cheers!

@oraNod oraNod merged commit cced906 into fedora-copr:main May 29, 2025
4 checks passed
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.

2 participants