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

Make a good faith effort to display a bytestring when one is provided… #1438

Merged
merged 1 commit into from
Mar 6, 2016

Conversation

Bachmann1234
Copy link
Contributor

Thanks for submitting a PR, your contribution is really appreciated!

Here's a quick checklist that should be present in PRs:

[ X] Target: for bug or doc fixes, target master; for new features, target features
[ X] Make sure to include one or more tests for your change
[ X] Add yourself to AUTHORS
[ X] Add a new entry to the CHANGELOG (choose any open position to avoid merge conflicts with other PRs)

… as a regex patterm
Attempting to fix #1437
This will display odd behavior when the text in the bytestring is not encoded in ascii or utf-8. It wont crash but it will be wrong.

However, as I dont see a way to know the encoding for sure this seemed reasonable

Open to other ideas. Saw this on twitter and thought I would take a stab at it

@nicoddemus
Copy link
Member

Hey @Bachmann1234 thanks for the PR! 😄

@@ -1115,7 +1115,10 @@ def _idval(val, argname, idx, idfn):
elif isinstance(val, (float, int, str, bool, NoneType)):
return str(val)
elif isinstance(val, REGEX_TYPE):
return val.pattern
if isinstance(val.pattern, str):
Copy link
Member

Choose a reason for hiding this comment

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

While this works, I think a better approach here would be to reuse the effort made by _escape_bytes to handle bytes as ascii-escaped values instead of trying to decode from utf-8:

elif isinstance(val, REGEX_TYPE):
        return _escape_bytes(val.pattern) if isinstance(val.pattern, bytes) else val.pattern

@nicoddemus
Copy link
Member

Aside from my comments, please also add a test in acceptance_test.py containing the short example posted in #1437.

Thanks again for putting work into this! 😄

@Bachmann1234
Copy link
Contributor Author

Will do! Thanks for the quick feedback!

…code to turn it into a string before further processing. Thanks @nicoddemus for the review and tips!
@Bachmann1234
Copy link
Contributor Author

Should be fixed up and squashed down. Let me know if there is anything else needed.

RonnyPfannschmidt added a commit that referenced this pull request Mar 6, 2016
Make a good faith effort to display a bytestring when one is provided…
@RonnyPfannschmidt RonnyPfannschmidt merged commit 6d4b14d into pytest-dev:master Mar 6, 2016
@RonnyPfannschmidt
Copy link
Member

Well done thanks for putting in the work 👍

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.

Error when using non-unicode regular expression in parametrize argument
3 participants