* morituri/test/common.py:
Add a method for diffing multiline strings.
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
2009-06-04 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/test/common.py:
|
||||
Add a method for diffing multiline strings.
|
||||
|
||||
2009-06-02 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||
|
||||
* morituri/common/encode.py:
|
||||
|
||||
@@ -4,3 +4,29 @@
|
||||
from morituri.common import log
|
||||
|
||||
log.init()
|
||||
|
||||
# lifted from flumotion
|
||||
|
||||
def _diff(old, new, desc):
|
||||
import difflib
|
||||
lines = difflib.unified_diff(old, new)
|
||||
lines = list(lines)
|
||||
if not lines:
|
||||
return
|
||||
output = ''
|
||||
for line in lines:
|
||||
output += '%s: %s\n' % (desc, line[:-1])
|
||||
|
||||
raise AssertionError(
|
||||
("\nError while comparing strings:\n"
|
||||
"%s") % (output, ))
|
||||
|
||||
|
||||
def diffStrings(orig, new, desc='input'):
|
||||
|
||||
def _tolines(s):
|
||||
return [line + '\n' for line in s.split('\n')]
|
||||
|
||||
return _diff(_tolines(orig),
|
||||
_tolines(new),
|
||||
desc=desc)
|
||||
|
||||
Reference in New Issue
Block a user