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

0 comments on commit 735f120

Please sign in to comment.