test: add coverage for HookRegistry.unregister#118
Conversation
Five tests covering the new method added in #117: - removes callback and prevents it from firing - returns False when callback was never registered - idempotent on repeated unregister calls - raises ValueError for unsupported hook names - removes only the targeted callback, leaving others intact
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Reviewer's GuideAdds focused async tests for HookRegistry.unregister to validate normal removal behavior, failure/false-return cases, idempotency, invalid hook name handling, and selective callback removal, in order to restore patch coverage for the newly added unregister method. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Warning Review limit reached
Next review available in: 35 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- Consider defining small named helper functions instead of inline lambdas for the callbacks (e.g.,
def cb_a(**kw): ...) to improve readability and make debugging stack traces clearer across the new tests.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider defining small named helper functions instead of inline lambdas for the callbacks (e.g., `def cb_a(**kw): ...`) to improve readability and make debugging stack traces clearer across the new tests.
## Individual Comments
### Comment 1
<location path="tests/test_hooks.py" line_range="144-149" />
<code_context>
+ assert result is False
+
+
+async def test_unregister_idempotent_on_repeat():
+ registry = HookRegistry()
+ cb = lambda **kw: None
+ registry.register("after_command", cb)
+ assert registry.unregister("after_command", cb) is True
+ assert registry.unregister("after_command", cb) is False
+
+
</code_context>
<issue_to_address>
**issue (testing):** Add a test for unregistering a callback that is registered multiple times for the same hook to pin down the expected behavior.
We only test idempotency after a successful unregister, but not the case where the same callback is registered multiple times for the same hook (e.g., `register(..., cb)` twice, then `unregister` once). Please add a test that defines whether a single `unregister` removes one or all registrations, and checks that `fire` calls the callback the expected number of times. This will pin down the intended contract for future refactors.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| async def test_unregister_idempotent_on_repeat(): | ||
| registry = HookRegistry() | ||
| cb = lambda **kw: None | ||
| registry.register("after_command", cb) | ||
| assert registry.unregister("after_command", cb) is True | ||
| assert registry.unregister("after_command", cb) is False |
There was a problem hiding this comment.
issue (testing): Add a test for unregistering a callback that is registered multiple times for the same hook to pin down the expected behavior.
We only test idempotency after a successful unregister, but not the case where the same callback is registered multiple times for the same hook (e.g., register(..., cb) twice, then unregister once). Please add a test that defines whether a single unregister removes one or all registrations, and checks that fire calls the callback the expected number of times. This will pin down the intended contract for future refactors.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
## v5.58.0 Release PR Bumps version to 5.58.0 and updates CHANGELOG. ### What's in this release (since v5.57.0) **Changed** - Docs accuracy audit across 10 files — fixed plugin counts, stale method names, wrong constructor params, wrong type names, wrong class relationships, stale CI pins (#116, #117) - `HookRegistry.unregister(hook, callback) -> bool` — new public method; returns `False` instead of raising on already-removed callbacks (#117) **Tests** - Full coverage for `HookRegistry.unregister()` — removal, idempotency, invalid hook name, selective removal (#118) **Release metadata**: `easycord-5.58.0-py3-none-any.whl` and `easycord-5.58.0.tar.gz` --------- Co-authored-by: tee <Thomas_BIRRELL@proton.me>
Fixes the codecov/patch failure from #117.
HookRegistry.unregister()was added in #117 but had no tests, dropping patch coverage to 12.50% (target 76%).5 tests added covering:
Falsewhen callback was never registeredFalsewithout raisingValueErrorSummary by Sourcery
Add missing tests for HookRegistry.unregister behavior to restore hook system coverage.
Tests: