Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests and CI #124

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Add unit tests and CI #124

merged 1 commit into from
Aug 19, 2024

Conversation

jardon
Copy link
Contributor

@jardon jardon commented Aug 15, 2024

This PR contains the following changes:

  • Add pytest-based unit tests
  • Add Github Actions CI for unit tests

Closes #72

@gerblesh
Copy link
Collaborator

gerblesh commented Aug 16, 2024

Thanks for helping out with this. Not super familiar with pytest but the test code looks good to me so far!

@jardon
Copy link
Contributor Author

jardon commented Aug 17, 2024

@gerblesh @akdev1l do we actually want to add a test run to the spec file? I would think the unit tests would be run on PR in github actions CI

@gerblesh
Copy link
Collaborator

@gerblesh @akdev1l do we actually want to add a test run to the spec file? I would think the unit tests would be run on PR in github actions CI

If you had to ask me, I would say just github actions. Having it in the spec file would be redundant

@gerblesh
Copy link
Collaborator

gerblesh commented Aug 17, 2024

I'm also planning on implementing some integration tests for the project soon as well so that'll probably be in the build/test action anyway, filling the role @akdev1l was mentioning

@jardon jardon marked this pull request as ready for review August 17, 2024 20:30
- Add basic pytest unit tests
- Add unit test Actions CI workflow
mock_cfg.dbus_notify = True
mock_os.getuid.return_value = 1001
notify(title, body)
mock_run.assert_called_once_with(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the idea of checking to see if the command has been ran properly, but this could also be a problem down the line if someone changes the arguments or if notify-send changes its cli. This also goes for a lot of these other subprocess calls. Testing subprocess is hard though and likely will need to be solved by integration tests down the line

Copy link
Contributor Author

@jardon jardon Aug 18, 2024

Choose a reason for hiding this comment

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

ya its definitely tricky. the trap with unit tests at times is asserting too much as it makes the tests more inflexible and requires more maintenance on them. I could reduce the number of assertions to a more simple input -> output format that would allow changes to not break the tests as much.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but at the end of the day the unit tests are there to maintain stability of the codebase. changes to the unit tests are a often occurrence in my experience

tests/unit/test_cli.py Show resolved Hide resolved
@gerblesh gerblesh self-requested a review August 19, 2024 04:38
Copy link
Collaborator

@gerblesh gerblesh left a comment

Choose a reason for hiding this comment

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

This looks good to me then! Subprocess is a tricky one but after mulling it over it's probably better than not to at least test the arguments being passed in. Thanks so much for the great work here!

@gerblesh gerblesh added this pull request to the merge queue Aug 19, 2024
Merged via the queue into ublue-os:main with commit f6bcb2e Aug 19, 2024
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.

[Help Wanted] Unit Testing
2 participants