[issue10164] Add an assertBytesMultiLineEqual to unittest and use it for bytes assertEqual

R. David Murray report at bugs.python.org
Thu Oct 21 14:48:17 CEST 2010


New submission from R. David Murray <rdmurray at bitdance.com>:

Just as with regular strings, when comparing failed output involving bytes strings it is really helpful to have a diff showing which bytes have changed.  The attached patch adds an assertMultiLineEqual method to unittest and uses it for comparing bytes in assertEqual.

The diff output is created by first breaking the byte strings into lines using 'splitlines(True)' just as in assertMultiLineEqual, but then each line is converted to a string using 'repr' before the lines sets are passed to ndiff.  This results in output containing escaped bytes, making it easier to compare the differences in the byte strings.

(NB: this patch is the end result of several attempts to make the unittest output more useful in the email package when testing bytes handling).

----------
files: bytes_multi_line_equal.diff
keywords: patch
messages: 119280
nosy: michael.foord, r.david.murray
priority: normal
severity: normal
stage: patch review
status: open
title: Add an assertBytesMultiLineEqual to unittest and use it for bytes assertEqual
type: feature request
versions: Python 3.2
Added file: http://bugs.python.org/file19320/bytes_multi_line_equal.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10164>
_______________________________________


More information about the Python-bugs-list mailing list