Fix assertrepr for mojibake
If the compared text was in bytes and not actually valid text (i.e. could not be encoded to text/unicode using the default encoding) then the assertrepr would fail with an EncodingError. This ensures that the internal string is always valid unicode, converting any bytes safely to valid unicode. This is done using repr() which then needs post-processing to fix the encompassing quotes and un-escape newlines. This fixes issue 429.
This commit is contained in:
@@ -185,6 +185,19 @@ class TestAssert_reprcompare:
|
||||
assert expl[1] == py.builtin._totext('- £€', 'utf-8')
|
||||
assert expl[2] == py.builtin._totext('+ £', 'utf-8')
|
||||
|
||||
def test_mojibake(self):
|
||||
# issue 429
|
||||
left = 'e'
|
||||
right = '\xc3\xa9'
|
||||
if not isinstance(left, py.builtin.bytes):
|
||||
left = py.builtin.bytes(left, 'utf-8')
|
||||
right = py.builtin.bytes(right, 'utf-8')
|
||||
expl = callequal(left, right)
|
||||
for line in expl:
|
||||
assert isinstance(line, py.builtin.text)
|
||||
msg = py.builtin._totext('\n').join(expl)
|
||||
assert msg
|
||||
|
||||
|
||||
def test_python25_compile_issue257(testdir):
|
||||
testdir.makepyfile("""
|
||||
|
||||
Reference in New Issue
Block a user