Skip to content

Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text #4001

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

Merged
merged 1 commit into from
Sep 20, 2018
Merged

Fix UnicodeDecodeError in assertion with mixed non-ascii bytes repr + text #4001

merged 1 commit into from
Sep 20, 2018

Conversation

asottile
Copy link
Member

Resolves #3999

@codecov
Copy link

codecov bot commented Sep 19, 2018

Codecov Report

Merging #4001 into master will increase coverage by 0.15%.
The diff coverage is 62.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4001      +/-   ##
==========================================
+ Coverage   94.34%   94.49%   +0.15%     
==========================================
  Files         109      109              
  Lines       23766    23778      +12     
  Branches     2356     2357       +1     
==========================================
+ Hits        22421    22470      +49     
+ Misses       1026     1000      -26     
+ Partials      319      308      -11
Flag Coverage Δ
#doctesting 29.37% <25%> (+0.82%) ⬆️
#linux 94.35% <62.5%> (+0.01%) ⬆️
#nobyte 0% <0%> (ø) ⬆️
#numpy 28.28% <25%> (+0.12%) ⬆️
#pexpect 0% <0%> (ø) ⬆️
#py27 92.62% <62.5%> (+0.12%) ⬆️
#py34 92.1% <50%> (+0.13%) ⬆️
#py35 92.12% <50%> (+0.13%) ⬆️
#py36 92.69% <50%> (+0.18%) ⬆️
#py37 92.32% <50%> (+0.18%) ⬆️
#trial 31.31% <25%> (+0.27%) ⬆️
#windows 93.8% <62.5%> (?)
#xdist 18.58% <6.25%> (+0.07%) ⬆️
Impacted Files Coverage Δ
src/_pytest/assertion/rewrite.py 95.34% <100%> (-0.33%) ⬇️
testing/test_assertrewrite.py 83.12% <50%> (-0.66%) ⬇️
src/_pytest/fixtures.py 97.27% <0%> (+0.27%) ⬆️
testing/test_capture.py 99.24% <0%> (+0.3%) ⬆️
src/_pytest/pytester.py 86.01% <0%> (+0.45%) ⬆️
testing/acceptance_test.py 97.8% <0%> (+0.65%) ⬆️
src/_pytest/nodes.py 94.53% <0%> (+0.84%) ⬆️
src/_pytest/terminal.py 91.6% <0%> (+1.74%) ⬆️
src/_pytest/capture.py 89.93% <0%> (+3.2%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7aff817...7122fa5. Read the comment docs.

@coveralls
Copy link

coveralls commented Sep 19, 2018

Coverage Status

Coverage decreased (-0.001%) to 93.808% when pulling 7122fa5 on asottile:fix_bytes_repr_text_mix_python_2 into 7aff817 on pytest-dev:master.

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

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

Great work @asottile!

@@ -608,6 +609,21 @@ def __repr__(self):

assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0]

def test_custom_repr_non_ascii(self):
Copy link
Member

Choose a reason for hiding this comment

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

Is this test something we want to keep around after dropping Python 2? If not, I suggest to leave a comment so we can remove the test itself when the time comes (the code itself already contains a "python2.x" so I think that's enough). 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

shouldn't have a need for this when python2.x is gone, should I update the test or do you think the 2.x comment in the code is enough? (I actually added the comment with the same thought because I knew we were eventually going to want to clean it up!)

Copy link
Member

Choose a reason for hiding this comment

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

The comment in the code is enough to remove the code, but the test doesn't have any reference so I think it will mostly stay around. One alternative is to skip the test on python 3,this makes it clear it is python2 only.

Copy link
Member Author

Choose a reason for hiding this comment

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

cool, yeah I added a comment to the test

if isinstance(r, bytes):
# Represent unprintable bytes as `\x##`
r = u"".join(
u"\\x{:x}".format(ord(c)) if c not in string.printable else c.decode()
Copy link
Member

Choose a reason for hiding this comment

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

isn't there the hex-escape encoding we can use instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

string-escape, yes: but it also escapes quote characters
unicode-escape: almost, but it decodes escape sequences to their unicode character

Copy link
Member

Choose a reason for hiding this comment

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

@asottile i see, thanks for researching the details

@asottile
Copy link
Member Author

does codecov load for anyone else? I can't get the page to render for me :(

@nicoddemus
Copy link
Member

Me neither. 😞 @blueyed do you know if codecov is facing some stability problems lately?

@RonnyPfannschmidt RonnyPfannschmidt merged commit f6eb39d into pytest-dev:master Sep 20, 2018
@asottile asottile deleted the fix_bytes_repr_text_mix_python_2 branch September 20, 2018 20:17
@blueyed
Copy link
Contributor

blueyed commented Sep 20, 2018

Re @codecov: you can browse some commits etc, but PR pages appear to hang / time out often (and constantly when it happens).
Mentioned in #3990 (comment) already.
I cannot say much more - they are investigating, but that takes (at least felt) some weeks already by now.

@blueyed
Copy link
Contributor

blueyed commented Sep 20, 2018

@blueyed
Copy link
Contributor

blueyed commented Sep 20, 2018

Not sure if correct/relevant, but there is shows that the test is not covered: https://codecov.io/gh/pytest-dev/pytest/commit/7122fa5613de8ef767eeb8106a5fee6dea0d9285#D2-612 (sorry, have not read this PR/issue/details).

@asottile
Copy link
Member Author

yeah that has to do with the way that getmsg works (it rips the code object out and evals it essentially)

a = A()
assert not a.name

msg = getmsg(f)
Copy link
Contributor

@blueyed blueyed Sep 20, 2018

Choose a reason for hiding this comment

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

Should this call f maybe?

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.

5 participants