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

chore: unit tests around protocol usage #48

Merged
merged 4 commits into from
Jul 16, 2024
Merged

Conversation

WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Jul 12, 2024

Summary

This PR started as exploratory work to remove the DefaultProtocol since it is no longer used by the CLI. Turns out we can't simply remove the DefaultProtocol since it is used when the user wants to execute the hooks directly. But this lead to the following improvements.

A refactor of the scenario unit tests now use the MessageBoundary protocol, this closer mimics the end user experience through the CLI 👍

A MockProtocol was introduced in order to facilitate unit testing.

Testing

  1. Pull the latest changes from this branch
  2. Run the unit tests

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_and_run_tests.sh after making the changes.

@codecov-commenter
Copy link

codecov-commenter commented Jul 12, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@d048022). Learn more about missing BASE report.

Files Patch % Lines
slack_cli_hooks/hooks/check_update.py 50.00% 1 Missing ⚠️
slack_cli_hooks/hooks/doctor.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #48   +/-   ##
=======================================
  Coverage        ?   94.63%           
=======================================
  Files           ?       11           
  Lines           ?      205           
  Branches        ?        0           
=======================================
  Hits            ?      194           
  Misses          ?       11           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WilliamBergamin WilliamBergamin self-assigned this Jul 12, 2024
@WilliamBergamin WilliamBergamin added the test Changes affecting the tests of the project label Jul 12, 2024
@WilliamBergamin WilliamBergamin changed the title chore: clean up unused protocol chore: unit tests around protocol usage Jul 12, 2024
@WilliamBergamin WilliamBergamin requested a review from zimeg July 15, 2024 12:55
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

LGTM and works well in testing! Nice find around the need for the DefaultProtocol too - it makes sense to me that we need this when initializing hooks like with get-hooks but that wasn't so obvious!

I think this is set to merge when you're ready but I left a few comments around defaulting arguments. All of these changes make sense and push the code in a solid direction (thank you for the import sorting) so these could be ignored! 🚀

I did also notice some warnings appear in testing and I'm unsure if these are related to the changes to import sorting or existed beforehand, but wanted to raise regardless:

https://github.com/slackapi/python-slack-hooks/actions/runs/9914063133/job/27392412627#step:5:33

def test_get_manifest(self, capsys):
runpy.run_module(get_hooks.__name__, run_name="__main__")
runpy.run_module(get_hooks.__name__, run_name="__main__", alter_sys=False)
Copy link
Member

Choose a reason for hiding this comment

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

Does this change need to be applied to other runpy.run_module methods? It seems like False is the default value but it'd be nice to keep this consistent in whatever case IMO! 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch 💯 this is a remnant of my experimental work

@@ -30,5 +26,5 @@
}

if __name__ == "__main__":
PROTOCOL = build_protocol()
PROTOCOL = build_protocol(argv=sys.argv[1:])
Copy link
Member

Choose a reason for hiding this comment

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

I'm for this argument being explicit instead of falling back to the same default, but I'm wondering if we'd also want to remove that defaulting value with this change? That might be a breaking change though, so feel free to ignore - this adds a bunch of clarity as is!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this 💯 it isn't a breaking change since the build_protocol util is not exposed publicly

@WilliamBergamin
Copy link
Contributor Author

I did also notice some warnings appear in testing and I'm unsure if these are related to the changes to import sorting or existed beforehand

@zimeg these error were present before these changes, it is something I need to address, I think it relates to the scenario test that execute using runpy 🤔

@WilliamBergamin WilliamBergamin merged commit b5ed2b2 into main Jul 16, 2024
11 checks passed
@zimeg zimeg deleted the clean-up-protocol branch September 16, 2024 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Changes affecting the tests of the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants