Skip to content

Commit

Permalink
only use safe_unicode where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinchow86 committed Sep 13, 2015
1 parent 51a52db commit 735f120
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Sequence = list

BuiltinAssertionError = py.builtin.builtins.AssertionError
u = py.builtin._totext


def safe_unicode(value, encoding='utf-8'):
Expand All @@ -21,8 +22,6 @@ def safe_unicode(value, encoding='utf-8'):

return value

# Fix unicode decode issues, for now
u = safe_unicode # used to be py.builtin._totext

# The _reprcompare attribute on the util module is used by the new assertion
# interpretation code and assertion rewriter to detect this plugin was
Expand Down Expand Up @@ -117,7 +116,7 @@ def _format_lines(lines):
stack.append(len(result))
stackcnt[-1] += 1
stackcnt.append(0)
result.append(u(' +') + u(' ')*(len(stack)-1) + s + u(line[1:]))
result.append(u(' +') + u(' ')*(len(stack)-1) + s + safe_unicode(line[1:]))
elif line.startswith('}'):
stack.pop()
stackcnt.pop()
Expand All @@ -126,7 +125,7 @@ def _format_lines(lines):
assert line[0] in ['~', '>']
stack[-1] += 1
indent = len(stack) if line.startswith('~') else len(stack) - 1
result.append(u(' ')*indent + u(line[1:]))
result.append(u(' ')*indent + safe_unicode(line[1:]))
assert len(stack) == 1
return result

Expand All @@ -147,9 +146,9 @@ def assertrepr_compare(config, op, left, right):
# the reencoding is needed for python2 repr
# with non-ascii characters (see isssue 877)
summary = u('%s %s %s') % (
u(left_repr),
safe_unicode(left_repr),
op,
u(right_repr),
safe_unicode(right_repr),
)

issequence = lambda x: (isinstance(x, (list, tuple, Sequence))
Expand Down

7 comments on commit 735f120

@beedub
Copy link

@beedub beedub commented on 735f120 Dec 1, 2015

Choose a reason for hiding this comment

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

can we get these changes merged upstream with pytest?

@alvinchow86
Copy link
Author

Choose a reason for hiding this comment

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

yeah probably should try to. i commented on someone else's issue or PR at some point in the past, should try to dig it up

@alvinchow86
Copy link
Author

Choose a reason for hiding this comment

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

@beedub
pytest-dev#877

supposedly fixed in pytest-dev@49c99a4?

i'm not completely sure though, we should do some tests

@beedub
Copy link

@beedub beedub commented on 735f120 Dec 3, 2015

Choose a reason for hiding this comment

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

does pydev have a test suite that we can leverage?

@alvinchow86
Copy link
Author

@alvinchow86 alvinchow86 commented on 735f120 Dec 3, 2015 via email

Choose a reason for hiding this comment

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

@beedub
Copy link

@beedub beedub commented on 735f120 Dec 3, 2015

Choose a reason for hiding this comment

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

right, just meant that we should add the failures that we have seen in our tests to pydev's test suite

@alvinchow86
Copy link
Author

Choose a reason for hiding this comment

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

yeah, definitely. just have to remember what the nature of those tests were

Please sign in to comment.