2 new commits in pytest: https://bitbucket.org/hpk42/pytest/commits/1d6d77f0bbd4/ Changeset: 1d6d77f0bbd4 User: flub Date: 2014-01-29 01:39:04 Summary: Avoid wasted string concatenation and improve english Affected #: 1 file
diff -r 0d595ac74709b416ff9ff7c52bed0f8de6bb6a9b -r 1d6d77f0bbd4777ec018209b2889ad46515a6016 _pytest/assertion/__init__.py --- a/_pytest/assertion/__init__.py +++ b/_pytest/assertion/__init__.py @@ -80,10 +80,10 @@ if new_expl: # Don't include pageloads of data unless we are very # verbose (-vv) - if (len(py.builtin._totext('').join(new_expl[1:])) > 80*8 + if (sum(len(p) for p in new_expl[1:]) > 80*8 and item.config.option.verbose < 2): new_expl[1:] = [py.builtin._totext( - 'Detailed information truncated, use "-vv" to see')] + 'Detailed information truncated, use "-vv" to show')] res = py.builtin._totext('\n~').join(new_expl) if item.config.getvalue("assertmode") == "rewrite": # The result will be fed back a python % formatting https://bitbucket.org/hpk42/pytest/commits/30dbac953dd3/ Changeset: 30dbac953dd3 User: flub Date: 2014-01-29 01:42:58 Summary: 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. Affected #: 2 files diff -r 1d6d77f0bbd4777ec018209b2889ad46515a6016 -r 30dbac953dd3b24dbd29b9d472ff7504011e210a _pytest/assertion/util.py --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -162,12 +162,18 @@ def _diff_text(left, right, verbose=False): - """Return the explanation for the diff between text + """Return the explanation for the diff between text or bytes Unless --verbose is used this will skip leading and trailing characters which are identical to keep the diff minimal. + + If the input are bytes they will be safely converted to text. """ explanation = [] + if isinstance(left, py.builtin.bytes): + left = u(repr(left)[1:-1]).replace(r'\n', '\n') + if isinstance(right, py.builtin.bytes): + right = u(repr(right)[1:-1]).replace(r'\n', '\n') if not verbose: i = 0 # just in case left or right has zero length for i in range(min(len(left), len(right))): diff -r 1d6d77f0bbd4777ec018209b2889ad46515a6016 -r 30dbac953dd3b24dbd29b9d472ff7504011e210a testing/test_assertion.py --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -185,6 +185,19 @@ 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(""" Repository URL: https://bitbucket.org/hpk42/pytest/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email. _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit