#877 - reencoding causes typeerrors on python2

This commit is contained in:
Ronny Pfannschmidt 2015-09-13 21:34:52 +02:00
parent 49c99a41ea
commit 7658f60146
1 changed files with 9 additions and 7 deletions

View File

@ -130,13 +130,15 @@ def assertrepr_compare(config, op, left, right):
left_repr = py.io.saferepr(left, maxsize=int(width/2))
right_repr = py.io.saferepr(right, maxsize=width-len(left_repr))
# the reencoding is needed for python2 repr
# with non-ascii characters (see isssue 877)
summary = u('%s %s %s') % (
u(left_repr, 'utf-8', 'replace'),
op,
u(right_repr, 'utf-8', 'replace'),
)
# the re-encoding is needed for python2 repr
# with non-ascii characters (see issue 877)
def ecu(s):
try:
return u(s, 'utf-8', 'replace')
except TypeError:
return s
summary = u('%s %s %s') % (ecu(left_repr), op, ecu(right_repr))
issequence = lambda x: (isinstance(x, (list, tuple, Sequence))
and not isinstance(x, basestring))