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

test: Don't assert error messages #570

Merged
merged 1 commit into from
Sep 27, 2024
Merged

test: Don't assert error messages #570

merged 1 commit into from
Sep 27, 2024

Conversation

lmars
Copy link
Member

@lmars lmars commented Sep 27, 2024

They are subject to change, so checking the error code is enough to know that the expected error occurred.

Summary by CodeRabbit

  • Tests
    • Updated the assertion in the test_without_permissions function to validate error codes instead of exception message content.

They are subject to change, so checking the error code is enough to know
that the expected error occurred.

Signed-off-by: Lewis Marshall <[email protected]>
@lmars lmars requested a review from owenpearson September 27, 2024 15:49
Copy link

coderabbitai bot commented Sep 27, 2024

Walkthrough

The change involves an update to the test_without_permissions asynchronous test function in the restchannels_test.py file. The assertion within the test has been modified to validate a specific error code, 40160, rather than checking for the presence of the string 'not permitted' in the exception message. This adjustment maintains the expected behavior of raising an AblyException while shifting the focus from the message content to the error code.

Changes

File Change Summary
test/ably/rest/restchannels_test.py Updated the assertion in test_without_permissions to check for error code 40160 instead of message content.

Poem

In the garden of code, a change took flight,
A rabbit hops in, with joy and delight.
"Error codes matter, let's make them clear,
With 40160, there's nothing to fear!
So hop along, friends, let’s test with glee,
For clarity blooms in our code, you see!" 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
test/ably/rest/restchannels_test.py (1)

90-90: Approve change and suggest minor improvement

The modification successfully addresses the PR objective by asserting the error code instead of the error message. This approach makes the test more robust against potential changes in error message wording.

However, there's a minor style improvement we can make:

Consider rewriting the assertion to avoid the Yoda condition:

- assert 40160 == excinfo.value.code
+ assert excinfo.value.code == 40160

This change aligns better with conventional Python style guidelines.

Would you like me to implement this change for you?

🧰 Tools
🪛 Ruff

90-90: Yoda condition detected

Rewrite as excinfo.value.code == 40160

(SIM300)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dff73cd and bf64282.

📒 Files selected for processing (1)
  • test/ably/rest/restchannels_test.py (1 hunks)
🧰 Additional context used
🪛 Ruff
test/ably/rest/restchannels_test.py

90-90: Yoda condition detected

Rewrite as excinfo.value.code == 40160

(SIM300)

@lmars
Copy link
Member Author

lmars commented Sep 27, 2024

I don't think the test suite will pass here due to the issue raised in #569 (i.e. ably-python won't properly decode msgpack encoded error responses, and so error code checks don't match up), but the change here is a correct one.

@lmars lmars merged commit 4066ce3 into main Sep 27, 2024
3 of 9 checks passed
@lmars lmars deleted the test-error-message branch September 27, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants