[SCM] morituri/master: * morituri/test/common.py: Add a method for diffing multiline strings.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:09:05 UTC 2014


The following commit has been merged in the master branch:
commit 316eefbbd987cf1d4d4b4a0b54ef85c56b261e9b
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Thu Jun 4 09:03:45 2009 +0000

    	* morituri/test/common.py:
    	  Add a method for diffing multiline strings.

diff --git a/ChangeLog b/ChangeLog
index c8f73ac..f591ba8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
diff --git a/morituri/test/common.py b/morituri/test/common.py
index 94c6ac7..74c679b 100644
--- a/morituri/test/common.py
+++ b/morituri/test/common.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)

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list